Repository navigation
Thoughts on monadic parsing #2
chris-martin
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
We keep track of advancement, fallibility, and atomicity in the types, resulting in seven different parser types. One thing I hadn't realized upfront when I started this is that traditional applicative/monadic style goes right out the window, for a few reasons:
<*>or>>=them (like the experience oflifting monad transformers, but worse)MoveandAtomicMoveare not Applicative, because they don't supportpure.Atombe Applicative, the sequencing operations would have to implicitly add backtracking, and I'm not sure that's a great idea.To get back the convenience of monadic parsing, I defined my own
>>=,<*>, etc. operators that make use of theKindJointype family.The parser API then has a handful of functions like this that replace the standard
ApplicativeandMonadones:This isn't so bad if we make use of the
QualifiedDoextension introduced in GHC 9.0, which allows the built-indosyntax to use our custom(>>=)et al. operators instead of the standard functions.One thing we lose is the ability to use all the standard Monad combinators (and Alternative ones too, though I haven't gotten to working on alternative choice yet). My suspicion is that this will not really be much of a loss, as it seems like many parsing libraries offer replacements for some of them anyway.
All reactions