Merge pull request #65 from sgraf812/master

Added Alternative constraint and made some minor changes
This commit is contained in:
Stephen Diehl 2017-04-19 19:41:59 +01:00 committed by GitHub
commit 1e609fbff1
2 changed files with 4 additions and 4 deletions

View File

@ -105,14 +105,14 @@ itself if there is not at least a single match.
```haskell
-- | One or more.
some :: f a -> f [a]
some :: Alternative f => f a -> f [a]
some v = some_v
where
many_v = some_v <|> pure []
some_v = (:) <$> v <*> many_v
-- | Zero or more.
many :: f a -> f [a]
many :: Alternative f => f a -> f [a]
many v = many_v
where
many_v = some_v <|> pure []

View File

@ -12,7 +12,7 @@ runParser :: Parser a -> String -> a
runParser m s =
case parse m s of
[(res, [])] -> res
[(_, rs)] -> error "Parser did not consume entire stream."
[(_, _)] -> error "Parser did not consume entire stream."
_ -> error "Parser error."
item :: Parser Char
@ -62,7 +62,7 @@ satisfy :: (Char -> Bool) -> Parser Char
satisfy p = item `bind` \c ->
if p c
then unit c
else (Parser (\cs -> []))
else failure
-------------------------------------------------------------------------------
-- Combinators