blob: 2e58e033c4b36a93c7baddb7b2c4fa79da78a3d5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
|
(* Binary tree with leaves carrying an integer. *)
type Tree = Leaf of int | Node of Tree * Tree
let rec existsLeaf test tree =
match tree with
| Leaf v -> test v
| Node (left, right) ->
existsLeaf test left
|| existsLeaf test right
let hasEvenLeaf tree =
existsLeaf (fun n -> n % 2 = 0) tree
|