[Haskell-cafe] Let's fight Int, Pt. 2

Johannes Waldmann johannes.waldmann at htwk-leipzig.de
Sun Mar 14 20:49:29 UTC 2021

Dear Cafe,

it's bad to use Int where you really mean Nat,
because this creates extra work  (defensive programming,
or  mental gymnastics to prove that you don't need it)

Another Int anti-feature is arithmetics with silent wrap-around -
with respect to an unspecified modulus,
as highlighted by a recent example:

What are the possibilities for a "checked Int"?
(also, "checked Nat")

A historical precedent is set by Ada
"The exception NUMERIC_ERROR is raised by the execution of an operation
... that cannot deliver the correct result"

Another point in the design space is Rust: "Integer operators
will panic when they overflow when compiled in debug mode."

The Haskell standard
says that
"The results of exceptional conditions (such as overflow or underflow)
on the fixed-precision numeric types are undefined;"
so any program that relies on Int's wrap-around, is already broken.

GHC's base library specifies "modulo 2^width" semantics
for signed (Data.Int) and unsigned (Data.Word) integer types.

Finally, about "fighting" - I guess it's more about strategies
to cope with the present situation.

- J.W.

More information about the Haskell-Cafe mailing list