[Haskell-cafe] Announce: EnumMap-0.0.1
Ketil Malde
ketil at malde.org
Thu Aug 13 02:34:33 EDT 2009
David Menendez <dave at zednenem.com> writes:
> That depends on what "outside the Enum range" means. You'll get an
> exception if you somehow get an Int key in the map which doesn't
> correspond to any value in the enum, but you don't get an exception if
> you try to pass in, say, a large Integer.
> Prelude> fromEnum (2^32)
> 0
Yes, but:
Prelude Data.Int> fromEnum (2^32 :: Int64)
*** Exception: Enum.fromEnum{Int64}: value (4294967296) is outside of Int's bounds (-2147483648,2147483647)
so apparently, different Enum instances deal with this differently.
>From GHC.Num:
instance Enum Integer where
[...]
fromEnum n = I# (toInt# n)
>From GHC.Int:
instance Enum Int64 where
[...]
fromEnum x@(I64# x#)
| x >= fromIntegral (minBound::Int) && x <= fromIntegral (maxBound::Int)
= I# (int64ToInt# x#)
| otherwise = fromEnumError "Int64" x
-k
--
If I haven't seen further, it is by standing in the footprints of giants
More information about the Haskell-Cafe
mailing list