"Sigbjorn Finne (Intl Vendor)" wrote:
>
> Hi,
>
> there's difference in behaviour of how Integers are coerced Ints
> between Hugs(98) and ghc.
>
> Prelude> (0x80000000 :: Int)
>
> Program error: {primIntegerToInt 2147483648}
>
> Prelude> (maxBound::Int) + 1
> -2147483648
> Prelude>
>
> ghc's conversion of Integers is modulo maxInt, i.e.,
>
> (maxBound :: Int) + 1 == (0x80000000::Int)
>
> is True.
>
> That's consistent & handy, but whatever the behaviour used, it'd be
> oh-so convenient if the two implementations agreed.
I think the current behavior of Hugs is reasonable.
The question is what should 0x80000000 :: Integer
become when its coerced into an int.
GHC takes the lowest 32 bits.
Advantage: Equality above maxBound still "works" aka above.
Disadvantage: 0xffffffff + 1 == 0 !
Perhaps constant Int's larger than maxBound (or smaller
than minBound) should be a compile time error?
Lets at least agree on the toInt definition.
Andy Gill