Skip to content

Instantly share code, notes, and snippets.

@kunigami
Created August 21, 2017 00:02
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 kunigami/05b5d5ddf3fff67aec8ad5356c83a9f9 to your computer and use it in GitHub Desktop.
Save kunigami/05b5d5ddf3fff67aec8ad5356c83a9f9 to your computer and use it in GitHub Desktop.
let size tree = match tree with
| Leaf _ -> 1
| Node ({size}) -> size
;;
let link tree1 tree2 = Node {
size = (size tree1) + (size tree2);
left = tree1;
right = tree2;
};;
let rec pushTree tree digits = match digits with
| [] -> [One tree]
| Zero :: restDigits -> (One tree) :: restDigits
| (One currentTree) :: restDigits ->
Zero :: (pushTree (link tree currentTree) restDigits)
;;
let push element digits = pushTree (Leaf element) digits;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment