[Haskell-cafe] ANN: convertible (first release)

wren ng thornton wren at freegeek.org
Tue Jan 27 21:41:30 EST 2009

John Goerzen wrote:
> Hi folks,
> I have uploaded a new package to Haskell: convertible.  At its heart,
> it's a very simple typeclass that's designed to enable a reasonable
> default conversion between two different types without having to
> remember a bunch of functions.

I once again point out that realToFrac is *wrong* for converting from 
Float or Double.

     > realToFrac (1/0::Float) ::Double
     > realToFrac (0/0::Float) ::Double

     > realToFrac (0/0::Double) ::Float

     > realToFrac (1/0::Float) ::Rational
     > realToFrac (0/0::Float) ::Rational

     > realToFrac (1/0::Double) ::Rational
     > realToFrac (0/0::Double) ::Rational

These exceptional values are not uncommon and should be dealt with 
correctly. The code to do this is already written in 
logfloat:Data.Number.Transfinite[1], simply use the realToFrac method of 
the RealToFrac class instead of the Prelude's version which is broken.

Since there is no total conversion from Float/Double to Rational, you 
can use the isInfinite and isNaN members of the Transfinite class to 
capture exceptional values as errors.

[1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/logfloat

Live well,

More information about the Haskell-Cafe mailing list