X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=manipulating_trees_with_monads.mdwn;h=73174fd0683343de73a320532867c5fd06228d59;hp=94a88e706b29582ef2f79c5b3a2806ce8a63f002;hb=9544a91e8b91d45196c976caa82be78fad92b832;hpb=1438c72f97b89eebb8524bc51f36918ba4b132b4 diff --git a/manipulating_trees_with_monads.mdwn b/manipulating_trees_with_monads.mdwn index 94a88e70..73174fd0 100644 --- a/manipulating_trees_with_monads.mdwn +++ b/manipulating_trees_with_monads.mdwn @@ -288,7 +288,7 @@ One more revealing example before getting down to business: replacing Unlike the previous cases, instead of turning a tree into a function from some input to a result, this transformer replaces each `int` with -a list of `int`'s. We might also have done this with a Reader monad, though then our environments would need to be of type `int -> int list`. Experiment with what happens if you supply the `tree_monadize` based on the List monad an operation like `fun -> [ i; [2*i; 3*i] ]`. Use small trees for your experiment. +a list of `int`'s. We might also have done this with a Reader monad, though then our environments would need to be of type `int -> int list`. Experiment with what happens if you supply the `tree_monadize` based on the List monad an operation like `fun i -> [2*i; 3*i]`. Use small trees for your experiment. [Why is the argument to `tree_monadize` `int -> int list list` instead of `int -> int list`? Well, as usual, the List monad bind operation @@ -360,8 +360,14 @@ interesting functions for the first argument of `tree_monadize`: # tree_monadize (fun a -> fun k -> 1 + k a) t1 (fun t -> 0);; - : int = 5 -We could simulate the tree state example too, but it would require -generalizing the type of the Continuation monad to +[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;; @@ -525,7 +531,7 @@ quantification. This sentence means (roughly) - &Forall; x . yesterday(saw x) john + 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 @@ -669,7 +675,7 @@ called a that is intended to represent non-deterministic computations as a tree. -What's this have to do with tree\_mondadize? +What's this have to do with tree\_monadize? -------------------------------------------- So we've defined a Tree monad: