An function with an effect (in this sense) is a function which can ask a handler to `perform` some effect for it. This suspends the function and passes control to whichever handler is in scope for that call, allowing that handler to resume the function at its leisure.
I suspect that you're misunderstanding what is meant by effect, because despite buzz about them and backend support for them in OCaml 5, they aren't yet implemented with syntax and type-level support in any mainstream languages I'm aware of.
Why does it need to ask a "handler" to do something, why can't it just call a function that does the "action" for it?
Depending on what your language tracked as an effect, you could make your business-logic always terminate, or perform no allocations, if you had effects for Mutation/GeneralRecursion/Allocation.
But no, I certainly don't understand the function->handler control flow here. It has to be handler->function, otherwise you've got two handlers!
Effects require 1) well-defined control flow (think of IO; you need to know in what order output occurs) and 2) manipulation of control flow (think of error handling or concurrency).
We can model effects as a back-and-forth between effect handlers, which carry out effects, and the user program. The user program passes control to the effect handler to carry out some effect, and the effect handler passes control back to the user program (potentially a different part of the user program; think error handling) when the effect has been performed. Continuations give complete control over control flow, so in their full generality effects require continuations (or some equivalent like monads). Coroutines are a slightly stilted form of continuations, that you can model much, but not all, control flow with.
There are obvious implementation differences but I'm not sure it makes any difference here, in both cases you can return to the same execution state multiple times.
A continuation is immutable in that way, so it is either an error to invoke it multiple times, or else it will always resume at the same place. Implementing coroutines in terms of continuations would mean capturing a new continuation each time you yield.
This can in fact be emulated with a coroutine generator and some fancy footwork, but it's a subtly different primitive.
Functions and lists are technically isomorphic, you just replace the function with a list of (domain, codomain) pairs and function invocation then becomes list lookup. This is basically the set theory definition of a function. So yes, this comparison to the article is apt, the article is saying that you can encode effects via coroutines.
I like the way is presented here: https://mikeinnes.io/posts/transducers/
The main gist is that "effect" allows you to define your own "except" of "try/except/finally"
I wrote "Feels like comparing Lists with functions" for a more general audience, but in my mind I was thinking:
- Effects are Monads
- Continuations are one particular Monad [1]
- Coroutines are probably similar?
- I would use monadic effects to allow/disallow a function from making use of Coroutines.
- If my effect system *itself* uses Coroutines how do I use the effect system to forbid Coroutines?
[1] https://hackage.haskell.org/package/mtl-2.3.1/docs/Control-M...