What is a constructor in Coq? -
i having trouble understanding principles of constructor , how works.
for example, in coq, have been taught define natural numbers this:
inductive nat : type := | o : nat | s : nat -> nat.
and have been told s
constructor, mean?
if do:
check (s (s (s (s o)))).
i 4
, of type nat
.
how work, , how coq know (s (s (s (s o))))
represents 4
?
i guess answer extremely clever background magic in coq.
inductive naturals : type := | z : naturals | n : naturals -> naturals.
says following things:
z
term of typenaturals
when
e
term of typenaturals
,n e
term of typenaturals
.applying
z
orn
2 ways create natural. when given arbitrary natural, know either made 1 or other.two terms
e1
,e2
of typenaturals
equal if , if bothz
or if respectivelyn t1
,n t2
t1
equalt2
.
you can see how these rules generalize arbitrary inductive type definitions. however, turns out when type definition constructors of shape of z
, n
, these properties correspond more or less peano's axioms natural numbers. why type named nat
pre-defined in coq constructors of these shapes used represent natural numbers. type receives special treatment because gets tiring manipulate raw form, special treatments there convenience.
Comments
Post a Comment