There is a hidden cost to trapping Int overflow, beyond the extra
instruction per operation mentioned by Paul Hudak. This is that
operations on Ints become unsafe i.e. may raise exceptions (well
that was the whole idea...). This is a problem both for a global
instruction scheduler (e.g. a trace scheduler) and for other
optimizations based on speculative execution. For instance, there
is an optimization for lazy functional languages called cheap
eagerness where cheap and safe expressions are evaluated before
they are known to be needed, which is often faster than building
a thunk for thenm. This is not possible if the expression can
raise an exception, as that would change the semantcs of the program
from successful termination to termination with a run-time error.
Hence the effectiveness of the cheap eagerness transformation is reduced.
/ Cheers,
Karl-Filip