Created
January 15, 2017 19:38
-
-
Save alinpopa/c86f5186ef9a0be152d2668f4868c2db to your computer and use it in GitHub Desktop.
This file contains hidden or 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
type 'a tree = | |
| Leaf of 'a | |
| Node of 'a * 'a tree * 'a tree;; | |
let t = Node (6, (Node (7, (Leaf 1), (Leaf 2))), (Node (8, (Leaf 3), (Leaf 4))));; | |
let rec parse t = | |
let rec parse_trees trees acc = match trees with | |
| [] -> acc | |
| (Leaf i) :: tl -> parse_trees tl (i + acc) | |
| (Node (i, l, r)) :: tl -> parse_trees (l :: r :: tl) (acc + i) | |
in | |
parse_trees [t] 0;; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment