type 'a tree = | Node of 'a tree * 'a * 'a tree | Leaf let rec reverse = function | Node (L, x, R) -> Node (reverse R, x, reverse L) | Leaf -> Leaf