Want more features on Pastebin? Sign Up, it's FREE!
Guest

Juliet

By: a guest on Nov 13th, 2009  |  syntax: OCaml  |  size: 0.36 KB  |  views: 97  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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
clone this paste RAW Paste Data