chapter3/parsec.hs: handle ambigous parses in runParser

The text doesn't mention ambigous parses, and the code didn't handle them.
The easiest way to fix the code without necessarily having to write about
this case is to hande it as parse error and merge it with the no parse case
by replacing the [] pattern with _.
This commit is contained in:
Christian Sievers 2015-01-30 18:15:31 +01:00
parent d40f93d884
commit ca8b771489

View File

@ -13,7 +13,7 @@ runParser m s =
case parse m s of
[(res, [])] -> res
[(_, rs)] -> error "Parser did not consume entire stream."
[] -> error "Parser error."
_ -> error "Parser error."
item :: Parser Char
item = Parser $ \s ->