Parsing Ratio with zero denominator
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) 2020년 5월 31일 (일) 오후 12:13, Dannyu NDos <ndospark320@gmail.com>님이 작성:
Shouldn't the parser be pfail rather than throwing an error?
Am So., 31. Mai 2020 um 10:06 Uhr schrieb Dannyu NDos <ndospark320@gmail.com
:
I mean, shouldn't there be a guard? [...]
In general, I'm heavily opposed against any change which can introduce subtle changes in the semantics without any warning/compilation error. Consider e.g. length (readsPrec 1 "2 % 0" :: [(Rational, String)]). Currently, this returns 1, which will silently turn into 0 with your proposed change, at least if I see this correctly. Therefore: -100 for this proposal. :-}
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.
Yes, I think you're right. On Sat, May 30, 2020, 11:13 PM Dannyu NDos <ndospark320@gmail.com> wrote:
Shouldn't the parser be pfail rather than throwing an error? _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
participants (4)
-
Dannyu NDos -
David Feuer -
Henning Thielemann -
Sven Panne