-So we've defined a Tree monad:
-
- type 'a tree = Leaf of 'a | Node of ('a tree) * ('a tree);;
- let tree_unit (a: 'a) : 'a tree = Leaf a;;
- let rec tree_bind (u : 'a tree) (f : 'a -> 'b tree) : 'b tree =
- match u with
- | Leaf a -> f a
- | Node (l, r) -> Node (tree_bind l f, tree_bind r f);;
-
-What's this have to do with the `tree_monadize` functions we defined earlier?
-
- let rec tree_monadize (f : 'a -> 'b reader) (t : 'a tree) : 'b tree reader =
- match t with
- | Leaf a -> reader_bind (f a) (fun b -> reader_unit (Leaf b))
- | Node (l, r) -> reader_bind (tree_monadize f l) (fun l' ->
- reader_bind (tree_monadize f r) (fun r' ->
- reader_unit (Node (l', r'))));;
-
-... and so on for different monads?
-
-The answer is that each of those `tree_monadize` functions is adding a Tree monad *layer* to a pre-existing Reader (and so on) monad. We discuss that further here: [[Monad Transformers]].
+Our different implementations of `tree_monadize` above were different *layerings* of the Tree monad with other monads (Reader, State, List, and Continuation). We'll explore that further here: [[Monad Transformers]].