[Haskell-cafe] Parsec Expected Type

Paul Keir pkeir at dcs.gla.ac.uk
Mon Apr 7 11:23:34 EDT 2008

Thanks. reservedOp is a better fit; ":+" should only be ":+".

I also overcame my type issues in an ad-hoc manner, adding

>> return ()

whenever I needed to.

-----Original Message-----
From: Tillmann Rendel [mailto:rendel at rbg.informatik.tu-darmstadt.de] 
Sent: 30 March 2008 12:30
To: Paul Keir; haskell-cafe at haskell.org
Subject: Re: [Haskell-cafe] Parsec Expected Type

Paul Keir 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. 

You may consider using reservedOp for ":", depending on how ":+" should
be parsed:

  for ":+" use reservedOp
  for ":" "+" use symbol

If you use reserved, then ":name" will be parsed as ":name" not ":"
"name" as you probably expect. generally, reserved is for
identifier-like keywords, and reservedOp for operator-like keywords.

> Perhaps I'd express my confusion better if I ask: Why are 'reserved'
> and 'symbol' different types?

I have no idea. They aren't in the Parsec manual on Daans site:


You can fix this by defining

  reserved name = ParsecToken.reserved tokenParser name >> return name

instead of

  reserved = ParsecToken.reserved tokenParser

to "import" the reserved component from the tokenParser to the toplevel.

  reserved :: String -> CharParser st String

Another option is to fix it the other way, by defining

  symbol name = ParsecToken.symbol tokenParser name >> return ()

or to fix it in a ad-hoc manner, by defining

  ignored = (>> return ())

and using it in the approbiate places, like

  parameterOrColon = reserved "parameter" <|> ignored (symbol ":")


More information about the Haskell-Cafe mailing list