mirror of
https://github.com/sdiehl/write-you-a-haskell.git
synced 2024-09-11 11:46:57 +03:00
DRY + nitpicking
This commit is contained in:
parent
1e9b0fba91
commit
d86a804a29
@ -12,7 +12,7 @@ runParser :: Parser a -> String -> a
|
|||||||
runParser m s =
|
runParser m s =
|
||||||
case parse m s of
|
case parse m s of
|
||||||
[(res, [])] -> res
|
[(res, [])] -> res
|
||||||
[(_, rs)] -> error "Parser did not consume entire stream."
|
[(_, _)] -> error "Parser did not consume entire stream."
|
||||||
_ -> error "Parser error."
|
_ -> error "Parser error."
|
||||||
|
|
||||||
item :: Parser Char
|
item :: Parser Char
|
||||||
@ -62,7 +62,7 @@ satisfy :: (Char -> Bool) -> Parser Char
|
|||||||
satisfy p = item `bind` \c ->
|
satisfy p = item `bind` \c ->
|
||||||
if p c
|
if p c
|
||||||
then unit c
|
then unit c
|
||||||
else (Parser (\cs -> []))
|
else failure
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- Combinators
|
-- Combinators
|
||||||
|
Loading…
Reference in New Issue
Block a user