1. (* Prints a binary tree sideways *)
  2.  
  3. type 'a tree =
  4.     | Node of 'a tree * 'a * 'a tree
  5.     | Nil
  6.  
  7. let rec print t =
  8.     let rec loop n = function
  9.         | Nil -> ()
  10.         | Node(l, x, r) ->
  11.             let spaces = new System.String(' ', n * 4)
  12.             loop (n + 1) r
  13.             printfn "%s%A" spaces x
  14.             loop (n + 1) l
  15.     loop 0 t