diff --git a/app/Parser.hs b/app/Parser.hs index 5dee86d..5f8f718 100644 --- a/app/Parser.hs +++ b/app/Parser.hs @@ -37,3 +37,9 @@ instance Applicative Parser where Just (rest, f) -> case a rest of Nothing -> Nothing 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