[英]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.