Theory and Design of PL (CS 538)
February 27, 2020
Read our comments on your HW!
max
functionNat
max
function on Char
Char
Maybe
[]
Maybe Int
[Int]
Define typeclasses for these things!
Maybe
, lists, trees, …f
is “mappable” if it has a fmap
f
doesn’t always need to be a “container”r
to something elseinstance Functor Maybe where
fmap f Nothing = Nothing
fmap f (Just x) = Nothing
-- What's the type?
-- fmap :: (a -> b) -> Maybe a -> Maybe b
instance Functor Maybe where
fmap f Nothing = Nothing
fmap f (Just x) = Nothing
-- What's the type?
-- fmap :: (a -> b) -> Maybe a -> Maybe b
fmap id (Just 42) === Nothing
f
then map g
is same as map g . f