visi-lang/visi — pull request #9 by jonsterling (2012-01-18 08:08:31+00:00)
Title: Rewrote some parsers in Applicative style

Monadic parsers are great, and do-notation makes it really easy to write them naturally. However, there are many cases where `Monad` is too powerful an abstraction (and `Applicative` will suffice); likewise, there are times when do-notation causes less clear code than the simple use of monadic combinators like `(>>=)`. A few patterns that are ripe for reduction:

### Mapping a function over a monadic value

~~~~hs
-- do {x <- f1; return (f2 x)}
f2 <$> f1
~~~~

### Mapping a function of a functor with multiple parameters

~~~~hs
-- do {x <- f1; f2; y <- f3; return (f4 x y)}
f4 <$> f1 <* f2 <*> f3
~~~~

### Discarding the output of a parser, and returning something else

~~~~hs
-- do {x; return y}
y <$ x
~~~~

### Flat-mapping a function over a monadic value

~~~~hs
-- do {x <- f1; f2 x}
f1 >>= f2
~~~~

(All the tests from the wiki pass after these changes). If heavy use of `Control.Applicative` isn't your speed, that's totally fine; feel free to ignore this pull request. I'm hugely interested in Visi, and can't wait to see what you do with it.