Re:Algebraic Effects in Practice with Flix
by alethic on Sunday September 07, 2025 @01:51PM
(#45160507)
The checked exceptions analogy is a good one. Thinking of effect handlers as resumable checked exceptions with some syntactic sugar is very accurate. For someone with a Haskell background, thinking about them as "dependency injection" is also helpful (and these notions are equivalent!) but for the Java heads out there, yeah, resumable checked exceptions provides a really good mental model for what effect handlers are doing with the call stack in the general case.
Re:Algebraic Effects in Practice with Flix
by tome on Monday September 08, 2025 @03:14AM
(#45165429)
What’s the difference between a resumable checked exception and a function call?
Re:Algebraic Effects in Practice with Flix
by saviorand on Monday September 08, 2025 @04:05AM
(#45165741)
Function call always returns, and to one single caller, whereas effects can choose not to "return" at all, resume multiple times, etc
Re:Algebraic Effects in Practice with Flix
by tome on Monday September 08, 2025 @04:45AM
(#45165987)
Right, though the former is just an exception. So what general effect systems provide above and beyond what we already have in most languages is "multiply-resumable" checked exceptions (also known as multi-shot continuations and often provided by "delimited continuations").
At the time I developed my Haskell effect system Bluefin there was a conventional wisdom that "you can't implement coroutines without delimited continuations". That's not true: you can implement coroutines simply as function calls, and that's what Bluefin does.
(The story is not quite as simple as that, because in order for coroutines to communicate you need to be able to pass control between threads with their own stack, but you still don't need multi-shot continuation.)
Re:Algebraic Effects in Practice with Flix
by saviorand on Monday September 08, 2025 @09:17AM
(#45167883)
Good point! You might be interested in reading this article on the topic: https://without.boats/blog/coroutines-and-effects/
Re:Algebraic Effects in Practice with Flix
by tome on Tuesday September 09, 2025 @03:37AM
(#45178726)
Thanks, I did find that interesting. I would say Bluefin is another entry in the static/lexical row, whereas its cousin effectful is in the static/dynamic row (although this may be a slightly different interpretation of the terms than is used in the article).
So in java, you could write two distinct classes implementing the MovieApi interface as you defined it, one of which calls out to the web and one which doesn't, and nothing about the type indicates that difference. If you accidentally used the wrong class, your tests could make a network call and you might never notice, because you would not have tracked that effect.
For someone with a java background, it's really helpful to make the analogy to Checked Exceptions, which let us propagate information about what kind of handler must be required contextually.