[Haskell-cafe] Lists of Existential DT
ekirpichov at gmail.com
Sun Feb 28 13:35:00 EST 2010
Or like this, with the benefit of using lists.
data DrawableObj a = forall a.Drawable a => DrawableObj a
a <,> b = DrawableObj a : b
2010/2/28 Miguel Mitrofanov <miguelimo38 at yandex.ru>:
> Sorry, no luck with that.
> But you can, probably, define some "customized comma":
> data DrawPair a b = DrawPair a b
> (<,>) :: a -> b -> DrawPair a b
> (<,>) = DrawPair
> instance (Drawable a, Drawable b) => Drawable (DrawPair a b) where ...
> drawMany :: Drawable a => Window -> a -> IO ()
> drawMany window $ image <,> text <,> otherImage
> On 28 Feb 2010, at 17:31, Yves Parès wrote:
>> I have a class Drawable, and some datatypes which are instances of it, and
>> would like to be able to draw them all at once!
>> drawMany window [image, text, otherImage]
>> I think the type of the function drawMany would be:
>> drawMany :: Window -> [forall a. (Drawable a) => a] -> IO ()
>> However it doesn't work.
>> I know one solution is to make a new datatype (e.g. DrawableObj) which
>> data DrawableObj = forall a (Drawable a) =>
>> DrawableObj a
>> And then declare drawMany as:
>> drawMany :: Window -> [DrawableObj] -> IO ()
>> But to use it I have to wrap up myself every drawable in a DrawableObj:
>> drawMany window [DrawableObj image, DrawableObj text, DrawableObj
>> Is there another more suitable way to handle a list of drawables?
>> Yves Parès
>> Live long and prosper
>> View this message in context:
>> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
Senior Developer, JetBrains
More information about the Haskell-Cafe