cps tweaks
[lambda.git] / cps_and_continuation_operators.mdwn
index 3b0dda7..258f722 100644 (file)
@@ -401,40 +401,41 @@ Here are some more examples of using delimited control operators. We present eac
 
 Example 1:
 
-       ; (+ 100 (+ 10 (abort 1))) ~~> 1
+       ; (+ 1000 (+ 100 (abort 11))) ~~> 11
        
-       app2 (op2 plus) (var hundred)
-         (app2 (op2 plus) (var ten) (abort (var one)))
+       app2 (op2 plus) (var thousand)
+         (app2 (op2 plus) (var hundred) (abort (var eleven)))
        
        # Continuation_monad.(run0(
-           abort 1 >>= fun i ->
-           unit (10+i) >>= fun j ->
-           unit (100+j)));;
-       - : int = 1
+           abort 11 >>= fun i ->
+           unit (100+i) >>= fun j ->
+           unit (1000+j)));;
+       - : int = 11
 
 When no `reset` is specified, there's understood to be an implicit one surrounding the entire computation (but unlike in the case of `callcc`, you still can't capture up to *and including* the end of the computation). So it makes no difference if we say instead:
 
        # Continuation_monad.(run0(
            reset (
-             abort 1 >>= fun i ->
-             unit (10+i) >>= fun j ->
-             unit (100+j))));;
-       - : int = 1
+             abort 11 >>= fun i ->
+             unit (100+i) >>= fun j ->
+             unit (1000+j))));;
+       - : int = 11
 
 
 Example 2:
        
-       ; (+ 100 (reset (+ 10 (abort 1)))) ~~> 101
+       ; (+ 1000 (reset (+ 100 (abort 11)))) ~~> 1011
        
-       app2 (op2 plus) (var hundred)
-         (reset (app2 (op2 plus) (var ten) (abort (var one))))
+       app2 (op2 plus) (var thousand)
+         (reset (app2 (op2 plus) (var hundred) (abort (var eleven))))
        
        # Continuation_monad.(run0(
            reset (
-             abort 1 >>= fun i ->
-             unit (10+i)) >>= fun j ->
-              unit (100+j)));;
-       - : int = 101
+             abort 11 >>= fun i ->
+             unit (100+i)
+           ) >>= fun j ->
+           unit (1000+j)));;
+       - : int = 1011
 
 Example 3:
 
@@ -477,7 +478,7 @@ To demonstrate the different adding order between Examples 4 and 5, we use `::`
            (shift (\k. ((op2 plus) (var ten) (app (var k) (var one)))))))
        
        Continuation_monad.(let v = reset (
-         let u = shift (fun k -> k [1] >>= fun x -> unit (10 :: x))
+           let u = shift (fun k -> k [1] >>= fun x -> unit (10 :: x))
            in u >>= fun x -> unit (100 :: x)
          ) in let w = v >>= fun x -> unit (1000 :: x)
          in run0  w)
@@ -503,7 +504,7 @@ Example 7:
            (shift (\k. app (var k) (app (var k) (var one))))))
        
        Continuation_monad.(let v = reset (
-         let u = shift (fun k -> k 1 >>= fun x -> k x)
+           let u = shift (fun k -> k 1 >>= fun x -> k x)
            in u >>= fun x -> unit (10 + x)
          ) in let w = v >>= fun x -> unit (100 + x)
          in run0 w)