Re: [Haskell-cafe] [C][enums][newbie] What is natural Haskell representation of such enum?

2012-01-23 Thread Malcolm Wallace
2012/1/22 Данило Глинський abcz2.upr...@gmail.com What is natural Haskell representation of such enum? enum TypeMask { UNIT, GAMEOBJECT, CREATURE_OR_GAMEOBJECT = UNIT | GAMEOBJECT }; I don't think that definition makes any sense in C, because UNIT is 0, so UNIT | GAMEOBJECT

Re: [Haskell-cafe] [C][enums][newbie] What is natural Haskell representation of such enum?

2012-01-23 Thread Daniel Hlynskyi
Thanks. This and previous email are answers to question I asked. But not the answer to question I mean. I'll describe the whole task, as Yves Parès suggested. I'm trying to convert C++ code to Haskell. I have such hierarchy: class Object, class Item : Object, class Container : Item. Another one

Re: [Haskell-cafe] [C][enums][newbie] What is natural Haskell representation of such enum?

2012-01-23 Thread David Barbour
If you want a simple translation, use Word8 (from Data.Word) for the type and use Data.Bits for operations on it just like in C++. This would offer you storage efficiency (if stored as a strict field). If you want idiomatic Haskell, constructor of the form: data ObjectType = Object | Item |

Re: [Haskell-cafe] [C][enums][newbie] What is natural Haskell representation of such enum?

2012-01-23 Thread Mike Burns
On 2012-01-23 13.45.50 -0800, David Barbour wrote: If your classes are more like `interfaces`, you could use Typeclasses to model them. Otherwise, look into OOHaskell. But I think your program architecture will simply be different in idiomatic Haskell than in idiomatic C++. If your OO is very

[Haskell-cafe] [C][enums][newbie] What is natural Haskell representation of such enum?

2012-01-22 Thread Данило Глинський
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

Re: [Haskell-cafe] [C][enums][newbie] What is natural Haskell representation of such enum?

2012-01-22 Thread David Barbour
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

Re: [Haskell-cafe] [C][enums][newbie] What is natural Haskell representation of such enum?

2012-01-22 Thread Erik de Castro Lopo
Данило Глинський wrote: What is natural Haskell representation of such enum? enum TypeMask { UNIT, GAMEOBJECT, CREATURE_OR_GAMEOBJECT = UNIT | GAMEOBJECT }; data ObjectType = Unit | GameObject creatureOrGameObject :: ObjectType - Bool creatureOrGameObject Unit = True

Re: [Haskell-cafe] [C][enums][newbie] What is natural Haskell representation of such enum?

2012-01-22 Thread Yves Parès
I may be curious to see how you intend to use such enum... It is very C-wise, I'm not sure it will be very handy, but I need some context. 2012/1/22 Данило Глинський abcz2.upr...@gmail.com What is natural Haskell representation of such enum? enum TypeMask { UNIT, GAMEOBJECT,