Hello!
I have a class Drawable, and some datatypes which are instances of it, and I
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
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 $
Or like this, with the benefit of using lists.
data DrawableObj a = forall a.Drawable a = DrawableObj a
a , b = DrawableObj a : b
drawMany (a,b,c,[])
2010/2/28 Miguel Mitrofanov miguelim...@yandex.ru:
Sorry, no luck with that.
But you can, probably, define some customized comma:
data
jkff wrote:
Or like this, with the benefit of using lists.
data DrawableObj a = forall a.Drawable a = DrawableObj a
a , b = DrawableObj a : b
drawMany (a,b,c,[])
I like this solution, but it's a pity I think that Haskell doesn't provide a
way to use types like [forall a. (Drawable a) =
You can actually write that type with impredicative polymorphism, but it
doesn't do what you seem to want: it makes a list of polymorphic values
(i.e., universally quantified ones, not existentially).
But that's going away soon, anyway...
On Sun, Feb 28, 2010 at 1:49 PM, Yves Parès
drawMany is just sequence dressed up a bit:
I assume you have this class:
class Drawable a where
draw :: Drawable a = a - Window - IO ()
So, the key is to remember that functions and IO actions are first-class values!
data Box = ...
instance Drawable Box where ...
box :: Box
box = ...
On Sun, Feb 28, 2010 at 6:31 AM, Yves Parès limestr...@gmail.com wrote:
Hello!
I have a class Drawable, and some datatypes which are instances of it, and
I
would like to be able to draw them all at once!
drawMany window [image, text, otherImage]
I think the type of the function drawMany