-
Notifications
You must be signed in to change notification settings - Fork 83
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
Remove user state from Megaparsec state #18
Comments
Can we get backtracking state by combining ParsecT and StateT? (I think Pandoc uses backtracking state.) |
I'm not sure. Ability to backtrack user state may be useful in some circumstances. What do you mean by "Pandoc uses this ability". Does Pandoc use Parsec's user state or some other parser in combination with |
Sorry, I realised it wasn't clear half a minute posting the comment and edited it. I meant that Pandoc uses backtracking state. |
I. e. Parsec user state. |
OK, I have to admit that I underestimated benefits of backtracking user state. In this case, we should continue to be maximalists in this Haskell-parsing world (because there are too many minimalists) and keep backtracking user state in Megaparsec as additional selling point. |
After reading this article I wonder now whether you could remove user state after all, since backtracking state could seemingly be achieved with |
Hm, no, then we'd have to use @mrkkrp: how bad of an idea is it to create a |
@neongreen, Interesting. We will return to this idea when obligatory part of our work is completed (i.e. finish Which functions would you include into |
@mrkkrp, it turns out that Edward Kmett already did it: |
@neongreen, Thanks for the links, I will return to this when everything else is finished. Indeed it looks like the right thing do to. |
Before you reinvent the wheel and copy/paste this class, perhaps the author can be contacted to find a solution. It is strange that just to reasonably work with some parser in some typeclass, one would have to depend on all libraries that support that interface. So I think something will have to happen upstream. |
@tulcod it's not “all libraries”, it's that it would be hard to convince authors of parsec and attoparsec to depend on parsers. Other libraries – like trifecta – depend on parsers (not the other way around). |
I don't really get why this thing depends on
…and because of that |
Well, the alternative is splitting it into
Most likely, yeah. |
@tulcod, I'm not against reinventing the wheel if it's easier then buying one and gives better results. For example Megaparsec have different naming conventions to parse various categories of characters, etc. Not sure we could reuse this “as is”. |
@mrkkrp, well I definitely agree that we have to analyse carefully what this common interface would really express, since yes, many instances will have different naming and semantics. So most likely we will have to copy/paste and edit some stuff. But I'm just saying that before we do that, we should at least try to contact the author of parsers. |
I created a separate issue for this so that it won't get forgotten. |
Parsec itself is a monad transformer (
ParsecT
). This means that state monad can be used with it easily if user of the library needs to. However, Parsec, unlike other similar libraries, keep special user state field in itsState
record. As far as I can tell, in vast majority of cases user state is nothing but unit()
.Here is a comment found in original Parsec's source code, above definition of instance of
MonadState
:I'm seeing
stateUser
field as unnecessary complication. I'm proposing removal of this custom user state from Megaparsec. What do you think, @albertnetymk, @neongreen?The text was updated successfully, but these errors were encountered: