
On Fri, Jul 20, 2007 at 10:10:58PM +0200, Hugh Perkins wrote:
Newbie question: why does the following give "Not in scope 'c'" for the last line?
I assume you meant
string :: Parsec.Parser String string = do c <- Parsec.letter do cs <- string return c:cs Parsec.<|> return [c]
Without adding that indentation, the second do cuts of the first block and you get a rather different error. The problem here is that the line beginning Parsec.<|> is lined up with the first token after do, so layout adds a semicolon in front of it, but a statement can't begin with an operator, so to avoid that parse error the layout rules add the close brace and end the do block. It parses like this: string = ( do { c <- Parsec.letter ; cs <- string ; return c:cs } ) Parsec.<|> (return [c] The parse error rule is there so a do block will be closed by the end of surrounding parens or braces, maybe it has other uses. In any case, you really ought to use many1.
string = Parsec.many1 Parsec.letter
Brandon