Reading material

Pages 185-191 and 213-219.

Additional material

(* Trees where each branch node
   is labelled with an element
   may have a finite number of branches. 
*)
datatype 'a tree = Leaf
                 | Branch of 'a * 'a tree list

(* Apply the function f to each element in the tree *)
fun tree_map f Leaf = Leaf
  | tree_map f (Branch(v, ts)) = Branch(f v, map (tree_map f) ts)

(* Apply the function f to the elements in the tree from top to
   bottom.  Leaves return e. 
*)
fun tree_fold f e Leaf = e
  | tree_fold f e (Branch(v, ts)) = f(v, map (tree_fold f e) ts)