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.