Skip to content

Instantly share code, notes, and snippets.

@stakx
Created July 17, 2010 17:47
Show Gist options
  • Save stakx/479694 to your computer and use it in GitHub Desktop.
Save stakx/479694 to your computer and use it in GitHub Desktop.
// Dummy definition of the binary tree:
type Deque<'a> =
| Empty
| Node of Deque<'a> * 'a * Deque<'a>
// Traverse from "front" (L) to "back" (R):
let rec items D =
match D with
| Empty -> Seq.empty
| Node(L,x,R) -> seq {
yield! items(L)
yield x
yield! items(R)
}
// Test tree; this reflects the insertion of elements 1, 2, 3 (in this order) at the front:
let T = Node( Node(Empty, 3, Empty),
2,
Node(Empty, 1, Empty) )
// The following would output something like, "val it : seq<int> = seq [3; 2; 1]"
let ts = items T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment