As part of a homework assignment we are working on a parser in Haskell. We have this data type
newtype Parser a = Parser { parse :: String -> Maybe (a,String) }
This is clear to me,our parser gets a string are return expression from type a and the remaining unparsed string.
But next we are having this functor definition :
instance Functor Parser where
fmap f p = Parser $ \s -> (\(a,c) -> (f a, c)) <$> parse p s
And I'm completely lost. It seems to me that parse p s gives the parsed expression from type a but I can't understand what this fmap is actually doing and why it makes sense.
Hope that someone can give me a clue.
Thanks!