From: Jim Pryor Date: Thu, 2 Dec 2010 15:49:20 +0000 (-0500) Subject: manip trees tweaks X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=3d98e6d16929dbdeb122713b86171b86039dca4a;ds=sidebyside manip trees tweaks Signed-off-by: Jim Pryor --- diff --git a/manipulating_trees_with_monads.mdwn b/manipulating_trees_with_monads.mdwn index 16097633..10c95564 100644 --- a/manipulating_trees_with_monads.mdwn +++ b/manipulating_trees_with_monads.mdwn @@ -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'));;