(* The factorial function *) let rec fac n = match n with | 0 -> 1 | n -> n * fac (n - 1) (* sumlist sums the elements of an int list *) let rec sumlist ls = match ls with | [] -> 0 | n::xs -> n + sumlist xs (* a binary tree type *) type 'a tree = Leaf of 'a | Node of 'a tree * 'a tree (* a recursive function over binary trees *) let rec leafproduct t = match t with | Leaf n -> n | Node (t1,t2) -> leafproduct t1 * leafproduct t2 (* an example tree *) let mytree = Node (Leaf 42, Leaf 2) (* a set of integers *) module Intset = Set.Make (struct type t = int let compare n1 n2 = if n1 == n2 then 0 else if n1 > n2 then 1 else -1 end) (* a set of set of integers *) module Intsetset = Set.Make(struct type t = Intset.t let compare = Intset.compare end)