category-theory-presentation/categories/30_How/200_Monads/020_Natural_Transformation_Examples_2_4.md
2013-02-28 16:49:12 +01:00

936 B

Natural Transformation Examples (2/4)

data Tree a = Empty | Node a [Tree a]
toList :: Tree a -> [a]
toList Empty = []
toList (Node x l) = [x] ++ concat (map toList l)

toList is a natural transformation. It is also a morphism from Tree to [] in the Category of \(\Hask\) endofunctors.

natural transformation commutative diagram
natural transformation commutative diagram
toList . toTree = id & toTree . toList = id &
therefore [] & Tree are isomorph.