In Coq, everything has a type. Type
is no exception: if you ask Coq with the Check
command, it will tell you that its type is... Type
!
Actually, this is a bit of a lie. If you ask for more details by issuing the directive Set Printing Universes.
, Coq will tell you that that Type
is not the same as the first one, but a "bigger" one. Formally, every Type
has an index associated to it, called its universe level. This index is not visible when printing expressions usually. Thus, the correct answer for that question is that Type_i
has type Type_j
, for any index j > i
. This is needed to ensure the consistency of Coq's theory: if there were only one Type
, it would be possible to show a contradiction, similarly to how one gets a contradiction in set theory if you assume that there is a set of all sets.
To make working with type indices easier, Coq gives you some flexibility: no type has actually a fixed index associated with it. Instead, Coq generates one new index variable every time you write Type
, and keeps track of internal constraints to ensure that they can be instantiated with concrete values that satisfy the restrictions required by the theory.
The error message you saw means that Coq's constraint solver for universe levels says that there can't be a solution to the constraint system you asked for. The problem is that the forall
in the definition of nat
is quantified over Type_i
, but Coq's logic forces nat
to be itself of type Type_j
, with j > i
. On the other hand, the application n nat
requires that j <= i
, resulting in a non-satisfiable set of index constraints.
-type-in-type
flag to Coq to disable all universe consistency checks. Using this flag is dangerous because it enables Girard's paradox (explained here). – Donohue-type-in-type
only works for Coq 8.5 beta (not for the currently stable 8.4 version) – Parenteau