On Mar 28, 2008, at 21:12 , Ryan Ingram wrote:
On 3/28/08, Paul Keir <[EMAIL PROTECTED]> wrote:
What I'd like is to parse either the string "parameter", or the string ":". I'm using 'reserved' and 'symbol' because they seem to correspond well to
the concepts in the language I'm parsing. I could try,

tester3 = reserved "parameter" <|> do { symbol ":"; return () }

Or you could factor this behavior out into a new combinator:

or_ :: Parser a -> Parser b -> Parser ()
or_ x y = (x >> return ()) <|> (y >> return ())

tester3 = reserved "parameter" `or_` symbol ":"

Or if you'd like to be inscrutable:

import Data.Function

or_ = (>> return ()) `on` (<|>)

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon university    KF8NH


_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to