<div dir="ltr">I can never seem to remember to reply-all ...<div><br></div><div><div class="gmail_extra"><div class="gmail_quote">On Wed, Mar 8, 2017 at 3:24 PM, Mike Ledger <span dir="ltr"><<a href="mailto:eleventynine@gmail.com" target="_blank">eleventynine@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">There is also the exact-real and numbers packages which provide exact reals with their respective CReal types.</div><div class="gmail-HOEnZb"><div class="gmail-h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 8, 2017 at 6:22 AM, Olaf Klinke <span dir="ltr"><<a href="mailto:olf@aatal-apotheke.de" target="_blank">olf@aatal-apotheke.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Before asking on this list, I wrote my own version which did just what David suggested: Parse the integer before the decimal point, parse the part behind the decimal point and divide the latter by 10^length, then sum both parts. This function has type<br>
<br>
Fractional t => String -> t<br>
<br>
I thought that this was maybe very inefficient and therefore looked for prior art. If someone feels it is worth adding to some package, I'm happy to provide the code.<br>
<span class="gmail-m_-4361018338835900648HOEnZb"><font color="#888888"><br>
Olaf<br>
</font></span><div class="gmail-m_-4361018338835900648HOEnZb"><div class="gmail-m_-4361018338835900648h5"><br>
<br>
> Am 06.03.2017 um 21:46 schrieb David Feuer <<a href="mailto:david.feuer@gmail.com" target="_blank">david.feuer@gmail.com</a>>:<br>
><br>
> I think your best bet is probably to get your hands dirty and parse it yourself: first grab an integer, then optionally a decimal point, etc.<br>
><br>
> On Mar 6, 2017 3:43 PM, "Olaf Klinke" <<a href="mailto:olf@aatal-apotheke.de" target="_blank">olf@aatal-apotheke.de</a>> wrote:<br>
> Ah, thanks! That is something to build on.<br>
><br>
> Olaf<br>
> > Am 24.02.2017 um 15:35 schrieb Patrick Chilton <<a href="mailto:chpatrick@gmail.com" target="_blank">chpatrick@gmail.com</a>>:<br>
> ><br>
> > Prelude> import Numeric<br>
> > Prelude Numeric> fst $ head $ readFloat "0.1234" :: Rational<br>
> > 617 % 5000<br>
> ><br>
> > On Fri, Feb 24, 2017 at 1:17 PM, Olaf Klinke <<a href="mailto:olf@aatal-apotheke.de" target="_blank">olf@aatal-apotheke.de</a>> wrote:<br>
> > Dear cafe,<br>
> ><br>
> > when processing text files containing numbers of the form "xxxx.yyyy" I used to parse them into Double using that type's Read instance. Obviously, even with arithmetic no more complicated than the field operations the result might have ugly rounding errors like 12.000000000002 due to the fact that numbers like 0.7 are not dyadic rationals. The math in my program is not complicated and the numbers are not large, so I don't care about Rationals having potentially huge memory footprints.<br>
> ><br>
> > So here's my question. A literal like 0.7 has type Fractional a => a, but the Read instance of Rational rejects the string "0.7". Must it be this way? Do I have to go via toRational.(read :: String -> Data.Scientific.Scientific)?<br>
> ><br>
> > Note that the documentation of Data.Scientific explicitly states that using (/) is unsafe, so I'd rather stay with the field Rational.<br>
> ><br>
> > For the output as decimal expansion, there is of course long division as described here [1], but I wonder whether either this exists in some library or there is even a more efficient solution.<br>
> ><br>
> > Any pointers are appreciated.<br>
> > Thanks,<br>
> > Olaf<br>
> ><br>
> > [1] <a href="http://stackoverflow.com/questions/30931369/how-to-convert-a-rational-into-a-pretty-string" rel="noreferrer" target="_blank">http://stackoverflow.com/quest<wbr>ions/30931369/how-to-convert-<wbr>a-rational-into-a-pretty-<wbr>string</a><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-bi<wbr>n/mailman/listinfo/haskell-caf<wbr>e</a><br>
> > Only members subscribed via the mailman list are allowed to post.<br>
> ><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-bi<wbr>n/mailman/listinfo/haskell-caf<wbr>e</a><br>
> Only members subscribed via the mailman list are allowed to post.<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-bi<wbr>n/mailman/listinfo/haskell-caf<wbr>e</a><br>
Only members subscribed via the mailman list are allowed to post.</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>