mirror of
https://github.com/sdiehl/write-you-a-haskell.git
synced 2024-09-11 19:47:31 +03:00
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'))) ""
This commit is contained in:
parent
ca8b771489
commit
11709255c3
@ -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 ->
|
||||
|
Loading…
Reference in New Issue
Block a user