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

Johan Holmquist holmisen at gmail.com
Mon Aug 13 19:38:24 CEST 2012


That pattern looks so familiar. :) Existential types seem to fit in to the
type system really well so I never got why it is not part of the standard.
On Aug 12, 2012 10:36 AM, "Daniel Trstenjak" <daniel.trstenjak at gmail.com>
wrote:

>
> 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],
>    ...
>    }
>
>
> Greetings,
> Daniel
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120813/316f881b/attachment.htm>


More information about the Haskell-Cafe mailing list