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

John Meacham john at repetae.net
Wed Aug 4 20:58:21 EDT 2010

On Wed, Aug 04, 2010 at 02:30:10PM -0400, Omari Norman wrote:
> 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? Thanks.

The numeric classes are sort of messed up when it comes to non integral
values.  (not that they are perfect for other things) for instance,
realToFrac doesn't preserve NaN or Infinity, except on ghc when
optimization is turned on. and the rounding functions discard
information too by trying to convert a floating point value to an
integral one... 

I was probably going to introduce a 'FloatMax' type in jhc that is
guarenteed to be able to represent all values representable by native
floating point types, then replace the use of Rational as an
intermediate type with it.. not that that helps things right now really.


John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/

More information about the Haskell-Cafe mailing list