Thanks for explanation Sean!<br><br><div class="gmail_quote">On Tue, Sep 15, 2009 at 4:30 PM, Sean Leather <span dir="ltr">&lt;<a href="mailto:leather@cs.uu.nl">leather@cs.uu.nl</a>&gt;</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;">
<div class="gmail_quote"><div class="im"><div> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">&quot;Existential types&quot; sounds a bit scary :)<div>


<div></div><div><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="gmail_quote"><div></div></div>

</blockquote></div></div></div></blockquote></div><div><br>It&#39;s unfortunate that they&#39;ve developed a scariness feeling associated with them. They can be used in strange ways, but simple uses are quite approachable. One way to think of them is like implementing an object-oriented interface. You know it&#39;s an object, but you can&#39;t do anything with it except use the methods of the interface.<br>


<br>---<br><br>{-# LANGUAGE ExistentialQuantification #-}<br><br>data Square = Square ...<div class="im"><br>data Circle = Circle ...<br><br>class Perimeter a where perimeter :: a -&gt; Double<br></div>instance Perimeter Square where perimeter (Square ...) = ... <br>
<div class="im">

instance Perimeter Circle where perimeter (Circle ...) = ...<br><br></div>-- The &#39;a&#39; is hidden here. The interface is defined by the class constraint.<br>data Perimeterizable = forall a . (Perimeter a) =&gt; P a <br>
<br>

-- This is the accessor method for things Perimeterizable.<br>getPerimeter (P x) = perimeter x<br><br>vals :: [Perimeterizable]<br>vals = [P Square, P Circle]<br><br>perims = map getPerimeter vals<br><br>---<br><br>Regards,<br>


Sean<br></div></div>
</blockquote></div><br>