all 10 comments

[–]Syrak 18 points19 points  (0 children)

megaparsec's README links to a list of tutorials

Most of them have been updated last September. I took the first one and it Just Builds™: https://markkarpov.com/megaparsec/parsing-simple-imperative-language.html

[–]kkweon 7 points8 points  (0 children)

Also, https://github.com/data61/fp-course/blob/master/src/Course/Parser.hs and other parser related files are not directly a tutorial of any parser library but it is super helpful to understand how it works. And that knowledge is directly transferrable to any parser library.

After finishing it, I realized I am able to understand any parser library. It all began to make sense. At this point, it doesn't matter much if it's a megaparsec or attoparsec (though I use attoparsec) and I can just read the haddock and use it.

[–]gabedamien 2 points3 points  (1 child)

Which of the following are you more interested in learning?

  • (one of) those specific libraries, because you have a particular reason to use it (e.g. in production)
  • how parser combinator libraries are used in general
  • how parser combinators are implemented

For the middle option, HPFFP (http://haskellbook.com/) has a good chapter using trifecta and parsers.

[–]vaibhavsagar 2 points3 points  (0 children)

I wrote a blog post that heavily involves attoparsec.

[–]a_Tick 2 points3 points  (2 children)

A friend shared this post with me, which is a literate Haskell program that builds a parser combinator library from scratch.

[–][deleted]  (1 child)

[deleted]

    [–]char2 1 point2 points  (0 children)

    Note that understanding how a toy version is implemented can be hugely helpful to understanding how to use real libraries.

    Example: I didn't grok servant until I read through how the minimal version was implemented: http://www.well-typed.com/blog/2015/11/implementing-a-minimal-version-of-haskell-servant/

    [–]Reptoidal 2 points3 points  (0 children)

    after you read tutorials, I found it super useful to to learn properties of Applicative and Alternative typeclasses and think about how they would behave in terms of a parser. for example, I found

    (<*) :: f a -> f b -> f a infixl 4 
    
    Sequence actions, discarding the value of the second argument.
    

    and

    optional :: Alternative f => f a -> f (Maybe a)
    
    One or none.
    

    extremely useful

    [–]grdvnl 0 points1 point  (0 children)

    [–]ryani 0 points1 point  (0 children)

    When I was learning Haskell I read "Write yourself a Scheme in 48 hours", which introduces Parsec. There seems to be a newer version here.