在下面的开发中,当我尝试定义单方法类型类的实例时,我遇到了一个奇怪的错误:
Universe ARG. Definition ARG := Type@{ARG}.
Universe ARG0. Definition ARG0 := Type@{ARG0}.
Universe ARG1. Definition ARG1 := Type@{ARG1}.
Universe ARG2. Definition ARG2 := Type@{ARG2}.
Constraint ARG<ARG0, ARG0<ARG1, ARG1<ARG2.
Inductive SR: ARG := Phy | Sen | Inf | Lim.
Parameter CA: Prop.
Parameter X: SR -> CA -> ARG -> ARG.
Parameter X': SR -> CA -> ARG -> ARG0.
Parameter XP: SR -> CA -> ARG -> ARG1.
Parameter XP': SR -> CA -> ARG -> ARG2.
Inductive tri:Set := one | two | three.
Definition iX' (t:tri): SR -> CA -> ARG -> ARG2 := match t with one => X' | two => XP | three => XP' end.
Parameter gk:> forall (b:SR)(d:CA)(c:ARG), X' b d c -> iX' one b d c.
Parameter gl:> forall (b:SR)(d:CA)(c:ARG), XP b d c -> iX' two b d c.
Parameter gm:> forall (b:SR)(d:CA)(c:ARG), XP' b d c -> iX' three b d c.
Definition iX'bsko {b:tri}{s:SR}{k:CA}{o:ARG} := iX' b s k o.
Parameter foo: forall {b:tri}{s:SR}{k:CA}{o:ARG}, iX' b s k o.
Fail Check foo: forall {b:tri}{s:SR}{k:CA}{o:ARG}, iX' b s k o. (*Why?*)
Check foo: iX'bsko.
Class CONN := p5 (x y z:ARG): x -> y -> z.
Instance cco: CONN := fun x y iX'bsko (_:x) (_:y) => foo.
(* Error: "foo" has type "iX' ?b@{y0:=x0; y1:=y0} ?s@{y0:=x0; y1:=y0} ?k@{y0:=x0; y1:=y0} ?o@{y0:=x0; y1:=y0}"
while it is expected to have type "iX'bsko". *)
错误的原因似乎是foo
没有类型 iX'bsko
,而上面 2 行 foo: iX'bsko
类型已检查。我该如何解决这个问题?
最佳答案
要回答您的评论(*为什么?*)
,问题是foo
意味着@foo _ _ _ _
。成功如下:
Check @foo: forall {b:tri}{s:SR}{k:CA}{o:ARG}, iX' b s k o.
为了回答你的问题,你已经搬起石头砸自己的脚,用局部不透明变量来遮蔽全局 iX'bsko
。
如果你改变
Instance cco: CONN := fun x y iX'bsko (_:x) (_:y) => foo.
至
Instance cco: CONN := fun x y not_really_iX'bsko' (_:x) (_:y) => foo.
你得到了
Error:
In environment
x : ARG
y : ARG
not_really_iX'bsko : ARG
x0 : x
y0 : y
The term "foo" has type
"iX' ?b@{y0:=x0; y1:=y0} ?s@{y0:=x0; y1:=y0} ?k@{y0:=x0; y1:=y0}
?o@{y0:=x0; y1:=y0}" while it is expected to have type
"not_really_iX'bsko".
这并不奇怪。 CONN
是forall x y z 的类型:Type@{ARG}, x -> y -> z
。该类型没有居民:
Lemma no_conn : CONN -> False.
Proof. exact (fun cco => cco True True False I I). Qed.
也许您打算将 x
、y
和 z
参数改为 CONN
,编写类似的内容这个?
Class CONN (x y z:ARG) := p5 : x -> y -> z.
Instance cco x y : CONN x y iX'bsko := fun (_:x) (_:y) => foo.
请注意,此操作会失败并显示更清晰的错误消息:
The term "iX'bsko" has type "ARG2" while it is expected to have type
"ARG" (universe inconsistency).
如果你这样做
Class CONN (x y z:ARG2) := p5 : x -> y -> z.
Instance cco x y : CONN x y iX'bsko := fun (_:x) (_:y) => foo.
然后你就得到了
Error: Cannot infer the implicit parameter b of iX'bsko whose type is
"tri" in environment:
x, y : ARG2
关于class - Coq:定义类型类实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46869324/