I'm learning Coq by reading the book "Certified Programming with Dependent Types" and I'm having trouble udnerstanding forall
syntax.
As an example let's think this mutually inductive data type: (code is from the book)
Inductive even_list : Set :=
| ENil : even_list
| ECons : nat -> odd_list -> even_list
with odd_list : Set :=
| OCons : nat -> even_list -> odd_list.
and this mutually recursive function definitions:
Fixpoint elength (el : even_list) : nat :=
match el with
| ENil => O
| ECons _ ol => S (olength ol)
end
with olength (ol : odd_list) : nat :=
match ol with
| OCons _ el => S (elength el)
end.
Fixpoint eapp (el1 el2 : even_list) : even_list :=
match el1 with
| ENil => el2
| ECons n ol => ECons n (oapp ol el2)
end
with oapp (ol : odd_list) (el : even_list) : odd_list :=
match ol with
| OCons n el' => OCons n (eapp el' el)
end.
and we have induction schemes generated:
Scheme even_list_mut := Induction for even_list Sort Prop
with odd_list_mut := Induction for odd_list Sort Prop.
Now what I don't understand is, from the type of even_list_mut
I can see it takes 3 arguments:
even_list_mut
: forall (P : even_list -> Prop) (P0 : odd_list -> Prop),
P ENil ->
(forall (n : nat) (o : odd_list), P0 o -> P (ECons n o)) ->
(forall (n : nat) (e : even_list), P e -> P0 (OCons n e)) ->
forall e : even_list, P e
But in order to apply it we need to supply it two parameters, and it replaces the goal with 3 premises (for P ENil
, forall (n : nat) (o : odd_list), P0 o -> P (ECons n o)
and forall (n : nat) (e : even_list), P e -> P0 (OCons n e)
cases).
So it's like it actually gets 5 parameters, not 3.
But then this idea fails when we think of this types:
fun el1 : even_list =>
forall el2 : even_list, elength (eapp el1 el2) = elength el1 + elength el2
: even_list -> Prop
and
fun el1 el2 : even_list => elength (eapp el1 el2) = elength el1 + elength el2
: even_list -> even_list -> Prop
Can anyone explain how does forall
syntax work?
Thanks,