manip trees tweaks
authorJim Pryor <profjim@jimpryor.net>
Thu, 2 Dec 2010 15:49:20 +0000 (10:49 -0500)
committerJim Pryor <profjim@jimpryor.net>
Thu, 2 Dec 2010 15:49:20 +0000 (10:49 -0500)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
manipulating_trees_with_monads.mdwn

index 1609763..10c9556 100644 (file)
@@ -498,7 +498,7 @@ Okay, now let's do the same thing for our Tree monad.
 
        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 *)
@@ -511,7 +511,7 @@ Okay, now let's do the same thing for our Tree monad.
 
        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'));;