manip trees tweak
[lambda.git] / manipulating_trees_with_monads.mdwn
index 7be7fd4..e309faa 100644 (file)
@@ -46,18 +46,18 @@ 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,
 leaving the structure of the tree unchanged.  For instance:
 
        let double i = i + i;;
-       tree_map t1 double;;
+       tree_map double t1;;
        - : int tree =
        Node (Node (Leaf 4, Leaf 6), Node (Leaf 10, Node (Leaf 14, Leaf 22)))
        
@@ -80,7 +80,7 @@ each leaf instead, by supplying the appropriate `int -> int` operation
 in place of `double`:
 
        let square i = i * i;;
-       tree_map t1 square;;
+       tree_map square t1;;
        - : int tree =
        Node (Node (Leaf 4, Leaf 9), Node (Leaf 25, Node (Leaf 49, Leaf 121)))
 
@@ -140,7 +140,7 @@ It would be a simple matter to turn an *integer* into an `int reader`:
        asker 2 (fun i -> i + i);;
        - : int = 4
 
-This is a monadic box that waits for an an environment (here, the argument `modifier`) and returns what that environment maps `a` to.
+`asker a` is a monadic box that waits for an an environment (here, the argument `modifier`) and returns what that environment maps `a` to.
 
 How do we do the analagous transformation when our `int`s are scattered over the leaves of a tree? How do we turn an `int tree` into a reader?
 A tree is not the kind of thing that we can apply a