1

I am currently learning coq thanks to the Software Fondation's ebook. 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:

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. Iterating over cnat itself is usually problematic. I tried using the definition of 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 !

4

1 回答 1

2

只需为其他陷入此问题的人发布解决方案。

Definition exp (n m : cnat) : cnat := 
  fun X => (m (X->X)) (n X).

关键是了解m (X->X)。下图可能会有所帮助。

2 ^ 2 的示例

2 ^ 2 的示例

于 2020-11-21T20:14:27.317 回答