BST? , :
- (
BST) , node - (
BST) , node
A fold - : , ( Leaf) ( Node ).
A Leaf BST, . Node , . , . fold:
, :
type is_bst = bool
type 'a interval = 'a * 'a
, :
let leaf_bst (a : 'a) : is_bst * 'a interval = (true, (a, a))
Node a, node, , (lih l eft i nduction h ypothesis) . , BST , (b1 && b2) , . , , (lb1, ub2).
let node_bst (a : 'a) (lih : is_bst * 'a interval) (rih : is_bst * 'a interval) =
let (b1, (lb1, ub1)) = lih in
let (b2, (lb2, ub2)) = rih in
(b1 && b2 && ub1 < a && a <= lb2, (lb1, ub2))
, , , BST, fold_tree leaf_bst node_bst .
let bst (t : 'a tree) : bool =
fst (fold_tree leaf_bst node_bst t)