Skip to content

Instantly share code, notes, and snippets.

@toroidal-code
Created July 29, 2014 15:08
Show Gist options
  • Select an option

  • Save toroidal-code/7c446e4538b5fa2c887a to your computer and use it in GitHub Desktop.

Select an option

Save toroidal-code/7c446e4538b5fa2c887a to your computer and use it in GitHub Desktop.

Revisions

  1. toroidal-code created this gist Jul 29, 2014.
    15 changes: 15 additions & 0 deletions btree.ml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    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 ")
    ;