From: Jim Pryor Date: Tue, 14 Dec 2010 09:22:40 +0000 (-0500) Subject: cps tweaks X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=9a23d7fc448e48268a7b60ce9ff3e55222cd833a cps tweaks Signed-off-by: Jim Pryor --- diff --git a/cps_and_continuation_operators.mdwn b/cps_and_continuation_operators.mdwn index 4fcf5e02..258f7227 100644 --- a/cps_and_continuation_operators.mdwn +++ b/cps_and_continuation_operators.mdwn @@ -401,41 +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) + abort 11 >>= fun i -> + unit (100+i) ) >>= fun j -> - unit (100+j)));; - - : int = 101 + unit (1000+j)));; + - : int = 1011 Example 3: @@ -478,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) @@ -504,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)