Also, I have to admit I was a bit handwavy here; I meant P in a metatheoretic sense, that is &quot;P(a) is some type which contains &#39;a&#39; as a free variable&quot;, and thus the &#39;theorem&#39; is really a collection of theorems parametrized on the P you choose.<br>
<br>For example, P(a) could be &quot;Show a &amp; a -&gt; Int&quot;; in that case we get the theorem<br><br>exists a. (Show a, a -&gt; Int)<br> &lt;=&gt;<br>forall r. (forall a. Show a =&gt; (a -&gt; Int) -&gt; r) -&gt; r<br>
<br>as witnessed by the following code (using the ExistentialQuantification and RankNTypes extensions)<br><br>data P = forall a. Show a =&gt; MkP (a -&gt; Int)<br>type CPS_P r = (forall a. Show a =&gt; (a -&gt; Int) -&gt; r) -&gt; r<br>
<br>isoR :: P -&gt; forall r. CPS_P r<br>isoR (MkP f) k =<br>   -- pattern match on MkP brings a fresh type T into scope,<br>   --     along with f :: T -&gt; Int, and the constraint Show T.<br>   -- k :: forall a. Show a =&gt; (a -&gt; Int) -&gt; r<br>
   -- so, k {T} f :: r<br><br><br>isoL :: (forall r. CPS_P r) -&gt; P<br>isoL k = k (\x -&gt; MkP x)<br>-- k :: forall r. (forall a. Show a =&gt; (a -&gt; Int) -&gt; r) -&gt; r<br>-- k {P} = (forall a. Show a =&gt; (a -&gt; Int) -&gt; P) -&gt; P<br>
-- MkP :: forall a. Show a =&gt; (a -&gt; Int) -&gt; P<br>-- therefore, k {P} MkP :: P<br><br>Aside: the type &#39;exists a. (Show a, a -&gt; Int)&#39; is a bit odd, and is another reason we don&#39;t have first class existentials in Haskell.  The &#39;forall&#39; side is using currying (a -&gt; b -&gt; r) &lt;=&gt; ((a,b) -&gt; r) which works because the constraint =&gt; can be modeled by dictionary passing.  But we don&#39;t have a simple way to represent the dictionary (Show a) as a member of a tuple.<br>
<br>One answer is to pack it up in another &quot;existential&quot;; I find this a bit of a misnomer since there&#39;s nothing existential about this data type aside from the dictionary:<br><br>data ShowDict a = Show a =&gt; MkShowDict<br>
<br>Then the theorem translation is a bit more straightforward:<br><br>data P = forall a. MkP (ShowDict a, a -&gt; Int)<br>type CPS_P r = (forall a. (ShowDict a, a -&gt; Int) -&gt; r) -&gt; r<br><br>-- theorem: P &lt;=&gt; forall r. CPS_P r<br>
<br>isoL :: P -&gt; forall r. CPS_P r<br>isoL (MkP x) k = k x<br><br>isoR :: (forall r. CPS_P r) -&gt; P<br>isoR k = k (\x -&gt; MkP x)<br><br>  -- ryan<br><br><div class="gmail_quote">On Sat, Aug 18, 2012 at 8:24 PM, wren ng thornton <span dir="ltr">&lt;<a href="mailto:wren@freegeek.org" target="_blank">wren@freegeek.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 8/17/12 12:54 AM, Alexander Solla wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
On Thu, Aug 16, 2012 at 8:07 PM, wren ng thornton &lt;<a href="mailto:wren@freegeek.org" target="_blank">wren@freegeek.org</a>&gt; wrote:<br>
</div><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Though bear in mind we&#39;re discussing second-order quantification here, not<br>
first-order.<br>
</blockquote>
<br>
Can you expand on what you mean here?  I don&#39;t see two kinds of<br>
quantification in the type language (at least, reflexively, in the context<br>
of what we&#39;re discussing).  In particular, I don&#39;t see how to quantify over<br>
predicates for (or sets of, via the extensions of the predicates) types.<br>
<br>
Is Haskell&#39;s &#39;forall&#39; doing double duty?<br>
</div></blockquote>
<br>
Nope, it&#39;s the &quot;forall&quot; of mathematics doing double duty :)<br>
<br>
Whenever doing quantification, there&#39;s always some domain being quantified over, though all too often that domain is left implicit; whence lots of confusion over the years. And, of course, there&#39;s the scope of the quantification, and the entire expression. For example, consider the expression:<br>

<br>
    forall a. P(a)<br>
<br>
The three important collections to bear in mind are:<br>
(1) the collection of things a ranges over<br>
(2) the collection of things P(a) belongs to<br>
(3) the collection of things forall a. P(a) belongs to<br>
<br>
So if we think of P as a function from (1) to (2), and name the space of such functions (1-&gt;2), then we can think of the quantifier as a function from (1-&gt;2) to (3).<br>
<br>
<br>
When you talk to logicians about quantifiers, the first thing they think of is so-called &quot;first-order&quot; quantification. That is, given the above expression, they think that the thing being quantified over is a collection of &quot;individuals&quot; who live outside of logic itself[1]. For example, we could be quantifying over the natural numbers, or over the kinds of animals in the world, or any other extra-logical group of entities.<br>

<br>
In Haskell, when we see the above expression we think that the thing being quantified over is some collection of types[2]. But, that means when we think of P as a function it&#39;s taking types and returning types! So the thing you&#39;re quantifying over and the thing you&#39;re constructing are from the same domain[3]! This gets logicians flustered and so they call it &quot;second-order&quot; (or more generally, &quot;higher-order&quot;) quantification. If you assert the primacy of first-order logic, it makes sense right? In the first-order case we&#39;re quantifying over individuals; in the second-order case we&#39;re quantifying over collections of individuals; so third-order would be quantifying over collections of collections of individuals; and on up to higher orders.<br>

<br>
<br>
Personally, I find the names &quot;first-order&quot; and &quot;second-order&quot; rather dubious--- though the distinction is a critical one to make. Part of the reason for its dubiousness can be seen when you look at PTSes which make explicit that (1), (2), and (3) above can each be the same or different in all combinations. First-order quantification is the sort of thing you get from Pi/Sigma types in dependently typed languages like LF; second-order quantification is the sort of thing you get from the forall/exists quantifiers in polymorphic languages like System F. But the Barendregt cube makes it clear that these are *orthogonal* features. Neither one of them comes &quot;first&quot; or &quot;second&quot;; they just do very different things. Logicians thought first of first-order quantification, so they consider that primitive and worry about the complications of dealing with second-/higher-order quantification. Until recently type theory was focused on polymorphism of various sorts, so that&#39;s considered primitive or at least easier, whereas dependent types are exotic and worrisome/hard.<br>

<br>
<br>
[1] This is also the root of the distinction between &quot;functions&quot;, &quot;predicates&quot;, and &quot;logical connectives&quot; in traditional logic. Functions map individuals to individuals; predicates map individuals to propositions/truth-values; and connectives map propositions/TVs to propositions/TVs. Though, traditionally, the set of connectives is taken to be small and fixed whereas functions and predicates are left to be defined by a &quot;signature&quot;.<br>

<br>
[2] Namely monotypes. If we allowed quantified variables to be instantiated with polymorphic types, then we&#39;d get &quot;impredicative&quot; quantification. Impredicativity can be both good and bad, depending on what you&#39;re up to.<br>

<br>
[3] Well, they&#39;re only the same domain for impredicative quantification. Otherwise the collection of types you&#39;re constructing is &quot;bigger&quot; than the collection you&#39;re quantifying over.<div class="HOEnZb">
<div class="h5"><br>
<br>
-- <br>
Live well,<br>
~wren<br>
<br>
______________________________<u></u>_________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br>