Sigbjorn:

: > 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? 
: > 
: 
: Int arithmetic is modulo maxBound (at least that's what
: ghc and Hugs implements), so making the Integer->Int conversion
: fall into line with that, has some merit.

On my machine the following program:

> main = do putStr "According to ghc-4.02 (1-maxBound)^2 = "
>           putStr $ show mult1
>           putStr "\nAccording to ghc-4.02 (maxBound-1)^2 = "
>           putStr $ show mult2
>      where mult1, mult2 :: Int
>            mult1 = (1-maxBound)*(1-maxBound)
>            mult2 = (maxBound-1)*(maxBound-1)

outputs:

According to ghc-4.02 (1-maxBound)^2 = 4
According to ghc-4.02 (maxBound-1)^2 = 4

Mod maxBound the result of both multiplication should have been 1.

Maybe it is better to rely on Integers.

Regards,


Marc van Dongen

Reply via email to