[英]Use False_rec to build an aliased list type in Coq
I'd like to create a dependent function, but I am running into a type mismatch error on the False_rec
term. 我想创建一个依赖函数,但是在False_rec
术语上False_rec
类型不匹配错误。 I'm trying to do something similar to the following: 我正在尝试执行以下操作:
Definition env A := list A.
Fixpoint zip (xs ys : env nat) (H : length xs = length ys) : env (nat * nat).
Proof.
refine
(match xs, ys with
| [], [] => []
| x :: xs, y :: ys =>
(x, y) :: zip xs ys _
| _, _ => False_rec _ _
end).
...
However, I receive the following error: 但是,我收到以下错误:
The term "False_rec ?P ?f" has type "?P" while it is expected to have type
"env (nat * nat)" (unable to find a well-typed instantiation for
"?P": cannot ensure that "Type" is a subtype of "Set").
The standard list, when it is given a Set, becomes a set itself, but it seems that it does not do so when aliased in this way. 当标准列表被赋予一个Set时,它本身就是一个set,但是当以这种方式进行别名时,它似乎并没有这样做。 For example: 例如:
Check (list nat). (* list nat : Set *)
Check (env nat). (* env nat : Type *)
Is there a reason for this mismatch? 是否存在这种不匹配的原因? And is there a way to work around it? 有办法解决吗? (For example, can I convince Coq that (env nat)
is a Set
? Or can I use a more general False_rec
function that operates on Type
instead of Set
?) (例如,我可以说服Coq (env nat)
是Set
吗?还是可以使用对Type
而不是Set
操作的更通用的False_rec
函数?)
Is there a reason for this mismatch? 是否存在这种不匹配的原因?
Yes. 是。 Type
is an entity that can contain (big) things that won't fit into Set
. Type
是一个实体,可以包含Set
不适合的(大)东西。 Eg nat
fits into Set
, but Set
does not fit into itself. 例如, nat
适合Set
,但Set
不适合自身。 I think there should be more than one excellent answers on SO explaining this issue. 我认为应该有不止一个出色的答案来解释这个问题。
(For example, can I convince Coq that
(env nat)
is aSet
? (例如,我可以说服Coq(env nat)
是Set
吗?
You can use explicit type annotations: 您可以使用显式类型注释:
Definition env (A : Set) : Set := list A.
Or can I use a more general
False_rec
function that operates onType
instead ofSet
? 还是可以使用在Type
而不是Set
上运行的更通用的False_rec
函数?
Yes, you can. 是的你可以。 It's called False_rect
. 它称为False_rect
。
Observe that simple match
-expression won't work in your case (regardless of Set
/ Type
business), you will need to use dependent pattern matching. 请注意,简单的match
-expression在您的情况下不起作用(无论Set
/ Type
业务如何),您将需要使用依赖的模式匹配。 Another possibility is to use proof mode to define your function. 另一种可能性是使用证明模式来定义您的功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.