
Juliet
By: a guest on
Nov 13th, 2009 | syntax:
OCaml | size: 0.36 KB | hits: 88 | expires: Never
(* Prints a binary tree sideways *)
type 'a tree =
| Node of 'a tree * 'a * 'a tree
| Nil
let rec print t =
let rec loop n = function
| Nil -> ()
| Node(l, x, r) ->
let spaces
= new System
.String(' ', n
* 4)
loop (n + 1) r
printfn "%s%A" spaces x
loop (n + 1) l
loop 0 t