Andy Gill <[EMAIL PROTECTED]> writes:
>
> "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.
>
If you're saying that non-catchable, run-time exceptions are ok,
I'm not at all sure I agree!
> 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.
--sigbjorn
RE: Integer -> Int conversion
Sigbjorn Finne (Intl Vendor) Wed, 23 Jun 1999 15:46:36 +0200 (MET DST)
- Integer -> Int conversion Sigbjorn Finne (Intl Vendor)
- Re: Integer -> Int conversion Andy Gill
- Re: Integer -> Int conversion Sigbjorn Finne (Intl Vendor)
- Re: Integer -> Int conversion Marc van Dongen
- RE: Integer -> Int conversion Simon Marlow
- Re: Integer -> Int conversion Lennart Augustsson
- Re: Integer -> Int conversion Lennart Augustsson
- RE: Integer -> Int conversion Simon Marlow
