Thanks Cédric for your explanations.<br>To sum up, that&#39;s the way I understood all this, in a bit less formal way:<br>(Could help some, I guess)<br><br>Universal quantification (forall) means that the <b>caller </b>will instanciate (&quot;fix&quot;) the type variables, and that <b>callee </b>cannot know those types.<br>

<br>Existential quantification (through data E = forall a. E a) means that the <b>callee </b>will fix the type variables, and that the <b>caller </b>cannot know those types.<br><br>Now concerning the way existential (resp. universal) in a context becomes universal (resp. existential) in the outer context:<br>

<br>f :: forall a. a -&gt; a<br>means that when you&#39;re <i>inside </i>f, &#39;a&#39; will have been fixed to some type <i>that f cannot know</i>, only the outer context can.<br>f says &quot;I can work with any type a, so give me whatever type you want&quot;.<br>

<br>g :: (forall a. a -&gt; a) -&gt; Something<br>g f = ....<br>means the exact opposite: &#39;a&#39; is universally quantified in the signature of &#39;f&#39;, so it is existentially quantified in that of &#39;g&#39;. So it&#39;s equivalent to:<br>

g :: exists a. (a -&gt; a) -&gt; Something<br>g says &quot;I can only work with <b>some</b> specific types &#39;a&#39;, but as you don&#39;t know what they will be, you can but give me something that can will work with <b>any </b>type &#39;a&#39;.&quot;<br>

<br>And so on:<br>h :: ((forall a. a -&gt; a) -&gt; Something) -&gt; SomethingElse<br>h g = ...<br>h can also be written as follows, am I right?:<br>h :: forall a. ((a -&gt; a) -&gt; Something) -&gt; SomethingElse<br><br>

And to be sure:<br>foo :: forall a. a -&gt; (forall b. b -&gt; a)<br>is equivalent to:<br>foo :: forall a b. a -&gt; b -&gt; a<br>Right?<br><br>And:<br>foo :: forall a. a -&gt; ((forall b. b) -&gt; a)<br>to:<br>foo :: forall a. exists b. a -&gt; b -&gt; a<br>

??<br><br><div class="gmail_quote">2012/1/4 AUGER Cédric <span dir="ltr">&lt;<a href="mailto:sedrikov@gmail.com">sedrikov@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

Le Wed, 4 Jan 2012 20:13:34 +0100,<br>
<div class="im">Yves Parès &lt;<a href="mailto:limestrael@gmail.com">limestrael@gmail.com</a>&gt; a écrit :<br>
<br>
</div><div class="im">&gt; &gt; f :: forall a. (forall b. b -&gt; b) -&gt; a -&gt; a<br>
&gt; &gt; f id x = id x<br>
&gt;<br>
&gt; &gt; is very similar to the first case, x is still universally<br>
&gt; &gt; quantified (a) and there is an existential quantification in id (b).<br>
&gt;<br>
&gt; I don&#39;t get it. What is &#39;id&#39; existentially quantified in?<br>
&gt; f calls id so f will decide what will be its type. In this case,<br>
&gt; because it&#39;s applied to &#39;x&#39;, id type will get instanciated to &#39;a -&gt;<br>
&gt; a&#39; (where a is rigid, because bound by f signature).<br>
<br>
</div>Sorry I badly expressed it.<br>
<br>
I wanted to say that the &quot;b&quot; type variable in &quot;id&quot; is existentially<br>
quantified in the type of f.<br>
<div class="im"><br>
forall a. (forall b. b -&gt; b) -&gt; a -&gt; a<br>
</div>                  ^<br>
       existentially quantified in the overall type<br>
       but locally universally quantified in the type forall b. b -&gt; b<br>
<br>
It is the same things for data types.<br>
<br>
Consider the data type of lists:<br>
<br>
data List a = Nil<br>
            | Cons a (List a)<br>
<br>
its elimination principle is:<br>
<br>
list_rec :: forall a b. b -&gt; (a -&gt; list a -&gt; b -&gt; b) -&gt; List a -&gt; b<br>
list_rec acc f l = case l of<br>
                    Nil -&gt; acc<br>
                    Cons a l -&gt; f a l (list_rec acc f l)<br>
(it is the type version of the induction principle:<br>
 &quot;∀ P. P Nil ⇒ (∀ x      l,      P l ⇒ P (Cons x l)) ⇒ ∀ l,       P l&quot;<br>
 which by Curry-DeBruijn-Horward gives<br>
       b    -&gt; (  b -&gt; List a -&gt;  b  -&gt;      b     ) -&gt; list a -&gt; b<br>
 you can also find an &quot;optimized&quot; version where &quot;l&quot; is removed from<br>
 the recursion as its information can be stored in &quot;P l/b&quot;;<br>
 this function is exactly &quot;foldr&quot;<br>
)<br>
<br>
Now if we take a look at the elimination principle,<br>
<br>
forall a b. b -&gt; (a -&gt; list a -&gt; b -&gt; b) -&gt; List a -&gt; b<br>
<br>
contains only universally quantified variables.<br>
<br>
Cons as a function is also universally quantified:<br>
Cons :: forall a. a -&gt; List a -&gt; List a<br>
<br>
Nil as a function is also universally quantified:<br>
Nil :: forall a. List a<br>
<br>
So that elimination and introduction are all universally quantified.<br>
(Nothing very surprising here!)<br>
=====================================================================<br>
<br>
Now for the existential part:<br>
<br>
data Existential = forall b. ExistIntro b<br>
<br>
What is its elimination principle (ie. what primitive function allows<br>
us to use it for all general purpouses)?<br>
<br>
Existential types are less easy to manipulate, since in fact they<br>
require functions which takes universally quantified functions as<br>
arguments.<br>
<br>
existential_elim :: forall b. (forall a. a -&gt; b) -&gt; Existential -&gt; b<br>
existential_elim f e = case e of<br>
                        ExistIntro x -&gt; f x<br>
(∀ P. (∀ a. a ⇒ P (ExistIntro a)) ⇒ ∀ e. P e)<br>
<br>
Here, you can see that &quot;a&quot; is existentially quantified (isn&#39;t it<br>
normal for a type containing existentials)!<br>
<br>
Note also that its introduction rule:<br>
ExistIntro :: forall a. a -&gt; Existential<br>
is also universally quantified (but with a type variable which doesn&#39;t<br>
appear in the introduced type).<br>
<br>
Which is not to mess with:<br>
<br>
data Universal = UnivIntro (forall a. a)<br>
<br>
elimination principle:<br>
univ_elim :: forall b. ((forall a. a) -&gt; b) -&gt; Universal -&gt; b<br>
univ_elim f u = case u of<br>
                 UnivIntro poly -&gt; f poly<br>
(∀ P. (∀ (poly:∀a.a). P (UnivIntro poly)) ⇒ ∀ u. P u)<br>
<br>
Here you can see that you don&#39;t need special syntax, and again, the<br>
elimination principle is universally quantified in both a and b.<br>
Its introduction has some existential quantification (which doesn&#39;t<br>
appear in the introduced type).<br>
<div class="HOEnZb"><div class="h5"><br>
&gt;<br>
&gt; 2012/1/4 AUGER Cédric &lt;<a href="mailto:sedrikov@gmail.com">sedrikov@gmail.com</a>&gt;<br>
&gt;<br>
&gt; &gt; Le Wed, 4 Jan 2012 14:41:21 +0100,<br>
&gt; &gt; Yves Parès &lt;<a href="mailto:limestrael@gmail.com">limestrael@gmail.com</a>&gt; a écrit :<br>
&gt; &gt;<br>
&gt; &gt; &gt; &gt; I expected the type of &#39;x&#39; to be universally quantified, and<br>
&gt; &gt; &gt; &gt; thus can be unified with &#39;forall a. a&#39; with no problem<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; As I get it. &#39;x&#39; is not universally quantified. f is. [1]<br>
&gt; &gt; &gt; x would be universally quantified if the type of f was :<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; f :: (forall a. a) -&gt; (forall a. a)<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; [1] Yet here I&#39;m not sure this sentence is correct. Some heads-up<br>
&gt; &gt; &gt; from a type expert would be good.<br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; For the type terminology (for Haskell),<br>
&gt; &gt;<br>
&gt; &gt; notations:<br>
&gt; &gt; a Q∀ t := a universally quantified in t<br>
&gt; &gt; a Q∃ t := a existentially quantified in t<br>
&gt; &gt; a Q∀∃ t := a universally (resp. existentially) quantified in t<br>
&gt; &gt; a Q∃∀ t := a existentially (resp. universally) quantified in t<br>
&gt; &gt;<br>
&gt; &gt; Two different names are expected to denote two different type<br>
&gt; &gt; variables. A type variable is not expected to be many times<br>
&gt; &gt; quantified (else, it would be meaningless, a way to omit this<br>
&gt; &gt; hypothesis is to think of path to quantification instead of<br>
&gt; &gt; variable name; to clarify what I mean, consider the following<br>
&gt; &gt; expression:<br>
&gt; &gt;<br>
&gt; &gt; forall a. (forall a. a) -&gt; a<br>
&gt; &gt;<br>
&gt; &gt; we cannot tell what &quot;a is existentially quantified&quot; means, since we<br>
&gt; &gt; have two a&#39;s; but if we rename them into<br>
&gt; &gt;<br>
&gt; &gt; forall a. (forall b. b) -&gt; a<br>
&gt; &gt; or<br>
&gt; &gt; forall b. (forall a. a) -&gt; b<br>
&gt; &gt;<br>
&gt; &gt; , the meaning is clear; in the following, I expect to always be in a<br>
&gt; &gt; place where it is clear.)<br>
&gt; &gt;<br>
&gt; &gt; rules:<br>
&gt; &gt; (1)   ⊤    ⇒ a Q∀ forall a. t<br>
&gt; &gt; (2)b Q∀∃ t ⇒ b Q∀∃ forall a. t<br>
&gt; &gt; (3)a Q∀∃ u ⇒ a Q∀∃ t -&gt; u (in fact it is the same rule as above,<br>
&gt; &gt;                        since &quot;-&gt;&quot; is an non binding forall in<br>
&gt; &gt;                        type theory)<br>
&gt; &gt; (4)a Q∀∃ t ⇒ a Q∃∀ t -&gt; u<br>
&gt; &gt;<br>
&gt; &gt; So in this context, we cannot say that &#39;x&#39; is universally or<br>
&gt; &gt; existentially quantified, but that the &#39;type of x&#39; is universally or<br>
&gt; &gt; existentially quantified &#39;in&#39; some type (assuming that the type of x<br>
&gt; &gt; is a type variable).<br>
&gt; &gt;<br>
&gt; &gt; so:<br>
&gt; &gt;<br>
&gt; &gt; a Q∃ (forall a. a -&gt; a) -&gt; forall b. b -&gt; b<br>
&gt; &gt;  since (4) and &quot;a Q∀ forall a. a -&gt; a&quot; due to (1)<br>
&gt; &gt;<br>
&gt; &gt; and<br>
&gt; &gt;<br>
&gt; &gt; b Q∀ (forall a. a -&gt; a) -&gt; forall b. b -&gt; b<br>
&gt; &gt;  since (3) and &quot;b Q∀ forall b. b -&gt; b&quot; due to (1)<br>
&gt; &gt;<br>
&gt; &gt; The quick way to tell is count the number of unmatched opening<br>
&gt; &gt; parenthesis before the quantifying forall (assuming you don&#39;t put<br>
&gt; &gt; needless parenthesis) if it is even, you are universally<br>
&gt; &gt; quantified, if it is odd, you are existentially quantified.<br>
&gt; &gt;<br>
&gt; &gt; So in:<br>
&gt; &gt;<br>
&gt; &gt; f :: (forall a. a -&gt; a) -&gt; forall b. b -&gt; b<br>
&gt; &gt; f id x = id x<br>
&gt; &gt;<br>
&gt; &gt; the type of &#39;x&#39; (b) is universally quantified in the type of f,<br>
&gt; &gt; and the type of &#39;id&#39; contains an existential quantification in the<br>
&gt; &gt; type of f (a).<br>
&gt; &gt;<br>
&gt; &gt; In:<br>
&gt; &gt;<br>
&gt; &gt; f :: forall a. (a -&gt; a) -&gt; a -&gt; a<br>
&gt; &gt; f id x = id x<br>
&gt; &gt;<br>
&gt; &gt; the type of &#39;x&#39; (a) is universally quantified in the type of f;<br>
&gt; &gt; there is no existential quantification.<br>
&gt; &gt;<br>
&gt; &gt; f :: forall a. (forall b. b -&gt; b) -&gt; a -&gt; a<br>
&gt; &gt; f id x = id x<br>
&gt; &gt;<br>
&gt; &gt; is very similar to the first case, x is still universally<br>
&gt; &gt; quantified (a) and there is an existential quantification in id (b).<br>
&gt; &gt;<br>
&gt; &gt; I guess that the only difference is that when you do a<br>
&gt; &gt; &quot;f id&quot; in the last case, you might get an error as the program<br>
&gt; &gt; needs to know the &quot;a&quot; type before applying &quot;id&quot; (of course if there<br>
&gt; &gt; is some use later in the same function, then the type can be<br>
&gt; &gt; inferred)<br>
&gt; &gt;<br>
&gt; &gt; Hope that I didn&#39;t write wrong things, and if so that you can tell<br>
&gt; &gt; now for sure if a type is universally or existentially quantified.<br>
&gt; &gt;<br>
<br>
</div></div></blockquote></div><br>