(* --- File Tree.ml --- * Time-stamp: * Created on: by mz@labri.fr on [Espelette] *) type 'a tree = Empty | Bin of 'a * 'a tree * 'a tree let rec infix t f = match t with | Empty -> () | Bin(v, l, r) -> infix l f; f v; infix r f let rec prefix t f = match t with | Empty -> () | Bin(v, l, r) -> f v; prefix l f; prefix r f let rec postfix t f = match t with | Empty -> () | Bin(v, l, r) -> postfix l f; postfix r f; f v let leaf v = Bin(v, Empty, Empty) let p = Bin(1, Bin(2, leaf(3), leaf(4)), Bin(5, leaf(6), leaf(7))) let _ = prefix p (fun v -> Printf.printf "%d " v) let _ = infix p (fun v -> Printf.printf "%d " v) let _ = postfix p (fun v -> Printf.printf "%d " v) (* tree.ml ends here *)