6 ms·
One important difference between algebraic effects and resumable exceptions is that with algebraic effects, the handler gets access to a reified version of the
by curryhoward 6y ago
One important difference between algebraic effects and resumable exceptions is that with algebraic effects, the handler gets access to a reified version of the current continuation. The handler can then use that continuation to resume an arbitrary number of times, or not at all. For example, the handler could resume once for each item in a list, essentially using the continuation to map the list to a new list. The handler can even return the continuation to be invoked later, after the handler has finished. This is very unlike the restricted kind of resumable exceptions that you see in hardware.
Algebraic effects are a structured form of delimited continuations, for people who know about that concept. They give you nearly the full power of monads.
- dan-robertson 6y agoI feel like the reification (or in particular the performance characteristics thereof) are more important than the repeatability. I think delimited continuations are a much more accurate description of what algebraic effects do. There are implementations of delimited continuations in Common Lisp based on the condition system but if you have too many continuations (or if you switch between them too often) you will blow up the stack. Other implementations (of async rather than continuations) use macros to translate source to continuation passing style and then rely on the compiler being clever, which sbcl is ok at. Note that you can implement resumable exceptions so long as you have a reliable way to do nonlocal transfers of control (eg return-from or go in CL; or some kind of exception which can only be caught by a try that you write and not by someone else’s, though the finally would still run), and some dynamically scoped list of first clsss functions. Implementing delimited continuations is much more involved.