in let outer_snapshot = fun box ->
let foo_result = box
in (foo_result) + 1000
- in let continue_foo_normally = fun from_value ->
+ in let continue_foo_snapshot = fun from_value ->
let value = from_value + 100
in outer_snapshot value
in (* start of foo_applied_to_x *)
- if x = 1 then continue_foo_normally 10
+ if x = 1 then continue_foo_snapshot 10
else outer_snapshot 20;;
And this is indeed what is happening, at a fundamental level, when you use an expression like `abort 20`. Here is the original code for comparison:
in let outer_snapshot = fun box ->
let foo_result = box
in (foo_result) + 1000
- in let continue_foo_normally = fun from_value ->
+ in let continue_foo_snapshot = fun from_value ->
let value = from_value + 100
in outer_snapshot value
in (* start of foo_applied_to_x *)
- if x = 1 then continue_foo_normally 10
+ if x = 1 then continue_foo_snapshot 10
else outer_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.
let outer_snapshot = fun box ->
let foo_result = box
in (foo_result) + 1000
- in let continue_foo_normally = fun from_value ->
+ in let continue_foo_snapshot = fun from_value ->
let value = from_value + 100
in outer_snapshot value
- in if x = 1 then continue_foo_normally 10
+ in if x = 1 then continue_foo_snapshot 10
else outer_snapshot 20;;
# let test_shift x =