[Haskell-cafe] Haskell report minutiae
wren ng thornton
wren at freegeek.org
Thu Mar 17 19:15:35 CET 2011
So I have a rules-lawyering question about how specified the overflow
behavior is for the types Int and Word.
* In the Haskell 2010 report it seems to be specified that (sections
18.1, 23.1): "All arithmetic is performed modulo 2^n, where n is the
number of bits in the type." And this seems to apply to Int and Word as
well as Int8, Word8, Int16, Word16, Int32, Word32, Int64, Word64.
* However, in the Haskell 98 report ---and this verbiage is retained in
the same section of H2010--- there is no such guarantee (section 6.4):
"The results of exceptional conditions (such as overflow or underflow)
on the fixed-precision numeric types are undefined; an implementation
may choose error (_|_, semantically), a truncated value, or a special
value such as infinity, indefinite, etc."
* However, the FFI addendum to H98 does specify modulo behavior for the
Int8, Word8, Int16, Word16, Int32, Word32, Int64, Word64 types (section
5.3): "There is, however, the additional constraint that all arithmetic
on the fixed-sized types is performed modulo 2^n." But it is unclear
whether this also applies to Int and Word.
So when it comes to interpreting the report(s) and ensuring proper
implementation, which is it? Are Int and Word arithmetic modular, or
not? Did the specification change between H98 and H98+FFI or between
H98+FFI and H2010?
More information about the Haskell-Cafe