X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=week11.mdwn;h=466c1e5bcfbf42df1e9579e0d50e53d353254e4c;hp=d1bceb03184b181859516317b4a57cfbcb5c31bb;hb=ce6130150336db0e8cd1a6dd538bff45c9af7c6c;hpb=a2a8ae846e123efa055406e6518d3f32baf3fd84;ds=sidebyside
diff --git a/week11.mdwn b/week11.mdwn
index d1bceb03..466c1e5b 100644
--- a/week11.mdwn
+++ b/week11.mdwn
@@ -887,9 +887,15 @@ describing how to finish building the list. We'll write a new
function, `tc` (for task with continuations), that will take an input
list (not a zipper!) and a continuation and return a processed list.
The structure and the behavior will follow that of `tz` above, with
-some small but interesting differences:
+some small but interesting differences. We've included the orginal
+`tz` to facilitate detailed comparison:
+let rec tz (z:char list_zipper) =
+ match z with (unzipped, []) -> List.rev(unzipped) (* Done! *)
+ | (unzipped, 'S'::zipped) -> tz ((List.append unzipped unzipped), zipped)
+ | (unzipped, target::zipped) -> tz (target::unzipped, zipped);; (* Pull zipper *)
+
let rec tc (l: char list) (c: (char list) -> (char list)) =
match l with [] -> List.rev (c [])
| 'S'::zipped -> tc zipped (fun x -> c (c x))
@@ -927,18 +933,23 @@ the recipe to produce the desired result (which is the same list,
A good way to test your understanding is to figure out what the
continuation function `c` must be at the point in the computation when
-`tc` is called with
+`tc` is called with the first argument `"Sd"`. Two choices: is it
+`fun x -> a::b::x`, or it is `fun x -> b::a::x`?
+The way to see if you're right is to execute the following
+command and see what happens:
+
+ tc ['S'; 'd'] (fun x -> 'a'::'b'::x);;
There are a number of interesting directions we can go with this task.
The task was chosen because the computation can be viewed as a
simplified picture of a computation using continuations, where `'S'`
plays the role of a control operator with some similarities to what is
-often called `shift`. &sset; &integral; In the analogy, the list
-portrays a string of functional applications, where `[f1; f2; f3; x]`
-represents `f1(f2(f3 x))`. The limitation of the analogy is that it
-is only possible to represent computations in which the applications
-are always right-branching, i.e., the computation `((f1 f2) f3) x`
-cannot be directly represented.
+often called `shift`. In the analogy, the list portrays a string of
+functional applications, where `[f1; f2; f3; x]` represents `f1(f2(f3
+x))`. The limitation of the analogy is that it is only possible to
+represent computations in which the applications are always
+right-branching, i.e., the computation `((f1 f2) f3) x` cannot be
+directly represented.
One possibile development is that we could add a special symbol `'#'`,
and then the task would be to copy from the target `'S'` only back to