<br><br><div class="gmail_quote">On Sun, Feb 28, 2010 at 6:31 AM, Yves Parès <span dir="ltr">&lt;<a href="mailto:limestrael@gmail.com">limestrael@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Hello!<br>
<br>
I have a class Drawable, and some datatypes which are instances of it, and I<br>
would like to be able to draw them all at once!<br>
drawMany window [image, text, otherImage]<br>
<br>
I think the type of the function drawMany would be:<br>
drawMany :: Window -&gt; [forall a. (Drawable a) =&gt; a] -&gt; IO ()<br>
<br>
However it doesn&#39;t work.<br>
I know one solution is to make a new datatype (e.g. DrawableObj) which will<br>
be:<br>
data DrawableObj = forall a (Drawable a) =&gt;<br>
                              DrawableObj a<br>
<br>
And then declare drawMany as:<br>
drawMany :: Window -&gt; [DrawableObj] -&gt; IO ()<br>
<br>
But to use it I have to wrap up myself every drawable in a DrawableObj:<br>
drawMany window [DrawableObj image, DrawableObj text, DrawableObj<br>
otherImage]<br>
<br>
Is there another more suitable way to handle a list of drawables?<br></blockquote><div><br></div><div>Luke Palmer has an article on his blog that proposes a different solution to the problem that I believe you&#39;re trying to solve:</div>
<div><a href="http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/">http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/</a></div><div><br></div><div>You might give his approach a try and see if it&#39;s simpler and easier to work with.</div>
<div><br></div><div>Good luck!<br>Jason</div></div>