3 ms·
> You can think of each point in the code as having a continuation which is what to do next immediately after it. You can think of it as anything you like. As
by sago 11y ago
> You can think of each point in the code as having a continuation which is what to do next immediately after it.
You can think of it as anything you like. As a plate of burritos, even (to borrow the monads cliche). But why would you want to spend so many hundreds of words setting up an imaginary world like that?
When you're running a program, the computer keeps track of where in the program you are. A continuation is a data structure representing that point. You create a continuation by asking for the data structure representing the current point. Then you can resume it later, which replaces the current point with the point stored in that data structure.
I fail to see why you'd want to make this more complex.
My approach is not a 'how to explain it', it is what it actually is.
CPS definitely has its places, in functional languages and in compilers. But tying the idea of a continuation to it is needlessly complex, niche, and purely a historical quirk. It gives the impression that they're intrinsically related, but they're not. As you've demonstrated, you have to 'imagine' all kinds of stuff to make that view of continuations fit with regular code.