+of leaves?
+
+ type ('a, 'r) continuation = ('a -> 'r) -> 'r;;
+ let continuation_unit a = fun k -> k a;;
+ let continuation_bind u f = fun k -> u (fun a -> f a k);;
+
+ let rec tree_monadize (t : 'a tree) (f : 'a -> ('b, 'r) continuation) : ('b tree, 'r) continuation =
+ match t with
+ | Leaf a -> continuation_bind (f a) (fun b -> continuation_unit (Leaf b))
+ | Node (l, r) -> continuation_bind (tree_monadize l f) (fun l' ->
+ continuation_bind (tree_monadize r f) (fun r' ->
+ continuation_unit (Node (l', r'))));;
+
+We use the Continuation monad described above, and insert the
+`continuation` type in the appropriate place in the `tree_monadize` code. Then if we give the `tree_monadize` function an operation that converts `int`s into `'b`-wrapping Continuation monads, it will give us back a way to turn `int tree`s into corresponding `'b tree`-wrapping Continuation monads.
+
+So for example, we compute:
+
+ # tree_monadize t1 (fun a k -> a :: k ()) (fun _ -> []);;
+ - : int list = [2; 3; 5; 7; 11]
+
+We have found a way of collapsing a tree into a list of its
+leaves. Can you trace how this is working? Think first about what the
+operation `fun a k -> a :: k a` does when you apply it to a
+plain `int`, and the continuation `fun _ -> []`. Then given what we've
+said about `tree_monadize`, what should we expect `tree_monadize (fun
+a -> fun k -> a :: k a` to do?
+
+Soon we'll return to the same-fringe problem. Since the
+simple but inefficient way to solve it is to map each tree to a list
+of its leaves, this transformation is on the path to a more efficient
+solution. We'll just have to figure out how to postpone computing the
+tail of the list until it's needed...
+
+The Continuation monad is amazingly flexible; we can use it to
+simulate some of the computations performed above. To see how, first
+note that an interestingly uninteresting thing happens if we use
+`continuation_unit` as our first argument to `tree_monadize`, and then
+apply the result to the identity function:
+
+ # tree_monadize t1 continuation_unit (fun t -> t);;
+ - : int tree =
+ Node (Node (Leaf 2, Leaf 3), Node (Leaf 5, Node (Leaf 7, Leaf 11)))
+
+That is, nothing happens. But we can begin to substitute more
+interesting functions for the first argument of `tree_monadize`:
+
+ (* Simulating the tree reader: distributing a operation over the leaves *)
+ # tree_monadize t1 (fun a -> fun k -> k (square a)) (fun t -> t);;
+ - : int tree =
+ Node (Node (Leaf 4, Leaf 9), Node (Leaf 25, Node (Leaf 49, Leaf 121)))
+
+ (* Simulating the int list tree list *)
+ # tree_monadize t1 (fun a -> fun k -> k [a; square a]) (fun t -> t);;
+ - : int list tree =
+ Node
+ (Node (Leaf [2; 4], Leaf [3; 9]),
+ Node (Leaf [5; 25], Node (Leaf [7; 49], Leaf [11; 121])))
+
+ (* Counting leaves *)
+ # tree_monadize t1 (fun a -> fun k -> 1 + k a) (fun t -> 0);;
+ - : int = 5
+
+[To be fixed: exactly which kind of monad each of these computations simulates.]
+
+We could simulate the tree state example too by setting the relevant
+type to `('a, 'state -> 'result) continuation`.
+In fact, Andre Filinsky has suggested that the continuation monad is
+able to simulate any other monad (Google for "mother of all monads").
+
+We would eventually want to generalize the continuation type to
+
+ type ('a, 'b, 'c) continuation = ('a -> 'b) -> 'c;;
+
+If you want to see how to parameterize the definition of the `tree_monadize` function, so that you don't have to keep rewriting it for each new monad, see [this code](/code/tree_monadize.ml).
+
+The idea of using continuations to characterize natural language meaning
+------------------------------------------------------------------------
+
+We might a philosopher or a linguist be interested in continuations,
+especially if efficiency of computation is usually not an issue?
+Well, the application of continuations to the same-fringe problem
+shows that continuations can manage order of evaluation in a
+well-controlled manner. In a series of papers, one of us (Barker) and
+Ken Shan have argued that a number of phenomena in natural langauge
+semantics are sensitive to the order of evaluation. We can't
+reproduce all of the intricate arguments here, but we can give a sense
+of how the analyses use continuations to achieve an analysis of
+natural language meaning.
+
+**Quantification and default quantifier scope construal**.
+
+We saw in the copy-string example and in the same-fringe example that
+local properties of a tree (whether a character is `S` or not, which
+integer occurs at some leaf position) can control global properties of
+the computation (whether the preceeding string is copied or not,
+whether the computation halts or proceeds). Local control of
+surrounding context is a reasonable description of in-situ
+quantification.
+
+ (1) John saw everyone yesterday.
+
+This sentence means (roughly)
+
+ forall x . yesterday(saw x) john
+
+That is, the quantifier *everyone* contributes a variable in the
+direct object position, and a universal quantifier that takes scope
+over the whole sentence. If we have a lexical meaning function like
+the following: