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,