[Haskell-cafe] Proposal: Rational read

Benno Fünfstück benno.fuenfstueck at gmail.com
Mon Aug 15 13:04:17 UTC 2016


Michael Orlitzky <michael at orlitzky.com> schrieb am Mo., 15. Aug. 2016 um
14:48 Uhr:

> On 08/14/2016 06:54 PM, David Feuer wrote:
> > Since decimal notation is defined in terms of fromRational, it seems a
> > bit strange that the notation doesn't work for read::String->Rational.
> > I'd be in favor of allowing it. I wouldn't expect too severe a
> > performance penalty.
> >
>
> One potential gotcha:
>
>   ghci> read (show (1/3)) == (1/3)
>   True
>   ghci> read (show (1/3 :: Float)) == (1/3)
>   False
>
> When does it work? Is it platform-dependent?
>

Well, you are showing 1/3 as a Float and reading it as a Double, which of
course won't work since the String represents a Float and not a Double. The
following does work:

λ: read (show (1/3 :: Float)) == ((1/3) :: Float)
True
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160815/34de1058/attachment.html>


More information about the Haskell-Cafe mailing list