I am having trouble understanding the principles of what a constructor is and how it works.
For example, in Coq, we have been taught to define the natural numbers like this:
Inductive nat : Type :=
| O : nat
| S : nat -> nat.
And have been told that S is a constructor, but what exactly does that mean?
If I then do:
Check (S (S (S (S O)))).
I get that it is 4 and of type nat.
How does this work, and how does Coq know that (S (S (S (S O)))) represents 4?
I guess the answer to this is some extremely clever background magic in Coq.
(S (S (S (S O))))as4is just a convenience that you should not let distract you. If you are at the point where you want to get a feeling of what a constructor is, define your own typenaturalswith constructorsZ(for zero) andN(for next). Then nothing magic will happen. - Pascal Cuoq