[英]How to define exp for Church Numerals in coq?
I am currently learning coq thanks to the Software Fondation's ebook .感谢Software Fondation 的电子书,我目前正在学习 coq。 I successfully wrote the addition as follow:
我成功编写了如下添加:
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).
But I'm stuck with exp because of the following error:但是由于以下错误,我被 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).
*)
Since they wrote:因为他们写道:
If you hit a "Universe inconsistency" error, try iterating over a different type.
如果您遇到“Universe inconsistency”错误,请尝试迭代不同的类型。 Iterating over cnat itself is usually problematic.
迭代cnat 本身通常是有问题的。 I tried using the definition of cnat:
我尝试使用cnat的定义:
Definition exp (n m : cnat) : cnat :=
m (forall X : Type, (X -> X) -> X) (mult n) n.
But then I have:但后来我有:
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).
I do not ask for a solution, but I'd really like to understand these errors.我不要求解决方案,但我真的很想了解这些错误。 Thanks for your lights !
谢谢你的灯!
Just post the solution for others who got stuck on this problem.只需为其他陷入此问题的人发布解决方案。
Definition exp (n m : cnat) : cnat :=
fun X => (m (X->X)) (n X).
The key is to understand m (X->X)
.关键是理解
m (X->X)
。 The figure below might be helpful.下图可能会有所帮助。
An example of 2 ^ 2 2 ^ 2 的示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.