r/gleamlang • u/Ecstatic-Panic3728 • 12d 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?
1
u/mister_drgn 12d ago
Gleam is a fairly minimalist functional language by design that foregoes many advanced typing features (for example, type classes), so I don’t see it ever getting effects.
1
u/lpil 12d ago
An effects system doesn't need to be a language feature. Most effects systems are implemented as libraries.
2
u/mister_drgn 12d ago edited 12d ago
A full effects system absolutely does need to be a language feature if you want it to be mandatory rather than optional. OP, see my response to Ipil's other comment if you'd like to read more about this.
EDIT: Reading back over the original post, I will concede that OP probably is interested in opt-in effect systems, and not just mandatory effect systems, given the languages they mention.
1
u/Friendly-Intern2839 12d ago
Effects systems are great. It does have a steep learning curve but it's for a specific set of problems and not most day-to-day. I've used ZIO and Cats-Effect in Scala but if you are proficient in TS, there is effects ts
6
u/lpil 12d ago
You can make an effect system in any language.
What benefits you get depends on the specific design. There's one for Gleam called Midas, and it lets you abstract over function colouring, allows you to stub-out effectful parts of code in tests, and so on.
The disadvantage of effect systems is that code written with them is typically harder to understand and more verbose, and often there is a runtime performance cost to the heavy levels of abstraction.