进口<;模块>;vs.Include<;模块>;在Coq模块系统中
在另一个模块(比如M)中包含M1的确切语义是什么?它与在模块M内导入M1有何不同?更准确地说,以下命令的语义是什么:进口<;模块>;vs.Include<;模块>;在Coq模块系统中,coq,Coq,在另一个模块(比如M)中包含M1的确切语义是什么?它与在模块M内导入M1有何不同?更准确地说,以下命令的语义是什么: Module Type M := M1 <+ M2 <+ M3. 模块类型M:=M1总结两个本地命令的语义: 命令Include M1(可用于模块或模块类型的定义)要求Coq复制M1的所有字段。因此,它的作用就像环境模块(分别为模块类型)内M1内容的“复制和粘贴” 命令Import M1(该命令也可用于模块或模块类型的定义中,但另外要求M1是一个模块)允许用户使用
Module Type M := M1 <+ M2 <+ M3.
模块类型M:=M1总结两个本地命令的语义:
- 命令
Include M1
(可用于模块或模块类型的定义)要求Coq复制M1
的所有字段。因此,它的作用就像环境模块(分别为模块类型)内M1
内容的“复制和粘贴”
- 命令
Import M1
(该命令也可用于模块或模块类型的定义中,但另外要求M1
是一个模块)允许用户使用短标识符引用M1
的字段(即,无需使用限定标识符M1.字段名称
)
接下来,语法模块类型M:=M1
Module Type M.
Include M1.
Include M2.
Include M3.
End M.
(********************************************)
(* Example involving a parameterized module *)
(********************************************)
(* A signature *)
Module Type MT.
Parameter t : Type.
End MT.
(* A bigger signature *)
Module Type MT1.
Include MT.
Parameter u : t.
Parameter f : t -> t.
End MT1.
(* A parameterized module *)
Module F1 (M1 : MT1).
Import M1. (* => we can now write f rather than M1.f *)
Definition fu := f u.
End F1.
(* A module implementing MT1 *)
Module M1 <: MT1. (* => check the signature but don't make the module opaque *)
Definition t := nat.
Definition u := O.
Definition f := S.
End M1.
(* Instantiation *)
Module FM1 := F1 M1.
Compute FM1.fu.
(********************************************)
(* Extra example: a parameterized signature *)
(* *)
(* It can be noted that this feature of Coq *)
(* module types has no equivalent in OCaml… *)
(********************************************)
Module Type MT2 (M : MT).
Parameter u : M.t.
Import M. (* => we can now write t rather than M.t *)
Parameter f : t -> t.
End MT2.
(* Another parameterized module *)
Module F2 (M : MT) (M2 : MT2 M).
Import M2.
Definition fu := f u.
End F2.
(* Modules implementing MT and MT2 *)
Module M <: MT.
Definition t := bool.
End M.
Module M2 <: MT2 M.
Definition u := false.
Definition f := negb.
End M2.
(* Instantiation *)
Module FM2 := F2 M M2.
Compute FM2.fu.