From: Jim Pryor
Date: Mon, 13 Dec 2010 04:20:39 +0000 (-0500)
Subject: manip trees tweak
X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=f4457664b4e5de53cff4bd079b8ea561ae66f1f0
manip trees tweak
Signed-off-by: Jim Pryor
---
diff --git a/manipulating_trees_with_monads.mdwn b/manipulating_trees_with_monads.mdwn
index e309faab..0d9e33df 100644
--- a/manipulating_trees_with_monads.mdwn
+++ b/manipulating_trees_with_monads.mdwn
@@ -293,7 +293,7 @@ it through:
Later, we will talk more about controlling the order in which nodes are visited.
One more revealing example before getting down to business: replacing
-`state` everywhere in `tree_monadize` with `list` gives us
+`state` everywhere in `tree_monadize` with `list` lets us do:
# let decider i = if i = 2 then [20; 21] else [i];;
# tree_monadize decider t1;;
@@ -311,11 +311,11 @@ one for each choice of `int`s for its leaves.
Now for the main point. What if we wanted to convert a tree to a list
of leaves?
- type ('a, 'r) continuation = ('a -> 'r) -> 'r;;
+ type ('r,'a) 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 (f : 'a -> ('b, 'r) continuation) (t : 'a tree) : ('b tree, 'r) continuation =
+ let rec tree_monadize (f : 'a -> ('r,'b) continuation) (t : 'a tree) : ('r,'b tree) continuation =
match t with
| Leaf a -> continuation_bind (f a) (fun b -> continuation_unit (Leaf b))
| Node (l, r) -> continuation_bind (tree_monadize f l) (fun l' ->
@@ -368,7 +368,7 @@ interesting functions for the first argument of `tree_monadize`:
It's not immediately obvious to us how to simulate the List monadization of the tree using this technique.
We could simulate the tree annotating example by setting the relevant
-type to `('a, 'state -> 'result) continuation`.
+type to `(store -> 'result, 'a) continuation`.
Andre Filinsky has proposed that the continuation monad is
able to simulate any other monad (Google for "mother of all monads").