I think this explanation is positively brilliant. Byorgey++<br><br><div class="gmail_quote">On Fri, Jan 23, 2009 at 9:59 AM, Brent Yorgey <span dir="ltr"><<a href="mailto:byorgey@seas.upenn.edu">byorgey@seas.upenn.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">><br>
> AbstractInterface a = new ConcreteClass();<br>
<br>
In Java, if a variable has type AbstractInterface, it is<br>
*existentially* quantified: it means, this variable references a value<br>
of *some* type, and all you know about it is that it is an instance of<br>
AbstractInterface. Whatever code sets the value of the variable gets<br>
to choose its concrete type; any code that uses the variable cannot<br>
choose what type it should be, but can only use AbstractInterface<br>
methods on it (since that's all that is known).<br>
<br>
However, a Haskell variable with type<br>
<br>
var :: AbstractInterface a => a<br>
<br>
is *universally* quantified: it means, this variable has a polymorphic<br>
value, which can be used as a value of any type which is an instance<br>
of AbstractInterface. Here, it is the code which *uses* var that gets<br>
to choose its type (and indeed, different choices can be made for<br>
different uses); the definition of var cannot choose, and must work<br>
for any type which is an instance of AbstractInterface (hence it must<br>
only use methods of the AbstractInterface type class).<br>
<br>
Writing<br>
<br>
a :: Num n => n<br>
a = 3 :: Integer<br>
<br>
is trying to define a universally quantified value as if it were<br>
existentially quantified.<br>
<br>
Now, it *is* possible to have existentially quantification in Haskell;<br>
I can show you how if you like, but I think I'll stop here for now.<br>
<br>
Does this help?<br>
<br>
-Brent<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</blockquote></div><br>