The actual implementation of suspending computations is done using CPS. This paradigm is based on the premise of sending a continuation to a function that is invoked, so that upon completion, the function will invoke the continuation. You can think of continuations as callbacks: whenever a suspending computation invokes another, it will pass a continuation that should be called upon completion or error.
All the heavy lifting is done by the compiler, which transforms all the suspending computations so that they send and receive said continuations—as we will see, this means that the actual signatures of suspending functions are not the same as what we define. On top of that, the suspending computations are transformed into state machines that can save and restore their state, and execute one portion of their code at a time—so whenever they...