From 6908f7726018f0d85c9c950033ffa77033ab24c1 Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Tue, 14 Dec 2010 05:35:11 -0500 Subject: [PATCH 1/1] cps tweaks Signed-off-by: Jim Pryor --- cps_and_continuation_operators.mdwn | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cps_and_continuation_operators.mdwn b/cps_and_continuation_operators.mdwn index 258f7227..d1a85cf8 100644 --- a/cps_and_continuation_operators.mdwn +++ b/cps_and_continuation_operators.mdwn @@ -481,7 +481,7 @@ To demonstrate the different adding order between Examples 4 and 5, we use `::` 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) + in run0 w);; - : int list = [1000; 10; 100; 1] @@ -493,7 +493,23 @@ Example 6: (app (reset (app2 (op2 plus) (var ten) (shift (\k. (var k))))) (var one)) - (* not sure if this example can be typed as-is in OCaml. We may need a sum-type *) + (* not sure if this example can be typed as-is in OCaml... this is the best I an do at the moment... *) + + # type 'x either = Left of (int -> ('x,'x either) Continuation_monad.m) | Right of int;; + # Continuation_monad.(let v = reset ( + shift (fun k -> unit (Left k)) >>= fun i -> unit (Right (10+i)) + ) in let w = v >>= fun (Left k) -> + k 1 >>= fun (Right i) -> + unit (100+i) + in run0 w);; + - : int = 111 + + Example 7: -- 2.11.0