RE: Behavior of fromInteger on out-of-range arguments
| It'd be lovely if the Haskell report took a stand on the | issue, but I suspect that may be too much to hope for. Actually, it'd be an easy, non-destablising change to make to the Report to specify the behaviour of the Int instance of fromInteger on numbers larger than will fit in an Int. If a consensus emerges I'm quite happy to enshrine it in H98. Simon
It seems to me that the behavior for `(fromInteger x)::Int`, where x is an Integer outside Int range, should be the same (in terms of the Haskell report) as that for `y + y`, where y is an Int such that `toInteger y + toInteger y` is outside Int range. I strongly prefer that that behavior _not_ be provision of any normal Int value. It's been a distinct disappointment for me that Haskell allows such operations to produce a result without any indication that a representation fault occurred. Dean Herington
Dean Herington:
I strongly prefer that that behavior _not_ be provision of any normal Int value.
I agree. I think a operation to let you examine the (possibly) underlying 2s complement representation without raising an exception should be quite separate from the operation to convert between signed and unsigned values possibly raising an exception even though they have the same type. (Note that they'd have different types if Haskell followed Java's example and made exceptions part of the type.) -- Alastair Reid reid@cs.utah.edu http://www.cs.utah.edu/~reid/
participants (3)
-
Alastair David Reid -
Dean Herington -
Simon Peyton-Jones