Signed-off-by: Jim Pryor <profjim@jimpryor.net>
let foo x =
try begin
(if x = 1 then 10
- else abort 20) + 100
+ else abort 20
+ ) + 100
end
in (foo 2) + 1;;
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.