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

John Goerzen jgoerzen at complete.org
Tue Jan 27 22:30:07 EST 2009

On Tue, Jan 27, 2009 at 09:41:30PM -0500, wren ng thornton wrote:
> 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
>     3.402823669209385e38

Yes, I understand what you are saying and agree with you.  But there
is nothing better in the standard library, and I did not feel it was
worth adding another dependency to the package simply for the sake of
this sort of thing.  People that need it can get it for themselves and
write their own instance of Convertible if they wish.

I also note that fromIntegral does no bounds checking and produces
garbage in a number of cases.  This, though, is detected in
convertible due to bounds checking there.

> 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.

I wonder if you would consider submitting a patch to base?  It seems
that this is a sore problem there, and ideally should be dealt with
properly in base.

-- John

More information about the Haskell-Cafe mailing list