使用Coq的提取机制将Coq中的仿函数提取到Ocaml

时间:2013-03-22 09:54:09

标签: ocaml coq coq-extraction

我有一个功能PolyInterpretationhttp://color.inria.fr/doc/CoLoR.PolyInt.APolyInt.html

Definition PolyInterpretation := forall f : Sig, poly (arity f).

和模块签名TPolyInthttp://color.inria.fr/doc/CoLoR.PolyInt.APolyInt_MA.html

Module Type TPolyInt.
  Parameter sig : Signature.
  Parameter trsInt : PolyInterpretation sig.
  Parameter trsInt_wm : PolyWeakMonotone trsInt.
End TPolyInt.

Module PolyInt (Export PI : TPolyInt).

然后在我的文件rainbow.v中,我定义了一个模块TPolyInt_imp,目的是使用仿函数PolyInt

Module TPolyInt_imp.
 Variable arity : symbol -> nat.
 Variable l : list {g : symbol & poly (arity f).
 Definition sig := Sig arity.
 Definition trsInt f := fun_of_pairs_list f l.
 ...
End TPolyInt_imp.

fun_of_pairs_list的类型为forall f: Cpf0.symbol, list {g : symbol & poly (arity g)} -> poly (arity f)

然后我定义了一个模块P

Module Export P := PolyInt TPolyInt_imp.

Coq校对助理接受了上述P定义。

然后我使用提取来提取到Ocaml

我将其写在另一个文件中:extraction.v

Extraction Language Ocaml.
Set Extraction Optimize.
Set Extraction AccessOpaque.
Separate Extraction rainbow.P.

工作正常。

以下是提取后的代码

module TPolyInt_imp = 
 struct 
  (** val arity : symbol -> int **)

  let arity =
    failwith "AXIOM TO BE REALIZED"

  (** val l : (symbol, poly) sigT list **)

  let l =
    failwith "AXIOM TO BE REALIZED"

  (** val coq_sig : coq_Signature **)

  let coq_sig =
    coq_Sig arity

  (** val trsInt : symbol -> poly **)

  let trsInt f =
    fun_of_pairs_list arity f l
 end

module P = PolyInt(TPolyInt_imp)

因为在仿函数TPolyInt_imp中,他们包含Variable并生成failwith AXIOM,所以我决定定义一个新签名来包含所有这些变量。

Module Type Arity.
 Variable arity : symbol -> nat.
 Variable l : list {g : symbol & poly (arity g)}.
End Arity.

然后定义一个以(Arity)为参数的新仿函数。在这个仿函数中,我定义了模块TPolyInt_imp(之前的TPolyInt_imp)。

Module S (Import A: Arity).

  Module TPolyInt_imp.
    Definition sig := Sig arity.
    Definition trsInt f := fun_of_pairs_list f l.
    ...
  End TPolyInt_imp.

  Module P := PolyInt TPolyInt_imp.

End S.

然后我使用提取将其提取到Ocaml

Extraction Language Ocaml.
Set Extraction Optimize.
Set Extraction AccessOpaque.
Separate Extraction S.

然后我得到一个错误说:

Error: Signature mismatch:
       ...
       Values do not match:
         val trsInt : Cpf0.symbol -> Polynom.poly
       is not included in
         val trsInt : APolyInt.coq_PolyInterpretation
       File "rainbow.ml", line 534, characters 8-14: Actual declaration

提取后的代码:

module type Arity = 
 sig 
  val arity : symbol -> int
  val l : (symbol, poly) sigT list
 end

module S = 
 functor (A:Arity) ->
 struct 
  module TPolyInt_imp = 
   struct 
    (** val coq_sig : coq_Signature **)

    let coq_sig =
      coq_Sig A.arity

    (** val trsInt : symbol -> poly **)

    let trsInt f =
      fun_of_pairs_list A.arity f A.l
   end

  module P = PolyInt(TPolyInt_imp)

提取有什么问题?以及他们有这个错误的原因?如何纠正我的代码,我可以在提取后获得成功编译?

此外,我不想定义实现签名Arity的新模块。

我很抱歉我的代码缺少类型而且无法编译。我试图提出我的问题的想法。

0 个答案:

没有答案