let rec bind (u : 'a tree) (f : 'a -> 'b tree) : 'b tree =
match u with
- | Leaf a -> f a
+ | Leaf a -> (fun b -> Leaf b) (f a)
| Node (l, r) -> (fun l' r' -> Node (l', r')) (bind l f) (bind r f);;
(* monadic operations for the TreeT monadic transformer *)
let rec bind (u : ('a, M) tree) (f : 'a -> ('b, M) tree) : ('b, M) tree =
match u with
- | Leaf a -> M.unit (f a)
+ | Leaf a -> M.bind (f a) (fun b -> M.unit (Leaf b))
| Node (l, r) -> M.bind (bind l f) (fun l' ->
M.bind (bind r f) (fun r' ->
M.unit (Node (l', r'));;