[Haskell-cafe] Data structure containing elements which are instances of the same type class

Daniel Trstenjak daniel.trstenjak at gmail.com
Sun Aug 12 10:34:43 CEST 2012

Hi Oleg,

On Sat, Aug 11, 2012 at 08:14:47AM -0000, oleg at okmij.org wrote:
> I'd like to point out that the only operation we can do on the first
> argument of MkFoo is to show to it. This is all we can ever do:
> we have no idea of its type but we know we can show it and get a
> String. Why not to apply show to start with (it won't be evaluated
> until required anyway)?

It's only a test case. The real thing is for a game and will be
something like:

class EntityT e where
   update      :: e -> e

   render      :: e -> IO ()

   handleEvent :: e -> Event -> e

   getBound    :: e -> Maybe Bound

data Entity = forall e. (EntityT e) => Entity e

data Level = Level {
   entities = [Entity],


More information about the Haskell-Cafe mailing list