Essentially find performs an exhaustive search by
depth-first backtracking. It’s impressive that find
can be programmed totally and without inspecting the source code of
its argument f, even though there are an uncountable
number of infinite bit sequences. Escardó makes find
go faster using lazy evaluation in Haskell: his
find_iii uses an infinite sequence of lazily evaluated
bits. But it wasn’t clear to me what role lazy evaluation plays in
find_vii, which is his final, fastest version of
find.

Contrary to
what some people inexplicably seem to think, I don’t know from
category theory, and I haven’t read Escardó’s paper or
code at
LICS 2007. Still, I suspect the/an essence of find_vii
is to replace an infinite sequence of lazily evaluated bits by a
lazily evaluated binary tree of bits. To confirm this hypothesis, I
reimplemented his algorithm as follows. You can download
this post as a program.

module Exhaustive where

We represent a function from natural numbers to some type
a by an infinite binary tree whose nodes are labeled
by a. To be more precise: the root node stores what
the function returns at 0; the left branch stores the return values
at positive odd integers, and the right branch stores the return
values at positive even integers.