Created
August 21, 2017 00:02
-
-
Save kunigami/05b5d5ddf3fff67aec8ad5356c83a9f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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