Primitive types and Prelude shenanigans
Wed, 21 Feb 2001 12:55:37 +1100
On 20-Feb-2001, Simon Peyton-Jones <email@example.com> wrote:
> I don't mind doing this, but can someone first give a brief justification
> about why it's a good idea, independent of the discussion that
> has taken place on this list? I'd like to add such an explanation
> to the code.
How about "Because the Haskell 98 Report says so"? ;-)
It's a pity there's no Haskell 98 Rationale, like the Ada 95
Rationale... if there was, then the documentation in the ghc code
could just point at it.
There is however one issue with this change that concerns me.
I'm wondering about what happens with the most negative Int.
E.g. assuming 32-bit Int (as in Hugs and ghc), what happens with
the following code?
minint :: Int
minint = -2147483648
I think the rules in the Haskell report mean that you need to write
that example as e.g.
minint :: Int
minint = -2147483647 - 1
ghc currently allows the original version, since it treats negative
literals directly, rather than in the manner specified in the Haskell report.
ghc also allows `(negate (fromInteger 2147483648)) :: Int', apparently
because ghc's `fromInteger' for Int just extracts the bottom bits (?),
so changing ghc to respect the Haskell report's treatment of negative
literals won't affect this code.
But the code does not work in Hugs, because Hugs follows the Haskell
report's treatment of negative literals, and the `fromInteger' in Hugs
does bounds checking -- Hugs throws an exception from `fromInteger'.
The documentation in the Haskell report does not say what
`fromInteger' should do for `Int', but the Hugs behaviour definitely
seems preferable, IMHO. However, this leads to the unfortunate
complication described above when writing a literal for the most
Of course using `minBound' is a much nicer way of finding out the
minumum integer, at least in hand-written code. But this issue might
be a potential pitfall for programs that automatically generate
Fergus Henderson <firstname.lastname@example.org> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.