Working on Brent Yorgey\'s 2013 UPenn class homework, the following newtype
exists:
newtype Parser a = Parser { runParser :: String -> Maybe (a
To apply g on a Parser f, i.e. composite g and f. However, as g is a general function,and f returns Maybe(a,String), we need to convert g to
Maybe(a,String)->d
. Given first::(a->b)->(a,c)->(b,c)
,then
first.Maybe :: Maybe(a->b,a->b)->Maybe(a,String)->Maybe(b,String)
first.Maybe :: (a->b)->Maybe(a,String)->Maybe(b,String)
first.Maybe g :: Maybe(a,String)->Maybe(b,String)
so
instance Functor Parser where
fmap g f = Parser $ fmap (first.Maybe g) . f