type tree = Leaf | Node of int * tree * tree

let rec depth t = match t with
  | Leaf -> 0
  | Node (_, l, r) ->
    let dl = depth l in
    let dr = depth r in
    1 + (if dl > dr then dl else dr)

;;

let t = Node (1,
  Node (2,
    Node (4, Leaf, Leaf),
    Node (5,
      Node (8, Leaf, Leaf),
      Leaf)),
  Node (3, Leaf, Leaf))
in
depth t
