[Haskell-cafe] Polymorphic (typeclass) values in a list?
timd at macquarie.com.au
Sun Oct 21 19:39:01 EDT 2007
> After all, sometimes all you need to know about a list is that
> all the elements support a common set of operations. If I'm
> implementing a 3d renderer for example, I'd like to have
> class Renderable a where
> render :: a -> RasterImage
> scene :: Renderable a => [a]
Everyone has launched into explanations of how to use existentials
to do this, but you may be happy in just haskell 98. In the above,
you could just have:
scene :: [RasterImage]
Laziness will ensure that the computation/storage of the images
will not occur until they are used.
More information about the Haskell-Cafe