6 ms·
A coroutine is a computation that can `yield`, suspending itself and passing control back up to the caller. It can then be resumed at the caller's leisure. An
by alephaleph 2y ago
A coroutine is a computation that can `yield`, suspending itself and passing control back up to the caller. It can then be resumed at the caller's leisure.
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.
- galaxyLogic 2y ago> An function with an effect (in this sense) is a function which can ask a handler to `perform` some effect for it. 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?
- mrkeen 2y agoBy making effects explicit, you reap the benefit of being able to write non-effectful code. 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!
- reuben364 2y agoa function will return to it's call site (or diverge), a handler doesn't necessarily have to resume from where it was invoked. There is also (sort of) dynamic scoping, where you don't have to thread the handlers through calls.