Work on the homework of a class working on Brent Yorgey 2013 UPenn exists newtype:
newtype Parser a = Parser { runParser :: String -> Maybe (a, String) }
I am trying to implement Parserhow Functor.
Given the following function firstthat will help solve this problem:
first :: (a -> b) -> (a, c) -> (b, c)
first f (a, c) = (f a, c)
I tried the following:
instance Functor (Parser) where
fmap g (Parser f) = Parser $ fmap (first g) (f . g)
However, this does not work.
As I understand it, type f String -> Maybe (a, String). So, I do not know how applya Stringto fget Maybe (a, String).
As soon as I receive Maybe (a, String), I believe that I can just run fmap (first g) ...where it ...represents Maybe.
Please let me know how to receive Maybe (a, String).
Since a is frequired Stringto give a type Maybe (a, String), I do not know where to find this argument String.