> Evaluating sum [1..100000] (compiled with hbc)
> results in a wrong value.
> Haskell seems to assume Int to be the
> correct type. But Integer is needed.

You can change the default type by using

        default (Integer,Double)

or whatever numeric types you prefer.  Most people
on the Haskell committee preferred Int to be the default: you
can take a big performance hit for using Integer.  If you think
your code is likely to cause overflows, use Integer in place
of Int.
 
> Why doesn't any error-message (like "overflow")
> occur during evaluation?

Haskell only requires that Int is 26 bits wide.  Overflow is not
*required* to be trapped (though an implementation may choose to do
so).  This allows efficient use of the fixed-precision type (overflow
trapping can be costly).  If you're more worried about
overflow/underflow than speed, use Integer.  [The other safe
alternative is to prove that values in your program will always lie
within the representable range of Ints].

Kevin


Reply via email to