Skip to content

Commit

Permalink
Merge pull request #65 from sgraf812/master
Browse files Browse the repository at this point in the history
Added Alternative constraint and made some minor changes
  • Loading branch information
sdiehl committed Apr 19, 2017
2 parents 204747f + d86a804 commit 1e609fb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions 002_parsers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down
4 changes: 2 additions & 2 deletions chapter3/parsec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1e609fb

Please sign in to comment.