我想用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
,对吧?
答案 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} _.