
From: Yves Parès
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.