Read (Ratio a) should also parse a decimal point literal

Dannyu NDos ndospark320 at gmail.com
Thu Feb 6 03:44:11 UTC 2020


Given a string representing a decimal point literal (ex. "0.25"), the
number it represents is guaranteed to be rational. It seems appropriate for
Ratio to parse such strings.

readDecimalRatio :: (Integral a, Read a) => ReadPrec (Ratio a)
readDecimalRatio = parens $ do
Number x <- lexP
return (numberToRational x)

Combine this by (+++) with the original `readPrec` from the instance Read
Ratio.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20200206/c7d6414e/attachment.html>


More information about the Libraries mailing list