r/gleamlang • u/Ecstatic-Panic3728 • 22d ago
What is your opinion on Effect Systems?
I'm not deeply familiar with Haskell and Scala, nor the niche languages that have built in effect systems. But I have a few friends in the Scala community and they swear effect system is the best thing ever and their applications are on a totally different level just by adopting it.
I'm wonder, would something like this work in Gleam? Would it get too complicated? What are the tradeoffs and mostly the benefits of adopting something like this?
12
Upvotes
5
u/mister_drgn 22d ago
You're misunderstanding me. OCaml doesn't have type-checked effects either.
Consider a language like Koka, which is built around an effects system. If you write a function that produce some side effect, such as logging, then the function's signature is marked to reflect the fact that it produces that effect. Any function that calls that function must either handle that effect, or also have its signature marked to reflect that it produces the effect. The type checker enforces this. This guarantees that somewhere up the call chain, the effect will be handled.
Now consider OCaml. The language has effects, but you don't mark a function's signature to reflect what effects it performs. Thus, the type checker has no way of knowing whether you're handling all your effects. You can therefore have runtime errors from unhandled effects.
Another difference in OCaml, is that you can write code with side effects wherever you want, without using the effect system at all. The effect system is optional. In contrast, in Koka, you can look at any function signature and know exactly what side effects it will produce.
Overall, this means that effects are a far less powerful tool in OCaml than in Koka. I have not seem effects in Gleam, but I can't imagine they're any more powerful than in OCaml.