let find (stack: 'data stack) (func: 'data -> int) : 'data =
if stack.size = 0 then
raise Not_found
else
(* binary search on array *)
let rec exists' (left: int) (right : int) =
let mid =
(left + right) / 2
in
let cmp =
func stack.stack.(mid)
in
if cmp = 0 then
stack.stack.(mid)
else if left >= right then
raise Not_found
else if cmp < 0 then
exists' left (mid - 1)
else (*if cmp > 0 then*)
exists' (mid + 1) right
in
exists' 0 (stack.size - 1)