Skip to content

Instantly share code, notes, and snippets.

@toroidal-code
Created July 29, 2014 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toroidal-code/7c446e4538b5fa2c887a to your computer and use it in GitHub Desktop.
Save toroidal-code/7c446e4538b5fa2c887a to your computer and use it in GitHub Desktop.
type 'a btree =
| Leaf of 'a
| Branch of ('a btree) * ('a btree)
let rec flatten = function
| Leaf(a) -> [a]
| Branch(r, l) -> flatten r @ flatten l
let _ =
Branch(Leaf "a", Branch(Leaf "b", Leaf "c"))
|> flatten
|> List.iter (Printf.printf "%s ")
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment