All
I am trying to understand the Church numerals, mentioned in the SF-LF book, chp4.
Definition cnat := forall X : Type, (X -> X) -> X -> X.
Definition one : cnat :=
fun (X : Type) (f : X -> X) (x : X) => f x.
Check cnat.
Check one.
And I get
cnat
: Type
one
: cnat
It seems cnat is some kind of type, and function at the same time. How can it be both type and function? Anyone can help explain a little more about this?
The "
forall (X : Type)," syntax is a way to form a type, from a type parameterized byX.forall (X : Type), (X -> X) -> X -> Xis a type of functions, which given a typeXproduce a value of type(X -> X) -> X -> X(which is itself a function).The "
fun (X : Type) =>" syntax is a way to form a function, from a term parameterized byX.fun (X : Type) (f : X -> X) (x : X) => f xis a function, which given a typeXproduce the functionfun (f : X -> X) (x : X) => f x(which is itself a function).What
funandforallhave in common is that they involve binders, like(X : Type)(also like(f : X -> X),(x : X)).funis a construct that involves binders to form functions, but not all constructs that involve binders form functions:forallis a construct that involves binders to form types.