Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload