the code I teach now
const iterate = f => z => pair(z, () => iterate(f)(f(z))); const integers = iterate(n => n+1)(0);
const iterate = f => z => pair(z, () => iterate(f)(f(z))); const integers = iterate(n => n+1)(0);
70 Observe that, for any two streams, there is in general more than one acceptable order of interleaving. Thus, technically, ‘merge’ is a relation rather than a function—the answer is not a deterministic function of the inputs. We already mentioned (footnote 38 ) that nondeterminism is essential when dealing with concurrency. The merge relation illustrates the same essential nondeterminism, from the functional perspective.
71 The object model approximates the world by dividing it into separate pieces. The functional model does not modularize along object boundaries. The object model is useful when the unshared state of the ‘objects’ is much larger than the state that they share. An example of a place where the object viewpoint fails is quantum mechanics, where thinking of things as individual particles leads to paradoxes and confusions. Unifying the object view with the functional view may have little to do with programming, but rather with fundamental epistemological issues.