[英]How to define exp for Church Numerals in coq?
感谢Software Fondation 的电子书,我目前正在学习 coq。 我成功编写了如下添加:
Definition cnat := forall X : Type, (X -> X) -> X -> X.
Definition plus (n m : cnat) : cnat :=
fun (X : Type) (f : X -> X) (x : X) => n X f (m X f x).
但是由于以下错误,我被 exp 卡住了:
Definition exp (n m : cnat) : cnat :=
m cnat (mult n) n.
(*
In environment
n : cnat
m : cnat
The term "cnat" has type "Type@{cnat.u0+1}"
while it is expected to have type "Type@{cnat.u0}"
(universe inconsistency).
*)
因为他们写道:
如果您遇到“Universe inconsistency”错误,请尝试迭代不同的类型。 迭代cnat 本身通常是有问题的。 我尝试使用cnat的定义:
Definition exp (n m : cnat) : cnat :=
m (forall X : Type, (X -> X) -> X) (mult n) n.
但后来我有:
In environment
n : cnat
m : cnat
The term "mult n" has type "cnat -> cnat"
while it is expected to have type
"(forall X : Type, (X -> X) -> X) -> forall X : Type, (X -> X) -> X"
(universe inconsistency).
我不要求解决方案,但我真的很想了解这些错误。 谢谢你的灯!
只需为其他陷入此问题的人发布解决方案。
Definition exp (n m : cnat) : cnat :=
fun X => (m (X->X)) (n X).
关键是理解m (X->X)
。 下图可能会有所帮助。
2 ^ 2 的示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.