If we have a given predicate p :: [Bool] -> Bool that take an infinite list as parameter and return True or False based on some unknown conditions, and we have no idea what this predicate is.
Can we work out a function f :: ([Bool] -> Bool) -> [Bool] that take such predicate and return an infinite list l where p l == True, assuming that the predicate is satisfiable.
You can think of an infinite list
[Bool]as being a binary number with the least significant bit first:and so on to infinity.
So if you construct a function like this:
then you can write
Will this work for every predicate
p? Well, if we restrict ourselves to total functions then thepmust inspect a finite prefix of its argument, and if any finite prefix is acceptable then that prefix must be reached eventually.If
pis not total but can returnTruefor at least one argument (e.g. the predicate "argument contains at least oneTrue"), then this problem cannot be solved as written because we can't know ifp xwill ever terminate. However ifpcould be expressed as a state machine:then you could enumerate every possible input by recursively applying
TrueandFalseto the output of the previous step in a breadth-first search until you findLeft True.