News for hackers. Stuff that matters.
Re:Why Algebraic Effects? by cryptonector on Saturday May 24, 2025 @03:12AM (#44079329)
It's the same as with monads:

1) Testing. Write pure code with "effects" but, while in production the effects are real interactions with the real world, in testing they are mocked. This allows you to write pure code that does I/O, as opposed to writing pure code that doesn't do I/O and needs a procedural shell around it that does do the I/O -- you get to write tests for more of your code this way.

2) Sandboxing. Like in (1), but where your mock isn't a mock but a firewall that limits what the code can do.

(2) is a highly-desirable use-case. Think of it as a mitigation for supply-chain vulnerabilities. Think of log4j.

Both of these are doable with monads as it is. Effects can be more ergonomic. But they're also more dynamic, which complicates the implementations. Dynamic features are always more costly than static features.

Re:Why Algebraic Effects? by charcircuit on Saturday May 24, 2025 @04:13AM (#44079649)
Again you are listing things that are possible but not explaining why it's better to do it via algebraic effects as opposed to the alternatives.
Re:Why Algebraic Effects? by cryptonector on Saturday May 24, 2025 @04:38AM (#44079722)
The only reason I can think of -but I'm not the right person to ask- is ergonomics, that in many cases it might be easier to push an effect handler than to build a whole monad or whatever. Elsewhere in this thread there's talk of effects solving the color problem.
Re:Why Algebraic Effects? by threeseed on Saturday May 24, 2025 @09:19AM (#44080923)
Take the following requirement:

"A user has made an API call. I want you to in parallel race two concurrent tasks: check if the data is in (1) cache and (2) database. Whichever returns fastest return to the user. Otherwise kill the other task mid-flight and make sure the connection resources for both are cleaned up".

This is trivial with an effect systems like ZIO and it will work flawlessly. That's the benefit of effect systems. Use cases like this are made easy.

But now with JVM Virtual Threads there are frameworks like Ox: https://github.com/softwaremill/ox which allow you to achieve the same thing without effects. And how many times do you really need that sort of capability ?