------------------------------------------------------------
-- Your code goes below here
------------------------------------------------------------
+
+-- Exercise 1. functor instance for Parser
+instance Functor Parser where
+ -- Parser a == String -> (a, String)
+ -- first :: (a -> b) -> (a, c) -> (b, c)
+ -- fmap :: (a -> b) -> Parser a -> Parser b
+ fmap f (Parser pf) = Parser (\s -> case (pf s) of
+ Nothing -> Nothing
+ Just v -> Just $ (uncurry (first f) v))
+ where first f' a b = (f' a, b)