From 76d2b904ae8af78f5d69fd1580f7f2a2cbfe6095 Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Wed, 1 Dec 2010 00:13:15 -0500 Subject: [PATCH] coroutines tweak Signed-off-by: Jim Pryor --- coroutines_and_aborts.mdwn | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/coroutines_and_aborts.mdwn b/coroutines_and_aborts.mdwn index 31da08f3..8cca9e3f 100644 --- a/coroutines_and_aborts.mdwn +++ b/coroutines_and_aborts.mdwn @@ -583,7 +583,8 @@ When working with continuations, it's easiest in the first place to write them o let foo x = try begin (if x = 1 then 10 - else abort 20) + 100 + else abort 20 + ) + 100 end in (foo 2) + 1;; @@ -593,11 +594,11 @@ into this: in let snapshot = fun box -> let foo_result = box in (foo_result) + 1000 - in let finish_value = fun start -> - let value = start + 100 + in let continue_normally = fun from_value -> + let value = from_value + 100 in snapshot value in - if x = 1 then finish_value 10 + if x = 1 then continue_normally 10 else snapshot 20;; Code written in the latter form is said to be written in **explicit continuation-passing style** or CPS. Later we'll talk about algorithms that mechanically convert an entire program into CPS. -- 2.11.0