Implement Alternative Parser
This commit is contained in:
parent
3deaeee24a
commit
39d77eafe0
1 changed files with 6 additions and 0 deletions
|
|
@ -37,3 +37,9 @@ instance Applicative Parser where
|
||||||
Just (rest, f) -> case a rest of
|
Just (rest, f) -> case a rest of
|
||||||
Nothing -> Nothing
|
Nothing -> Nothing
|
||||||
Just (rest', x) -> Just (rest', f x)
|
Just (rest', x) -> Just (rest', f x)
|
||||||
|
|
||||||
|
instance Alternative Parser where
|
||||||
|
empty = Parser $ const Nothing
|
||||||
|
(<|>) (Parser p1) (Parser p2) = Parser $ \input -> case p1 input of
|
||||||
|
Nothing -> p2 input
|
||||||
|
result -> result
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue