Tillmann Rendel wrote:
My self-defined monadic combinator of choice to use with parsec is
a >>~ b = a >>= \x -> b >> return x
It works like (>>), but returns the result of the first instead of the
result of the second computation. It is kind of an alternative for
between:
between lparen rparen p == lparen >> p >>~ rparen
Cool. I've always liked how Parsec made parsers so readable, and this
makes it even more so.
It can be usefull like this:
data Term = TVar Identifier | TTerm Identifier [Term]
term = (return TTerm
`ap` try (identififer >>~ lparen)
`ap` (term `sepBy` comma >>~ rparen))
<|> (return TVar
`ap` identifier)
After accepting lparen, the second branch is discarded.
Interesting. I think I'll have to keep this one around. Not sure if I'll
need it, but its the kind of thing that would have taken me a while to
solve ;)
Levi
lstephen.wordpress.com
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe