有谁可以告诉我为什么COQ中的以下投影功能不起作用?
Require Import Vector.
Require Import Fin.
Definition Proj {n:nat}{p:nat}(x:t p+{(exists m : nat, n=p+m)}):=
match x with
inleft y => y
|_ => F1
end.
我收到以下错误:
Error:
In environment
n : nat
p : nat
x : t p + {(exists m : nat, n = p + m)}
e : exists m : nat, n = p + m
The term "F1" has type "t (S ?6 (* [n, p, x, e, e] *))"
while it is expected to have type "t p".
另一方面,使用p的具体值可以正常工作:
Require Import Vector.
Require Import Fin.
Definition Proj {n:nat}(x:t 3 + {(exists m : nat, n=3+m)}):=
match x with
inleft y => y
|_ => F1
end.
Eval compute in (Proj (of_nat 2 3)) = FS (FS F1): t 3.
答案 0 :(得分:1)
我假设您希望Proj
返回t p
类型的值。 p = 0
这是不可能的(因为t 0
是空集),这就是为什么你无法为任意Proj
实现p
的原因。如果您扩展函数以获取p
不等于0
的证明,那么您可以按如下方式实现它。阅读Adam's CPDT Chapter on Dependent Types以了解此处发生了什么。
Definition Proj {n:nat} {p:nat} (x:t p+{(exists m : nat, n=p+m)}) : p <> 0 -> t p :=
match x with
| inleft y => fun _ => y
| _ => match p with
| 0 => fun h => False_rect _ (h eq_refl)
| S _ => fun _ => F1
end
end.