Parsing Ratio with zero denominator
Henning Thielemann
lemming at henning-thielemann.de
Sun May 31 18:17:32 UTC 2020
On Sun, 31 May 2020, Dannyu NDos wrote:
> I mean, shouldn't there be a guard?
>
> instance (Integral a, Read a) => ReadPrec (Ratio a) where
> readPrec = parens . prec 7 $ do
> n <- step readPrec
> lift (expect (Symbol "%"))
> d <- step readPrec
> guard (0 /= d)
> return (n % d)
I think you are right. A readPrec parser should only generate parser
errors and should be total. I do not know if anyone relies on the current
behavior. I suspect that most users are not aware of the problem and their
programs will be aborted in case of zero denominator where they shouldn't.
More information about the Libraries
mailing list