lists-to-contin tweaks
[lambda.git] / from_lists_to_continuations.mdwn
index be7e17f..8c84dfb 100644 (file)
@@ -75,9 +75,10 @@ entire list has been unzipped (and so the zipped half of the zipper is empty).
        type 'a list_zipper = ('a list) * ('a list);;
        
        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 *)
+           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 *)
        
        # tz ([], ['a'; 'b'; 'S'; 'd']);;
        - : char list = ['a'; 'b'; 'a'; 'b'; 'd']
@@ -152,23 +153,23 @@ The structure and the behavior will follow that of `tz` above, with
 some small but interesting differences.  We've included the orginal
 `tz` to facilitate detailed comparison:
 
-<pre>
-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))
-             | target::zipped -> tc zipped (fun x -> target::(c x));;
-
-# tc ['a'; 'b'; 'S'; 'd'] (fun x -> x);;
-- : char list = ['a'; 'b'; 'a'; 'b']
-
-# tc ['a'; 'S'; 'b'; 'S'] (fun x -> x);;
-- : char list = ['a'; 'a'; 'b'; 'a'; 'a'; 'b']
-</pre>
+       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))
+           | target::zipped -> tc zipped (fun x -> target::(c x));;
+       
+       # tc ['a'; 'b'; 'S'; 'd'] (fun x -> x);;
+       - : char list = ['a'; 'b'; 'a'; 'b']
+       
+       # tc ['a'; 'S'; 'b'; 'S'] (fun x -> x);;
+       - : char list = ['a'; 'a'; 'b'; 'a'; 'a'; 'b']
 
 To emphasize the parallel, I've re-used the names `zipped` and
 `target`.  The trace of the procedure will show that these variables