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:

  1. z term of type naturals

  2. when e term of type naturals, n e term of type naturals.

  3. applying z or n 2 ways create natural. when given arbitrary natural, know either made 1 or other.

  4. two terms e1 , e2 of type naturals equal if , if both z or if respectively n t1 , n t2 t1 equal t2.

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

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -