readFloat

Wolfgang Jeltsch wolfgang@jeltsch.net
29 May 2002 23:10:44 +0200


On Tuesday, 2002-05-28, 18:57, CEST Simon Peyton-Jones wrote:
> Folks
> 
> I'm back to tidying up the Haskell Report.
> 
> In the Numeric library, there is the useful function
> 
> 	readFloat :: RealFloat a => ReadS a
> 
> But you can't use it for reading rationals, because Rational
> isn't in RealFloat!
> 
> This is a Royal Pain, and entirely unnecessary. In fact,
> readFloat uses only operations from the RealFrac class,
> so it could equally well have type
> 
> 	readFloat :: RealFrac a => ReadS a
> 
> I'm strongly inclined to make this change. It breaks no
> programs, and it fixes a real bug i.e. there is no way to
> read a "103" as a Rational.
> 
> Simon

It would be strange to name a function readFloat if its type is
    RealFrac a => ReadS a.
I think the function should be named readFrac. For compatibility, one
could put the following into the prelude:
    readFloat :: RealFloat a => ReadS a
    readFloat = readFrac
And one could mark readFloat as depricated and maybe remove it in some
future version of Haskell.

Ciao, Wolfgang