Straightforward conversion from Int <-> Word
Simon Marlow
simonmar@microsoft.com
Wed, 27 Feb 2002 10:24:42 -0000
> Simon Marlow notes:
> > But fromIntegral *does* do the right thing, doesn't it?
> >=20
> > > Numeric.showHex (fromIntegral (-1 :: Int32) :: Word32) ""
> > "0xffffffff"
>=20
> Interesting. The fact that this fooled Julian as well as me suggests
> the behavior needs to be better documented. Interestingly,=20
> hugs yields
> an error. I'm going to follow up in more detail to haskell, as this
> is really about the behavior of "fromInteger", and has nothing to do
> with Word32 or Int32 per se at all.
There's this paragraph which talks about the behaviour of fromIntegral =
in GHC:
http://www.haskell.org/ghc/docs/latest/set/vs-haskell-defn.html#HASKELL98=
-UNDEFINED
but it suggests that this only happens for Int. I'll expand it to cover =
the sized integral types.
Cheers,
Simon