News for hackers. Stuff that matters.
Re:Why Algebraic Effects? by aatd86 on Saturday May 24, 2025 @08:43AM (#44080699)
I might be a bit dense but I didn't quite get it and the examples didn't help me. For instance, the first example SayMessage. Is it supposed to be an effect? Why? From the function signature it could well be a noop and we wouldn't know the difference. Or is it arbitrarily decided? Is this all about notations for side-effectful operations?
Re:Why Algebraic Effects? by scalaisneat on Saturday May 24, 2025 @09:28AM (#44080970)
because it is declared as an effect - and implements a handle.

Think of it more like an interface. It turns out that many common patterns - async, IO, yielding can all be expressed with a handle - and the effect can be represented in the signature.

This allows the code to have which effect its ran in, at runtime - other commenters pointed out its very similar to dependency injection.

Re:Why Algebraic Effects? by aatd86 on Saturday May 24, 2025 @03:04PM (#44083117)
Ok so we are basically defining a named function signature that represents a side effect shape.

Then the implementation of these side effect is done elsewhere and assigned as the capability of a function, which is now deemed as impure by the compiler.

You're right, it looks a bit like an interface.

Re:Why Algebraic Effects? by anon-3988 on Saturday May 24, 2025 @09:13AM (#44080877)
if I have to guess, it's something like this function will call fopen, fwrite, etc somewhere downstream.

of course I am hoping to get corrected on this.

Re:Why Algebraic Effects? by lblume on Saturday May 24, 2025 @02:13PM (#44082828)
It might, if the effect is handled using these functions. You could also handle the effect using another handler, doing something entirely different. It is up to the caller how to handle effects, or propagate them up.