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

Quy*_*yen 6 ocaml coq coq-extraction

我有一个功能PolyInterpretation(http://color.inria.fr/doc/CoLoR.PolyInt.APolyInt.html)

Definition PolyInterpretation := forall f : Sig, poly (arity f).
Run Code Online (Sandbox Code Playgroud)

和模块签名TPolyInt(http://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).
Run Code Online (Sandbox Code Playgroud)

然后在我的文件中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.
Run Code Online (Sandbox Code Playgroud)

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

然后我定义了一个模块P:

Module Export P := PolyInt TPolyInt_imp.
Run Code Online (Sandbox Code Playgroud)

Coq证明助手接受的定义P之上.

然后我用提取物提取到Ocaml.

我把它写在另一个文件中: extraction.v

Extraction Language Ocaml.
Set Extraction Optimize.
Set Extraction AccessOpaque.
Separate Extraction rainbow.P.
Run Code Online (Sandbox Code Playgroud)

它工作正常.

这是提取后的代码

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)
Run Code Online (Sandbox Code Playgroud)

因为在functor中TPolyInt_imp他们包含Variable并生成failwith AXIOM然后我决定定义一个新的签名来包含所有这些变量.

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

然后定义一个以(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.
Run Code Online (Sandbox Code Playgroud)

然后我使用提取将其提取出来Ocaml.

Extraction Language Ocaml.
Set Extraction Optimize.
Set Extraction AccessOpaque.
Separate Extraction S.
Run Code Online (Sandbox Code Playgroud)

然后我得到一个错误说:

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
Run Code Online (Sandbox Code Playgroud)

提取后的代码:

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)
Run Code Online (Sandbox Code Playgroud)

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

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

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