Dan Piponi wrote:
> There's a bit of work required to make this code good enough for
> general consumption, and I don't know much about Haskell internals.
>> (1) What is the "official" way to find the size of a word? A quick
> look at 6.8.1's base/GHC/Num.lhs reveals that it uses a #defined
> symbol.
I'm not 100% sure what you mean by "word" in this context, but assuming you
mean the same thing as we do in GHC when we say "word" (a pointer-sized
integral type), then one way is
Foreign.sizeOf (undefined :: Int)
or
Foreign.sizeOf (undefined :: Ptr ())
(in GHC these are guaranteed to be the same).
There's also
Data.Bits.bitSize (undefined :: Int)
which might be more appropriate since you're using Data.Bits anyway.
Cheers,
Simon