Behavior of fromInteger on out-of-range arguments
What about having Int be considered a restricted integer that notices overflow, and create another type (bit bunch?) that does not notice overflow, and require explicit conversion to go from one to the other? This would seem to be the best of both worlds. The "bit bunch" type could also provide useful info about its size. It could even be possible to have a "machine-specific bit-bunch" of the same size as an Int or bit bunch, but with machine-specified overflow behavior that the programmer can discover (whether this should be at compile-time or run-time I couldn't say). Question: Is there any standard way in Haskell of determining the maximal and minimal Int values? If not, there should. David Feuer
David Feuer writes: : | Question: Is there any standard way in Haskell of determining the | maximal and minimal Int values? Yes, instance Bounded Int, which means you can use maxBound :: Int and minBound :: Int
On Tuesday, February 26, 2002, 15:36:18 EST, David Feuer wrote:
[...] Question: Is there any standard way in Haskell of determining the maximal and minimal Int values?
There is one. Use maxBound :: Int and minBound :: Int.
[...]
By the way, the report says: "Class Enum defines operations on sequentially ordered types." I think the "sequentially" means that multiple applications of succ to a value shall not result in the same value. That's why I think that succ (maxBound :: Int) should be an error and not minBound :: Int. Because i + 1 should be equal to succ i for every Int value i, (maxBound :: Int) + 1 should also be an error and so should every arithmetic operation that overflows or underflows. Wolfgang
participants (3)
-
David Feuer -
Tom Pledger -
Wolfgang Jeltsch