I'd like to create a dependent function, but I am running into a type mismatch error on the False_rec
term. 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. 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
?)
Is there a reason for this mismatch?
Yes. Type
is an entity that can contain (big) things that won't fit into Set
. Eg nat
fits into Set
, but Set
does not fit into itself. 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
?
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
?
Yes, you can. It's called 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. Another possibility is to use proof mode to define your function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.