At 14:06 -0700 1999/06/30, Mark P Jones wrote:
>| > > 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!
>
>I guess the real problem here is that the Haskell report doesn't
>say which of these behaviors is correct. The problem here will
>go away when Hugs and GHC use the same runtime system, but that
>doesn't really help, especially for other implementations. So
>perhaps somebody will have to make a choice between the alternatives.
>From the mathematical point of view, let Z denote the mathematical
integers; then there are two interpretations of Int, as a ring R = Z/N, N =
2^n, and as a segment I = [minBound , maxBound] of integers from Z.
Here, we could identify Z = Integer. If we set Int = R, then the natural
type conversion Integer -> Int is the canonical homomorphism Z -> R
(corresponding to taking the remainder attained by division by N). If we
set Int = I, then one should throw an exception when the computations goes
out of bounds.
So it seems that one has not given sufficiently much thought of what
mathematical structure Int should have.
My guess is that Int should behave as R, and then one should use the
canonical homomorphism Z -> R for type conversion. The variation where Int
= I, I think is not of much use in computers, in view of the overhead
keeping track of arithmetic errors create. But it could surely be added as
a special structure.
Hans Aberg
* Email: Hans Aberg <mailto:[EMAIL PROTECTED]>
* Home Page: <http://www.matematik.su.se/~haberg/>
* AMS member listing: <http://www.ams.org/cml/>