ass10 hint tweaks
authorJim Pryor <profjim@jimpryor.net>
Fri, 24 Dec 2010 03:38:42 +0000 (22:38 -0500)
committerJim Pryor <profjim@jimpryor.net>
Fri, 24 Dec 2010 03:38:42 +0000 (22:38 -0500)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
hints/assignment_10_hint_3.mdwn

index 6a442a0..0523d67 100644 (file)
@@ -43,22 +43,26 @@ While we're at it, let's re-define our Reader monad too:
 
 Now instead of annotating leaves with the current store, we'll convert
 the leaves into "askers" that will wait for an environment and return what that
 
 Now instead of annotating leaves with the current store, we'll convert
 the leaves into "askers" that will wait for an environment and return what that
-environment says about the original leaf. At the same time, we'll update the store so that it knows how many leafs of each value have been seen:
+environment says about the original leaf. At the same time, we'll update the store so that it knows how many leafs of each value have been seen.
 
 
+We could proceed in two ways: we could either convert the leafs into "askers" now, and then use `TR.monadize` to conver the tree of askers into a tree-asker (that is, a function from an environment to a tree). Or we could just pass the leaves through unchanged for the moment, and leave the job of converting them to askers to the `TR.monadize` pass. We'll take the second strategy. (This turns out to fit better with what we go on to do later.) Hence, this first pass, using `TS.monadize`, only has to update the store.
 
 
-    let annotater : char -> ((char -> int) -> int) State_custom.m =
-        fun a s -> ((fun e -> e a), update_env s a);;
+
+    let annotater : char -> char State_custom.m =
+        fun a s -> (a, update_env s a);;
 
     let v2 = TS.monadize annotater tree (fun a -> 0);;
 
 
 The seed function here is an environment that by default maps every leaf
 
     let v2 = TS.monadize annotater tree (fun a -> 0);;
 
 
 The seed function here is an environment that by default maps every leaf
-element to 0. In the end, `v2` consists of a pair of a tree of askers, and a
-`char -> int` environment. We can use `TR.monadize` to convert that tree of
-askers into a tree-asker, that is, a function from an environment to a tree. And we then feed it the very environment that was `v2`'s final store:
+element to 0. In the end, `v2` consists of a pair of a tree and a
+`char -> int` environment. We can use `TR.monadize` to convert that tree into a tree-asker, that is, a function from an environment to a tree. And we then feed it the very environment that was `v2`'s final store:
+
+    let asker : char -> int Reader_custom.m =
+      fun (a : char) -> fun (env : char -> int) -> env a;;
 
 
-    let (tree',env) = v2
-    in TR.monadize (fun a -> a) tree' env;;
+    let (tenv) = v2
+    in TR.monadize asker t env;;
 
 
 This gives us a tree of `int`s, where each `int` replaces the original `char`
 
 
 This gives us a tree of `int`s, where each `int` replaces the original `char`