Hacker News new | ask | show | jobs
by tome 12 days ago
Right, I understand the history (although I'm not sure I'd say that exception don't compose well) and I understand that "algebraic effects" are an attempt at something better. But I don't understand whether they're something that can be precisely defined or just informal terminology for "a better sort thing for dealing with effects".
1 comments

You can precisely define any particular model, but not all work in the area shares the same model. I think you know about the capability-passing model, which is quite different to the algebraic effects (e.g. row types) models.

The general ideas are:

* effects are handled by handlers (called capabilities in the capability-passing model)

* function signatures describe the effects that are used

* effectful code is written in direct style, not monadic style

Thanks! This begins to make more sense to me

> effects are handled by handlers

OK, and in the general case a handler allows its body to "perform" an action, and when the action is performed it has the ability to "respond" to it in (in some cases) a very flexible way, running it never, or multiple times, or in a modified environment, or possibly even passing it out of the scope of the handler entirely.

> function signatures describe the effects that are used

Would you say this is not possible in an untyped language then?

> effectful code is written in direct style, not monadic style

I don't understand the distinction here

> OK, and in the general case a handler allows its body to "perform" an action...

Yes, although not all systems allow this, as implementing full continuations is involved and can hurt performance.

> Would you say this is not possible in an untyped language then?

You can definitely implement the ideas of algebraic effects in an untyped language, but you lose one of the benefits.

> I don't understand the distinction here

Monadic code is code where the order of evaluation is specified by bind / flatMap. Direct-style just uses the language's built-in control flow. See https://noelwelsh.com/posts/direct-style/ for more