Category Theory for Programmers Chapter 10: Natural Transformations
A reminder of the naturality condition: G f ∘ αa = αb ∘ F f
Define a natural transformation from
Listfunctor. Prove naturality condition for it.
asList :: Maybe a -> [a] asList Nothing =  asList (Just x) = [x]
To prove the naturality condition,
fmap f . asList = asList . fmap f, we have two cases,
fmap f (asList Nothing) = fmap f  =  asList (fmap f Nothing) = asList Nothing = 
fmap f (asList (Just x)) = fmap f [x] = [f x] asList (fmap f (Just x)) = asList (Just (f x)) = [f x]
Define at least 2 different natural transformations between
Reader ()and the list functor
. How many different lists of
asEmptyList :: Reader () a -> [a] asEmptyList _ = 
asOneList :: Reader () a -> [a] asOneList r = [r ()]
asTwoList :: Reader () a -> [a] asTwoList r = [r (), r ()]
And so on, there are infinitely many of these.
Define natural transformations between
none :: Reader Bool -> Maybe none _ = Nothing
true :: Reader Bool -> Maybe true r = Just (r True)
false :: Reader Bool -> Maybe false r = Just (r False)
Show that horizontal composition of natural transformations satisfies the naturality condition.
F'be functors from categories
G'functors from categories
Cwith natural transformations
G'. We must show the naturality condition holds for
(G ∘ F) f ∘ (β * α) = (β * α) ∘ (G' ∘ F') f
I don’t want to do it.
Naturality conditions of transformations between differetn
Op A Bis
B -> A, and
op :: Op Bool Int op = Op (\x -> x > 0) f :: String -> Int f x = read x
fmap f op :: Op Bool StringDon’t know where to go with this…