type bst = Leaf | Node of int * bst * bst let rec mem x = function | Leaf -> false | Node (y, a, b) when x < y -> mem x a | Node (y, a, b) when y < x -> mem x b | _ -> true let rec insert x = function | Leaf -> Node (x, Leaf, Leaf) | Node (y, a, b) when x < y -> Node (y, (insert x a), b) | Node (y, a, b) when y < x -> Node (y, a, (insert x b)) | Node (y, a, b) -> Node (y, a, b)