为什么在Coq中,记录投影需要类型作为参数?

时间:2018-06-25 15:21:58

标签: coq

我想用Coq形式化数据结构(字符串连接):

Require Import List.

Record SeedPassword (A: Type): Type := {
    seed: list A;
    password: list A
}.

Record SeedPasswordConcatenation {A: Type} (S: SeedPassword A): Type := {
    concatenation: list A;
    proof: concatenation = (seed S ++ password S)
}.

但是,我在上一条记录中遇到了错误:

The term "S" has type "SeedPassword A" while it is expected to have type "Type".

为什么会期望Type?投影seed应该采用SeedPassword A,对吧?

1 个答案:

答案 0 :(得分:1)

About seed.

返回:

seed : forall A : Type, SeedPassword A -> list A

Argument scopes are [type_scope _]
seed is transparent
Expands to: Constant Top.seed

因此,seed需要类型,否则A中的SeedPassword A将不受限制。

您可以使用隐式参数解决问题,Coq会尝试推断出该参数。一种方法是放入

Set Implicit Arguments.

进入文件(通常在导入后)。或者,您可以像这样使用Arguments命令:

Record SeedPassword (A: Type): Type := {
    seed: list A;
    password: list A
}.
Arguments seed {A} _.
Arguments password {A} _.