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:
zterm of typenaturalswhen
eterm of typenaturals,n eterm of typenaturals.applying
zorn2 ways create natural. when given arbitrary natural, know either made 1 or other.two terms
e1,e2of typenaturalsequal if , if bothzor if respectivelyn t1,n t2t1equalt2.
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