Skip to content
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

Use Control.Applicative as a parser. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Use Control.Applicative as a parser. #3

wants to merge 1 commit into from

Conversation

jlouis
Copy link

@jlouis jlouis commented Mar 30, 2015

Control.Applicative often simplifies parsers and this is no exception. Use the
applicative <$> and <*> to run the 'getErl' function which simplifies its structure
and makes it more clear what is going on.

While here, destroy a couple of liftM's, now we have started to use applicatives.

Note that Applicatives sits "between" a functor and a monad. They allow for some monad-like operations (and all monads are applicatives, but not vice versa). Here, we can utilize the applicatives to invert the ordering and get a parser which looks more like Erlang binary pattern matching. Also, we avoid having to invent the names for what we parse because it is stuffed directly into the position of the algebraic data type.

Not tested at all, so please don't blindly eat it. It compiles however, and since this is Haskell, it must be correct (snicker). No, really, read through the code and verify I did not miss a putN/putn erroneous swap.

Control.Applicative often simplifies parsers and this is no exception. Use the
applicative <$> and <*> to run the 'getErl' function which simplifies its structure
and makes it more clear what is going on.

While here, destroy a couple of liftM's, now we have started to use applicatives.
@bookshelfdave
Copy link
Collaborator

nice :-)

@joedevivo
Copy link
Owner

Thanks! This needs more focus than I can give it while I'm at chefconf, but I'll get to it next week :D

@jlouis
Copy link
Author

jlouis commented Apr 1, 2015

Take your time. I'm going on a vacation which means my network bandwidth is being severly downgraded from 100mbit to 4mbit :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants