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
Maybe
to theList
functor. 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,Nothing
andJust x
.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()
are there?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
Reader Bool
andMaybe
.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.
Let
F
,F'
be functors from categoriesA
toB
andG
,G'
functors from categoriesB
toC
with natural transformationsα
fromF
toF'
andβ
fromG
toG'
. We must show the naturality condition holds for(G ∘ F) f ∘ (β * α) = (β * α) ∘ (G' ∘ F') f
I don’t want to do it.

No essays.

Naturality conditions of transformations between differetn
Op
functors. Ie,Op A B
isB > A
, andop :: Op Bool Int op = Op (\x > x > 0) f :: String > Int f x = read x
fmap f op :: Op Bool String
Don’t know where to go with this…