[Haskell-cafe] [Haskell Cafe] Parsec: buildExpressionParser and
parens typecheck problem
Paul Sujkov
psujkov at gmail.com
Fri Jul 10 18:27:09 EDT 2009
Hi haskellers,
I'm trying to use buildExpressionParser parser generator from ParsecExpr
module of Parsec (
http://legacy.cs.uu.nl/daan/download/parsec/parsec.html#ParsecExpr). It
works well, except for the "parens" token parser (
http://legacy.cs.uu.nl/daan/download/parsec/parsec.html#parens). This code
(sample from Expressions part of the manual) typechecks fine:
expr :: Parser Integer
expr = buildExpressionParser table factor
<?> "expression"
table = [[op "*" (*) AssocLeft, op "/" div AssocLeft]
,[op "+" (+) AssocLeft, op "-" (-) AssocLeft]
]
where
op s f assoc
= Infix (do{ string s; return f}) assoc
factor = do{ char '('
; x <- expr
; char ')'
; return x
}
<|> number
<?> "simple expression"
but if I try to use parens:
factor = parens expr
<|> number
<?> "simple expression"
it fails to typecheck:
Couldn't match expected type `GenTokenParser s u m'
against inferred type `Parser Integer'
In the first argument of `parens', namely `expr'
In the first argument of `(<|>)', namely `parens expr'
In the first argument of `(<?>)', namely `parens expr <|> number'
Failed, modules loaded: none.
the type of expr infers to GenParser Char () Integer, and the expected type
for the parens is GenTokenParser s u m (however, manual introduces it with
the type CharParser st a expected)
It seems pretty weird for me, as there are numerous examples of using parens
with the buildExpressionParser (e.g.
http://blog.moertel.com/articles/2005/08/27/power-parsing-with-haskell-and-parsec)
and nobody comments such an error. I know I'm missing something very simple
here, maybe someone could help me with it? Thanks in advace
I'm using GHC 6.10.1 and Parsec 3.0.0
--
Regards, Paul Sujkov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090710/de181677/attachment.html
More information about the Haskell-Cafe
mailing list