[Haskell-cafe] Why is toRational a method of Real?

ok at cs.otago.ac.nz ok at cs.otago.ac.nz
Wed Aug 4 22:11:08 EDT 2010

> Why is toRational a method of Real? I thought that real numbers need not
> be rational, such as the square root of two. Wouldn't it make more sense
> to have some sort of Rational typeclass with this method?

I think everyone has problems with the Haskell numeric typeclasses.
The answer in this case is that
  - toRational DOES make sense for every instance of Real in the
    Haskell98 Report and Libraries, because that basically means
    floating point numbers, and floating point numbers are rationals
    (if you allow 1/0, -1/0, and 0/0 you've covered infinities and NaNs)
  - the designers don't seem to have included any layers that weren't
    needed for the tasks immediately at hand, after all, Haskell was
    supposed to avoid success, and the language went through several
    revisions quite quickly.
  - but then the wind changed and her face WAS frozen like that...

shows what _can_ be done in Haskell.  Making it possible to work
with alternatives to parts of the standard Prelude was a very
far-sighted design decision.

More information about the Haskell-Cafe mailing list