From 11709255c308906c8d78c449c462c0cecc79f806 Mon Sep 17 00:00:00 2001 From: Christian Sievers Date: Fri, 30 Jan 2015 18:29:15 +0100 Subject: [PATCH] chapter3/parsec.hs: change definition of option Let (<|>) (which equals option) return all parses of the succeeding parser, as seems to be implied by the description in the chapter on Parsing. Example: parse (empty <|> ((unit 'a') `combine` (unit 'b'))) "" --- chapter3/parsec.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chapter3/parsec.hs b/chapter3/parsec.hs index 1fc3c3c..5d2cbfe 100644 --- a/chapter3/parsec.hs +++ b/chapter3/parsec.hs @@ -54,9 +54,9 @@ failure = Parser (\cs -> []) option :: Parser a -> Parser a -> Parser a option p q = Parser $ \s -> - case parse (mplus p q) s of - [] -> [] - (x:xs) -> [x] + case parse p s of + [] -> parse q s + res -> res satisfy :: (Char -> Bool) -> Parser Char satisfy p = item `bind` \c ->