-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parser is bad Alternative #122
Comments
Indeed this is true but I'm afraid I don't see any way to fix this which doesn't either compromise performance or significantly complicate the implementation (and perhaps, as a result, also compromise performance). Fixing this would in effect require that we add a variety of "weak failure" result, which |
I want to use Alternative freely with Aeson.Parser, and I have no option in aeson's underlying parsing library. |
One way to fix this is to have an Ord instance for your error type and then always return the "largest" error. Doing so can give you much-needed much better error messages for backtracking parsers. (Basically what you do is order your errors from less specific to more specific, so that you always keep the more specific one.) See https://github.com/vimus/vimus/blob/master/src/Vimus/Command/Parser.us for an implementation. That said, attoparsec parsers are still a monoid under the assumption that we consider all errors equal (similar to what GHC does for exceptions). Sent from mobile
|
@sol, the problem is that you end up carrying around significantly more information through the parser state. The simplest approach I could come up with (implemented here) appears to significantly degrade performance in uses of I don't have time to investigate this further but I suspect this will be a quite difficult issue to fix, if it is possible at all. That, of course, shouldn't stop others from taking a stab at it themselves. I'd be happy to see what others come up with. |
Alternative
is expected to be a monoid.But for
Parser
we have:Implications:
empty
erases useful error message.p1 <|> p2 <|> p3
withasum [p1, p2, p3]
(asum
always appendsempty
at the end).The text was updated successfully, but these errors were encountered: