On 06/04/11 20:32, Brandon Moore wrote:
From: Yves Parès<[email protected]>
Sent: Wed, April 6, 2011 1:57:51 PM

Hello Café,

I'm trying to get some modular data types.
The idea that came to me is that I could stack them, for instance :

data Character a = Character { life :: Int,
                               charaInner :: a }

data Gun a = Gun { firepower :: Int,
                   gunInner :: a }

data Armor a = Armor { resistance :: Int,
                       armorInner :: a }

Then a character with a gun and an armor can be build this way:

chara = Character 100 $ Armor 40 $ Gun 12

The idea now is to be able to get some part of the character:
I don't have a better design to suggest, but I think this may end up more
complicated than you want. In particular, it will probably be complicated to
make a collection of characters that have e.g. an Armor but maybe any
other stuff.

If you do want to use this sort of design, check out Wouter Swiestra's
paper "Data Type a la Cart".

Brandon.


_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe
I was struggling with this idea a few weeks ago. I think I tried the same types of extensions that you have, also with no luck.

I then started looking at extensible records on the Haskell wiki
http://www.haskell.org/haskellwiki/Extensible_record

This was the one I liked, but as far as I could tell it has not been implemented (please tell me if I was wrong about that)
http://research.microsoft.com/en-us/um/people/simonpj/Haskell/records.html

RS

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to