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
Maybeto theListfunctor. 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,NothingandJust 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 BoolandMaybe.none :: Reader Bool -> Maybe none _ = Nothingtrue :: 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 categoriesAtoBandG,G'functors from categoriesBtoCwith natural transformationsαfromFtoF'andβfromGtoG'. We must show the naturality condition holds for(G ∘ F) f ∘ (β * α) = (β * α) ∘ (G' ∘ F') fI don’t want to do it.
-
No essays.
-
Naturality conditions of transformations between differetn
Opfunctors. Ie,Op A BisB -> A, andop :: Op Bool Int op = Op (\x -> x > 0) f :: String -> Int f x = read xfmap f op :: Op Bool StringDon’t know where to go with this…