From 399197e0af7c4b80f326be60ff2c0caae74b3687 Mon Sep 17 00:00:00 2001
From: Jim Pryor
Date: Thu, 23 Dec 2010 22:29:22 -0500
Subject: [PATCH] ass10 hint tweaks
Signed-off-by: Jim Pryor
---
hints/assignment_10_hint_2.mdwn | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/hints/assignment_10_hint_2.mdwn b/hints/assignment_10_hint_2.mdwn
index 83be68fb..9bb1cd66 100644
--- a/hints/assignment_10_hint_2.mdwn
+++ b/hints/assignment_10_hint_2.mdwn
@@ -12,11 +12,11 @@ But I found it easier to work out the solution using the simpler "tree\_monadize
It makes debugging easier if we work with a tree whose starting leaf
-elements are differently types than the tree we aim to finish with. So:
+elements are differently typed than the tree we aim to finish with. So:
let tree = Node(Leaf '1', Node(Leaf '2', Node(Leaf '3', Leaf '1')));;
-Now, we already know how to count the leaves using a continuation monad
+Now, we already know how to count the leaves using a Continuation monad
in tree shape:
let v0 = TreeCont.monadize (fun a k -> 1 + k a) tree (fun t -> 0);;
@@ -28,9 +28,9 @@ of each value, rather than how many leaves in total:
let update_env e x = fun y -> (if x = y then 1 else 0) + e y;;
- let v1 = TreeCont.monadize (fun a k e ->
- let e_prev = k a e
- in update_env e_prev a
+ let v1 = TreeCont.monadize (fun a k e0 ->
+ let ecur = k a e0
+ in update_env ecur a
) tree (fun t e -> e) (fun a -> 0);;
(* now
@@ -39,7 +39,7 @@ of each value, rather than how many leaves in total:
v1 '2' ~~> 1
*)
-How does this work? Our distributed function (fun a k e -> ...) takes a leaf element a and a continuation k, which maps leaf elements and environments e to new environments.
+How does this work? Our distributed function `fun a k e -> ...` takes a leaf element `a` and a continuation `k`, which maps leaf elements and environments `e0` to new environments `ecur`. It gives back a function from `e0` to an updated version of `ecur`.
Our seed function here is the initial continuation. Instead of taking a leaf element and an env, it takes a tree of such elements and an env. In general, wherever the distributed function takes `'a`s, the seed function takes `'a tree`s.
--
2.11.0