在Coq模块系统中导入<module>与Include <module>

时间:2018-02-17 04:55:51

标签: coq

另一个模块中Include M1的确切语义是什么,比方说M?它与在模块M中执行Import M1有什么不同?更确切地说,以下命令的语义是什么:

Module Type M := M1 <+ M2 <+ M3.

1 个答案:

答案 0 :(得分:5)

总结两种白话命令的语义:

  • 命令Include M1(可用于模块的定义模块类型)要求Coq复制所有字段M1。因此,它就像一个&#34;复制和粘贴&#34;环境模块内部M1的内容(分别为模块类型)。
  • 命令Import M1(也可用于模块模块类型的定义,但另外需要M1是一个模块)允许人们使用他们的短标识符来引用M1的字段(即,无需使用限定标识符M1.field_name

接下来,语法Module Type M := M1 <+ M2 <+ M3是以下的快捷方式:

Module Type M.
  Include M1.
  Include M2.
  Include M3.
End M.

Coq参考手册的相关部分为Sect. 2.5.1 (Include)Sect. 2.5.8 (Import),您可能还需要查看Export命令({{1}的变体}})。

如果在某些时候你在ImportInclude之间犹豫不决,你应该首先尝试使用Import,因为它会产生更轻的效果(它赢得了#39} ; t克隆指定模块的内容,但只定义较短的名称。)

最后,下面是两个综合示例,说明了Coq中模块,模块类型和仿函数的使用以及命令ImportInclude

Import

我记得Compute(********************************************) (* 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.

的快捷方式
Eval vm_compute in
相关问题