[Haskell-cafe] Defaulting to Rational [was: Number overflow]

Donald Bruce Stewart dons at cse.unsw.edu.au
Wed Jul 11 18:23:40 EDT 2007


lennart:
> 
>    Yes, I think we want Integer to be the type that is used
>    unless you ask for something else.
>    It adheres to the principle of getting it right before
>    optimizing.

On a similar note, there's been a long discussion in #haskell about the
problems of defaulting to floating point, and should Rational, or
something similar be used instead, given that Doubles and Float are
broken for a lot of basic things (like Eq and Ord), much as we default
to Integer already.

The issues raised regarding Rational was that you can unexpectedly
build up large precision, and performance in general, of course.
It was unknown whether there were suitable replacement types.
Rational also can't be used with Floating functionsl, like sqrt, which
would bring back Double defaulting.

But shouldn't this really work in Haskell, and if you want imprecision
you must ask for Double explicitly:

    Prelude> 1.1 + 2.2 - 3.3
    4.440892098500626e-16

    Prelude> 1.1 + 2.2 - 3.3 :: Rational
    0%1

-- Don


More information about the Haskell-Cafe mailing list