[Haskell-cafe] Parsec Expected Type
Paul Keir
pkeir at dcs.gla.ac.uk
Sat Mar 29 09:53:08 EDT 2008
Many thanks guys, you've really taught me how to catch a fish here!
Paul
-----Original Message-----
From: Brandon S. Allbery KF8NH [mailto:allbery at ece.cmu.edu]
Sent: Sat 3/29/2008 1:41 AM
To: haskell-cafe at haskell.org Cafe
Cc: Paul Keir
Subject: Re: [Haskell-cafe] Parsec Expected Type
On Mar 28, 2008, at 21:12 , Ryan Ingram wrote:
> On 3/28/08, Paul Keir <pkeir at dcs.gla.ac.uk> 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] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university KF8NH
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080329/e17c5212/attachment.htm
More information about the Haskell-Cafe
mailing list