[Haskell-cafe] Proposal: Rational read
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
> 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)
> ghci> read (show (1/3 :: Float)) == (1/3)
> 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)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe