[Haskell-cafe] Polymorphic (typeclass) values in a list?

TJ tjay.dreaming at gmail.com
Mon Oct 22 00:56:16 EDT 2007


On 10/22/07, Tim Docker <timd at macquarie.com.au> wrote:
> TJ:
>
> > 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.
>
> Tim
>

Ah... indeed it can, in this case. It won't work if class Renderable
also has a method for saving to file, etc, I suppose, unless scene ::
[(RasterImage,IO (),...whatever other operations...)]

Thanks for the heads up :)

TJ


More information about the Haskell-Cafe mailing list