<p dir="ltr">That choice has already been made, with a different conclusion, in the Haskell numeric syntax. In Haskell syntax, decimal syntax is interpreted via fromRational *already*. In source, I can write 3.796::Rational and get a good result, without any conversion from Double anywhere--it just puts 3796/1000 into lowest terms as it should. I see no particular reason to do otherwise here. In either case, we need to read digits, building an integer, until we get to a non-digit. Only what happens next depends on the notation. Either notation should work for any Fractional type, as it does in Haskell syntax.</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Aug 15, 2016 11:09 AM, "Michael Orlitzky" <<a href="mailto:michael@orlitzky.com">michael@orlitzky.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 08/15/2016 09:04 AM, Benno Fünfstück wrote:<br>
><br>
> Well, you are showing 1/3 as a Float and reading it as a Double, which<br>
> of course won't work since the String represents a Float and not a<br>
> Double. The following does work:<br>
><br>
<br>
Sorry, unclear example. We have a choice to make for how to read in<br>
decimal strings that could also represent Floats or Doubles. I'm worried<br>
about the resulting confusion from whatever choice we make.<br>
<br>
Read/Show are supposed to be machine-readable, and representing a<br>
Rational as a decimal (the same way a Float is represented) gives away<br>
some type-safety. This is the same argument I would make against having<br>
(read "1.0" :: Integer) return 1.<br>
<br>
Suppose that this is what the rational read instance would do...<br>
<br>
  ghci> let ratread :: String -> Rational;<br>
        ratread s = realToFrac (read s :: Double) :: Rational<br>
<br>
We're compatible with the Fractional/Show instance for Float/Double:<br>
<br>
  ghci> fromRational $ ratread (show (0.33333334 :: Float)) :: Float<br>
  0.33333334<br>
  ghci> fromRational $ ratread (show (0.33333334 :: Double)) :: Double<br>
  0.33333334<br>
<br>
But obviously things will go wrong for rationals themselves, when they<br>
don't fit into a Double. The other choice we could make is to take<br>
"0.33333334", multiply it by ten-to-the-whatever, and then make that the<br>
denominator (over ten-to-the-whatever). That's probably a better choice,<br>
but then you have other inconsistencies...<br>
<br>
  ghci> 0.33333334 :: Rational<br>
  16666667 % 50000000<br>
  ghci> toRational (0.33333334 :: Float)<br>
  11184811 % 33554432<br>
<br>
Namely, that that's not how the Float itself is converted into a<br>
Rational. Basically, beware of confusing the hell out of everyone in<br>
order to avoid an explicit type conversion.<br>
<br>
______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/haskell-<wbr>cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div></div>