-
Notifications
You must be signed in to change notification settings - Fork 52
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
Chris martin's seven parser types #202
Comments
I've went ahead and made my in-progress Haskell project public so you can have a look. A few things that might be worth reading:
There are actually only two different type definitions, One noteworthy observation that I hadn't realized upfront when I started this is that traditional applicative/monadic style goes right out the window if you introduce this many types, for a few reasons:
To get back the convenience of monadic parsing, I defined my own type family KindJoin (k1 :: ActionKind) (k2 :: ActionKind) :: ActionKind
type a :> b = KindJoin a b -- its infix alias is convenient sometimes My parser API then has a handful of functions like this that replace the standard (>>=) ::
Monad m => IsAction k1 => IsAction k2 => IsAction k3 => ActionJoin k1 k2 => k1 :> k2 ~ k3 =>
Parser text k1 m a -> (a -> Parser text k2 m b) -> Parser text k3 m b This isn't so bad if we make use of the Anyway, caveats aside, I've been obsessed with this for a week now, a good bit of it is working, and I think it shows promise 😄 Oof, I wrote a lot. Going to copy some of this text into discussions on my own repo. |
Thanks for the writeup @chris-martin ! (Purescript does have qualified do). |
Update - I've still been noodling on this library, and seven is down to five. I've removed the parser types that include a movement guarantee. I had no way to codify this property in the type definitions, and so it relied entirely on unsafe casts to indicate that I know that a parser will always advance if it succeeds. I had been hoping that just a few primitive parsers would need unsafe casts, and that the information would end up getting propagated upward through the We are left with... Four core parser types:
And the composition:
|
Nice. |
Something to aspire to:
https://twitter.com/chris__martin/status/1545102338360107008?t=MnxHlQ4zc6fzL28jX_IOzg&s=09
The text was updated successfully, but these errors were encountered: