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
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
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 |
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
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
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
Данило Глинський 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
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,