<div dir="ltr"><div><div>Just expanding on Brandon's answer: DeMorgan's law he's referring to goes like this:<br></div>∀a.P(a) === ¬∃a.¬P(a) where 'a' is a sentence, so P is second order<br></div>A special case of this is this:<br>
∀a.(R(a) -> Q) === ¬∃a.¬(R(a) -> Q) === ¬∃a.(R(a)∧¬Q) === ¬((∃a.R(a))∧¬Q) === (∃a.R(a)) -> Q   (i added extra parantheses for emphasis)<br><div><div>So what does this mean in terms of haskell? R(a) is your data definition's "body", and Q is the type you are defining. On the lhs the universally quantified version gives you the type of the constuctor you're defining, and on the rhs the existential tells you what you're constructing the type with.<br>
Or in other words the universal version says: For any 'a' give me an R(a) and i'll give you back a Q.<br></div><div>The existential version says: If you have some 'a' for which R(a) i'll give you back a Q. (It's hard to phrase the difference without sounding stupid, they are equivalent after all).<br>
</div><div><br></div><div>There are of course other considerations, for example introducing 'exists' would mean another keyword in the syntax.<br></div><div><br></div><div>Having said that I think that the choice of 'forall' for -XExistentialQuantification is wrong, as the data body defines the type you're constructing with, not the type of the whole constructor. HOWEVER for -XGADTs forall makes perfect sense. Compare the following:<br>
<br></div><div>data AnyType = forall a. AnyType a<br></div><div>data AnyType where<br></div><div>  AnyType :: forall a. a -> AnyType<br><br></div><div>These two definitions are operationally identical, but I think the GADT way is the one that actually corresponds to the DeMorgan law.<br>
</div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 2 December 2013 22:07, TP <span dir="ltr"><<a href="mailto:paratribulations@free.fr" target="_blank">paratribulations@free.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi everybody,<br>
<br>
<br>
I try to understand existential quantification. I have two questions.<br>
<br>
1/ I have just read the answer of yairchu at<br>
<br>
<a href="http://stackoverflow.com/questions/3071136/what-does-the-forall-keyword-in-haskell-ghc-do" target="_blank">http://stackoverflow.com/questions/3071136/what-does-the-forall-keyword-in-haskell-ghc-do</a><br>
<br>
He writes:<br>
<br>
"""<br>
So with Existential-Quantification, foralls in data definitions mean that,<br>
the value contained *can* be of *any* suitable type, not that it *must* be<br>
of *all* suitable types.<br>
"""<br>
<br>
This made me think to an error I obtained with the code:<br>
---------------<br>
test :: Show s => s<br>
test = "foobar"<br>
---------------<br>
<br>
The error is:<br>
<br>
Could not deduce (s ~ [Char])<br>
from the context (Show s)<br>
bound by the type signature for test :: Show s => s<br>
[...]<br>
`s' is a rigid type variable bound by<br>
the type signature for test :: Show s => s<br>
<br>
Indeed, `test :: Show s => s` means "for any type s which is an instance of<br>
Show, test is a value of that type s". But for example "foobar" can't be an<br>
Int that is an instance of Show, so it yields an error.<br>
By comparison,<br>
<br>
---------------<br>
test :: Num a => a<br>
test = 42<br>
---------------<br>
<br>
works because 42 can be a value of type Int or Integer or Float or anything<br>
else that is an instance of Num.<br>
So I thought that by using existential quantification, the first example<br>
could work:<br>
<br>
---------------<br>
{-# LANGUAGE ExistentialQuantification #-}<br>
<br>
test :: forall s . Show s => s<br>
test = "asd"<br>
---------------<br>
<br>
But I obtain the same error, why?<br>
<br>
2/<br>
Is the notion of existential type related in some way to the classical<br>
mathematical quantifier "∃" (Unicode symbol U+2203: "There exists")?<br>
If yes, then why using "forall" for an "existential type"?<br>
<br>
At the following address<br>
<br>
<a href="http://www.haskell.org/ghc/docs/6.12.1/html/users_guide/data-type-extensions.html#existential" target="_blank">http://www.haskell.org/ghc/docs/6.12.1/html/users_guide/data-type-extensions.html#existential</a><br>

<br>
we read<br>
<br>
"""<br>
7.4.4.1. Why existential?<br>
<br>
 What has this to do with existential quantification? Simply that MkFoo has<br>
the (nearly) isomorphic type<br>
<br>
  MkFoo :: (exists a . (a, a -> Bool)) -> Foo<br>
<br>
But Haskell programmers can safely think of the ordinary universally<br>
quantified type given above, thereby avoiding adding a new existential<br>
quantification construct.<br>
"""<br>
<br>
But I don't understand the explanation.<br>
<br>
Thanks in advance,<br>
<br>
TP<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br></div>