Natural Transformations
Prev: Function Types Next: Declarative Programming
Prev: Function Types Next: Declarative Programming
Exercises
- Define a natural transformation from the
Maybefunctor to the list functor. Prove the naturality condition for it. - Define at least two different natural transformations between
Reader ()and the list functor. How many different lists of()are there? - Continue the previous exercise with
Reader BoolandMaybe. - Show that horizontal composition of natural transformation satisfies the naturality condition (hint: use components). It’s a good exercise in diagram chasing.
- Write a short essay about how you may enjoy writing down the evident diagrams needed to prove the interchange law.
- Create a few test cases for the opposite naturality condition of transformations between different
Opfunctors. Here’s one choice:
op :: Op Bool Int
op = Op (\x -> x > 0)and
f :: String -> Int
f x = read x