Package-level declarations
Types
Generator output: yieldValue performs a Yield, and the generator handler reifies the continuation as data. The program becomes a Generator value: Generator.Finished with the result, or Generator.Yielded holding the value and the rest of the program as a callable continuation. The driver decides when, and whether, to resume; in between, the suspended program is just data:
Nondeterminism: multi-shot continuations. choose suspends on a Choose effect, and the collectAll handler resumes the same captured continuation once per option and concatenates the results. Resuming a continuation more than once is impossible with one-shot suspend coroutines; it works here because the continuation is an immutable value that can be replayed. guard prunes a branch, orElse is a binary choice, and msplit, once and ifte give committed choice: the first answer with the rest of the search as a program, the first answer only, and a soft cut.
A single mutable cell: read with getState, written with putState and modifyState, handled by runState or runStateWithFinal, and scoped by transactional.
Functions
Run this program as a generator: every Emit.Yield pauses it as a Generator.Yielded holding the rest of the program, and completion gives Generator.Finished. The yielded type is erased, so one generator() should see one yielded type T.
Terminal suspend runner, available on every target: runs every IO thunk and returns the program's final value. Call it from a coroutine, after all other handlers, so that only IO effects remain; any other effect left fails naming itself. Thunk resumptions re-enter through the calling context's ContinuationInterceptor, so under a coroutine dispatcher interpretation stays on that dispatcher; in an interceptor-free context (a plain suspend main) the first thunk that resumes on another thread moves the rest of interpretation there, which is what ioBlocking() avoids on the JVM.
JVM-only blocking edge runner for interceptor-free contexts (a plain main, a thread you own): runs every IO thunk and returns the final value, blocking the caller while a thunk is suspended. Every interpretation step stays on the calling thread; a thunk may hop threads internally, but its result is handed back before interpretation continues, so handler state needs no synchronization. Apply it after all other handlers, so that only IO effects remain; any other effect left fails naming itself.
Split the search: null if it has no answers, otherwise the first answer paired with the rest of the search as a replayable program. The rest is built in O(1): the first answer's own rest, then one choice over the options not yet tried — each of those is resumed only if the rest is run and reaches it. Splitting a rest again nests one more msplit interpreter around the search, so enumerating by repeated splits costs stack and time proportional to the number of prior splits — a bound set by handler nesting, not by the number of options.
Recover from a failure: on Failure.Raise, the rest of the failed program is abandoned (there is nothing to resume into) and fallback replaces it. A failure raised inside fallback is not caught here — it propagates to the next outer recover or attempt.
Run this program as a transaction: its State effects hit a local copy of the state, seeded by reading the downstream handler, and the final local state is committed downstream only if the program completes. If it fails part-way (e.g. a Failure.Raise handled outside), the commit is part of the abandoned continuation and never runs — the downstream state stays untouched. Built from flatMap alone, so it is safe under a multi-shot handler such as collectAll: each branch reads, runs and commits independently.