<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7651.59">
<TITLE>RE: [Haskell-cafe] Parsec Expected Type</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>Many thanks guys, you've really taught me how to catch a fish here!<BR>
Paul<BR>
<BR>
<BR>
-----Original Message-----<BR>
From: Brandon S. Allbery KF8NH [<A HREF="mailto:allbery@ece.cmu.edu">mailto:allbery@ece.cmu.edu</A>]<BR>
Sent: Sat 3/29/2008 1:41 AM<BR>
To: haskell-cafe@haskell.org Cafe<BR>
Cc: Paul Keir<BR>
Subject: Re: [Haskell-cafe] Parsec Expected Type<BR>
<BR>
<BR>
On Mar 28, 2008, at 21:12 , Ryan Ingram wrote:<BR>
> On 3/28/08, Paul Keir <pkeir@dcs.gla.ac.uk> wrote:<BR>
>> What I'd like is to parse either the string "parameter", or the <BR>
>> string ":".<BR>
>> I'm using 'reserved' and 'symbol' because they seem to correspond <BR>
>> well to<BR>
>> the concepts in the language I'm parsing. I could try,<BR>
>><BR>
>> tester3 = reserved "parameter" <|> do { symbol ":"; return () }<BR>
><BR>
> Or you could factor this behavior out into a new combinator:<BR>
><BR>
>> or_ :: Parser a -> Parser b -> Parser ()<BR>
>> or_ x y = (x >> return ()) <|> (y >> return ())<BR>
><BR>
>> tester3 = reserved "parameter" `or_` symbol ":"<BR>
<BR>
Or if you'd like to be inscrutable:<BR>
<BR>
import Data.Function<BR>
<BR>
or_ = (>> return ()) `on` (<|>)<BR>
<BR>
--<BR>
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com<BR>
system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu<BR>
electrical and computer engineering, carnegie mellon university KF8NH<BR>
<BR>
<BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>