Adding Algebraic Effects to Gleam #1740
Replies: 4 comments 8 replies
-
Super cool! I am not yet convinced that effect handlers are simple enough of an API to fit in Gleam. We need to think carefully about ease of use. Is effects tracking without handlers useful? What Erlang code would the above example compile to? |
Beta Was this translation helpful? Give feedback.
-
Effect tracking and effects+handlers (algebraic effects) are actually orthogonal features. The value proposition of algebraic effects is that you can abstract away the details of an effect, with client code controlling how those effects are performed. As @CrowdHailer's example shows, you could provide an abstract The value proposition of effect tracking is security, as I believe you're familiar with. AFAICT the two features are conflated because almost every language with algebraic effects has effect tracking as well - OCaml is a notable counterexample, although this may have changed by now. To directly answer the question: Yes effect tracking without handlers is useful, but for a completely different reason than algebraic effects are useful. We need to clarify exactly which feature we want - or perhaps both! - before going forward and discussing the concrete details.
Typically languages with algebraic effects have to CPS-transform the program. I'm unfamiliar with the exact pros and cons of this approach, but it would at least obfuscate the Erlang output. I've been told readability of the output code is a desired feature? However, we could probably use Erlang's native concurrency primitives instead! The body of a
This would keep the structure of the Erlang output very similar to the original code - handlers and
Right, they can get quite complicated. My two cents: Discarding effect tracking would decrease the learning curve of algebraic effects significantly. |
Beta Was this translation helpful? Give feedback.
-
One benefit of effects tracking could be to improve compiler strictness: pub fn main() -> Result(Int, Nil) {
let x = 1;
// Compiler could reject this code block:
// because it is never bound to a variable or returned from the block
// ...nor did it trigger any side effect
{
try b = Error(Nil);
b
}
Ok(x)
} p.s.: While I am far from being even an amateur on this topic, it also seems that effects of arbitrary blocks must thus be tracked and/or settable by the programmer. |
Beta Was this translation helpful? Give feedback.
-
I've recorded a discussion on how to design effect types. |
Beta Was this translation helpful? Give feedback.
-
There are a lot of reasons to add Effect Tracking to a language like Gleam, and probably plenty of good reasons not too.
Here is a good tutorial on effect types. This paper is good for the examples section. https://www.eff-lang.org/handlers-tutorial.pdf
A short discussion was previously had here gleam-lang/suggestions#49
I have been experimenting with effect types and here is one potential syntax
Simple Log
Gather all logs in a pure fashion
Beta Was this translation helpful? Give feedback.
All reactions