The class OfNat α n
powers the numeric literal parser. If you write
37 : α
, Lean will attempt to synthesize OfNat α 37
, and will generate
the term (OfNat.ofNat 37 : α)
.
There is a bit of infinite regress here since the desugaring apparently
still contains a literal 37
in it. The type of expressions contains a
primitive constructor for "raw natural number literals", which you can directly
access using the macro nat_lit 37
. Raw number literals are always of type Nat
.
So it would be more correct to say that Lean looks for an instance of
OfNat α (nat_lit 37)
, and it generates the term (OfNat.ofNat (nat_lit 37) : α)
.
Instance Constructor
OfNat.mk.{u}
Methods
ofNat : α
The OfNat.ofNat
function is automatically inserted by the parser when
the user writes a numeric literal like 1 : α
. Implementations of this
typeclass can therefore customize the behavior of n : α
based on n
and
α
.