parsing - <|> in Parsec - why do these examples behave differently? -
i think i'm misunderstanding <|> in parsec - have input stream contains either bunch of as in 1 representation or bunch of as in representation. expect following functions equivalent (given input form said, , have verified is):
foo = ... a1s <- many $ try $ a1 a2s <- many $ try $ a2 return $ a1s ++ a2s versus
foo = ... <- (many $ try $ a1) <|> (many $ try $ a2) return what going wrong? first function works on input, second function fails, saying unexpected a2, expecting a1.
when give sequence of a2 latter parser, first many matches , returns empty list, doesn't try match against second many.
you can use many1 instead.
foo = ... <- many1 a1 <|> many a2 return in case, many1 fails when give sequence of a2, , many matches against input.
Comments
Post a Comment