[Haskell-cafe] [C][enums][newbie] What is natural Haskell representation of such enum?
David Barbour
dmbarbour at gmail.com
Sun Jan 22 23:01:16 CET 2012
Performing bit-mask operations is possible via the Data.Bits operations (on
elements of type Word8 or Word16, etc.). But I must say, it doesn't seem
very `natural` in Haskell, nor even in other languages. It crosses lines,
binding abstraction to representation in order to improve efficiency.
The natural way in Haskell to model model `CREATURE_OR_GAMEOBJECT` would
simply be as a function (e.g. of type Object -> Bool, or ObjectType ->
Bool).
Regards,
Dave
2012/1/22 Данило Глинський <abcz2.uprola at gmail.com>
> What is natural Haskell representation of such enum?
>
> enum TypeMask
> {
> UNIT,
> GAMEOBJECT,
>
> CREATURE_OR_GAMEOBJECT = UNIT | GAMEOBJECT
> };
>
> More sophisticated question is: and what data structures must be used when
> converting this naturally one to Haskell?
>
> // 1-byte flaged enum
> enum TypeMask
> {
> // ...
> UNIT = 0x0004,
> GAMEOBJECT = 0x0008,
> // ...
>
> CREATURE_OR_GAMEOBJECT = UNIT | GAMEOBJECT
> WORLDOBJECT = UNIT | PLAYER | GAMEOBJECT | DYNAMICOBJECT | CORPSE
> // ... even more enum combos ...
> };
>
> _______________________________________________
> 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/20120122/02c6735f/attachment.htm>
More information about the Haskell-Cafe
mailing list