From: Jim Pryor Date: Mon, 13 Dec 2010 04:10:17 +0000 (-0500) Subject: manip trees tweak X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=6debd883b7ee5c9125743a23d05e997b9188f90e manip trees tweak Signed-off-by: Jim Pryor --- diff --git a/manipulating_trees_with_monads.mdwn b/manipulating_trees_with_monads.mdwn index 7be7fd49..4f91bbbb 100644 --- a/manipulating_trees_with_monads.mdwn +++ b/manipulating_trees_with_monads.mdwn @@ -46,11 +46,11 @@ We'll be using trees where the nodes are integers, e.g., Our first task will be to replace each leaf with its double: - let rec tree_map (t : 'a tree) (leaf_modifier : 'a -> 'b): 'b tree = + let rec tree_map (leaf_modifier : 'a -> 'b) (t : 'a tree) : 'b tree = match t with | Leaf i -> Leaf (leaf_modifier i) - | Node (l, r) -> Node (tree_map l leaf_modifier, - tree_map r leaf_modifier);; + | Node (l, r) -> Node (tree_map leaf_modifier l, + tree_map leaf_modifier r);; `tree_map` takes a tree and a function that transforms old leaves into new leaves, and maps that function over all the leaves in the tree,