<div dir="ltr">From what I understand (not much), It seems that type-classes are more-or-less equivalent to OO interfaces (I think OP mentioned this), and that containers with existential types are less more-or-less equivalent to OO containers whose elements implement an interface, the biggest exception being that you can't use anything that isn't a part of the class on the contained values.<br>
<br>As I understand, something like this could be relevant:<br><br>> class AquaticLifeform a where<br>> nutrition :: Int<br>> reproduce :: Maybe (a, a)<br><br><div class="gmail_quote">On Thu, Aug 26, 2010 at 10:08 AM, Stephen Tetley <span dir="ltr"><<a href="mailto:stephen.tetley@gmail.com">stephen.tetley@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Drew<br>
<br>
Bear in mind though that existentials are not equivalent to subtyping in OO.<br>
<br>
For instance, with example 2.1 from [1] all you can do with an Obj is<br>
show it, so for the list xs all you can do is show the elements:<br>
<br>
data Obj = forall a. (Show a) => Obj a<br>
<br>
xs :: [Obj]<br>
xs = [Obj 1, Obj "foo", Obj 'c']<br>
<br>
Because Obj is an existential you can't do an case analysis on it - so<br>
you can't write a function like this:<br>
<br>
add_one_if_int (Obj (n::Int)) = Obj (n+1)<br>
add_one_if_int (Obj other) = Obj other<br>
<br>
There really is nothing you can do with Obj other than show it.<br>
<br>
<br>
If you are trying to transliterate OO designs, you might quickly find<br>
existentials are too inert to be useful.<br>
<br>
Best wishes<br>
<br>
Stephen<br>
<br>
[1] <a href="http://www.haskell.org/haskellwiki/Existential_type" target="_blank">http://www.haskell.org/haskellwiki/Existential_type</a><br>
<div class="im"><br>
<br>
On 26 August 2010 07:45, Drew Haven <<a href="mailto:drew.haven@gmail.com">drew.haven@gmail.com</a>> wrote:<br>
> I think I found the answers to all my questions at<br>
> <a href="http://www.haskell.org/haskellwiki/Existential_type" target="_blank">http://www.haskell.org/haskellwiki/Existential_type</a><br>
</div><div><div></div><div class="h5">_______________________________________________<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>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr"><div> Alex R</div></div><br>
</div>