Parsec: Applicatives vs Monads

前端 未结 3 958
被撕碎了的回忆
被撕碎了的回忆 2020-12-23 15:11

I\'m just starting with Parsec (having little experience in Haskell), and I\'m a little confused about using monads or applicatives. The overall feel I had after reading \"R

3条回答
  •  温柔的废话
    2020-12-23 15:40

    Following on from @pigworker (I'm too new on here to comment alas) it's worth noting join $ fM <*> ... <*> ... <*> ... as a pattern as well. It nets you a "bind1, bind2, bind3..." family the same way <$> and <*> get you an "fmap1,fmap2,fmap3" one.

    As a stylistic thing, when you're used enough to the combinators it's possible to use do much the same as you would use let: as a way to highlight when you wanted to name something. I tend to want to name things more often in parsers for example, because that probably corresponds to names in the spec!

提交回复
热议问题