A coroutine is a computation that suspends and later resumes by cooperatively transferring control to another computation. In an IO program, execution becomes explicit data: Suspend requests an effect, while FlatMap requests a subroutine and continuation. section 13.3.1
Instead of relying on the JVM call stack, unsafeRun repeatedly interprets one request, invokes the suspended computation, and receives the next request. This interpreter drives the program through successive suspensions. section 13.3.1
An IO coroutine
An IO value such as printLine("Still going...").forever builds repeated suspended effects. Its nested FlatMap structure returns control after each effect, allowing unsafeRun to continue the computation without growing the call stack. section 13.3.1
The same interaction pattern generalizes:
- Free structures and their interpreters can be viewed as interacting coroutines; the type F defines the allowed interaction protocol. section 13.4.1
- A tail-recursive interpreter can use trampolining to return repeatedly to one loop and eliminate stack growth. section 13.3.1







