Live data from Hacker News

Algebraic Effects for the Rest of Us

overreacted.io

91–100 of 106 posts

Re: Algebraic Effects for the Rest of Us

#91

Near the end of the article: > Because algebraic effects are coming from statically typed languages, much of the debate about them centers on the ways they can be expressed in types. This is no doubt important but can also make it challenging to grasp the concept. That’s why this article doesn’t talk about types at all. I'm only remotely familiar with algebraic effects, but I thought the whole point was to have a nic…

> Near the end of the article:

>> Because algebraic effects are coming from statically typed languages,

Though in fact the origins come from dynamically typed languages like Lisp, where condition signalling systems were developed in the 1970s. When they started appearing in statically typed languages in the late 80s, they were only used for errors, and by the time they were caught the stack had already been unwound.

What's old is new again.

Re: Algebraic Effects for the Rest of Us

#92

Earlier quoted context omitted.

Algebraic Effects are not common lisp's condition system. They are far more general. The example here to do with error handling only shows that this form of error handling is an (incredibly) specific (very limited) instance. And nothing is being reinvented here. This is an article to communicate, in the simplest terms possible, decades of academic research. The author is not claiming to, nor has he, invented anything…

Lisp's condition system isn't just for handling errors either; it's an system for handling conditions, just as the name suggests.

Algebraic Effects specifically meaningful in statically typed systems; they have nothing to do with conditions.

Continuation-passing is only one component.

Your whole approach to commenting here is, "I think I know what AE are, and on that basis, this is stupid!"

Both your premise and conclusion are false.

Re: Algebraic Effects for the Rest of Us

#93
post #59

I, like many people in this thread, learnt about algebraic effects for the first time from the posted article. However, many commenters seem to be mislead by the explanation based on an example with exceptions. What I learnt from [1] linked below is that algebraic effects is a generalization of which language constructs like try/catch, async/await, or generators are just particular cases. From that perspective, algeb…

I tried to address this in the article but I guess people skipped over this?

>Note, however, that algebraic effects are much more flexible than try / catch, and recoverable errors are just one of many possible use cases. I started with it only because I found it easiest to wrap my mind around it.

Re: Algebraic Effects for the Rest of Us

#94
post #34

Earlier quoted context omitted.

In e.g. Haskell, you often Dont explicitly write out types, letting the compiler infer them for you. This could essentially cascade all the way up. Meanwhile, if you want to add logging in Haskell via a monad, you don't just need to change the type of each calling function to make it monadic, but you need to rewrite the function to make it monadic. That is harder work than changing some types. Moreover it is harder t…

That explains why one of his examples is a log handler, which in javascript would be sensibly provided by dependency injection, but that doesn't work as well for haskell. Things I'd want more information on: what about errors in effect handlers (or would errors be reimplemented as effects?), effects with no handler, which handlers do effects inside handlers use? Is it really worth making it much harder to reason abou…

Dependency injection works fine on Haskell. An effect system is one way of implementing it.

That is, you write code that says it may perform any effects from the following list. At some central point, you execute that code in the context of a handler for those effects.

That's the same idea as using dependency injection to provide a service. The only difference is that the ergonomics are better. You can't forget to inject a service, the types prevent it.

Re: Algebraic Effects for the Rest of Us

#95
post #88

The author ought to look into and write about the Common Lisp condition system, which allows error handlers to invoke restarts at different parts of the call stack. [1] The long-story-short on them is that they decouple the treatment of exceptional situations (or conditions ) into three orthogonal roles: signaling the condition (akin to “throwing”), handling the condition (akin to “catching”), and recovering from the…

I was thinking throughout reading this: "Isn't this just call/cc?"

call/cc with handlers i.e. delimited continuations, yes.

Re: Algebraic Effects for the Rest of Us

#96
post #91

Near the end of the article: > Because algebraic effects are coming from statically typed languages, much of the debate about them centers on the ways they can be expressed in types. This is no doubt important but can also make it challenging to grasp the concept. That’s why this article doesn’t talk about types at all. I'm only remotely familiar with algebraic effects, but I thought the whole point was to have a nic…

> Near the end of the article: >> Because algebraic effects are coming from statically typed languages, Though in fact the origins come from dynamically typed languages like Lisp, where condition signalling systems were developed in the 1970s. When they started appearing in statically typed languages in the late 80s, they were only used for errors, and by the time they were caught the stack had already been unwound.…

Sure but I mean most work on algebraic effects (or at least the papers I know of) deals with the associated type system.

Instead most people here seem to focus on the semantics, which indeed boil down to call/cc + handlers or previous condition systems.

Re: Algebraic Effects for the Rest of Us

#97
post #91

Earlier quoted context omitted.

> Near the end of the article: >> Because algebraic effects are coming from statically typed languages, Though in fact the origins come from dynamically typed languages like Lisp, where condition signalling systems were developed in the 1970s. When they started appearing in statically typed languages in the late 80s, they were only used for errors, and by the time they were caught the stack had already been unwound.…

Sure but I mean most work on algebraic effects (or at least the papers I know of) deals with the associated type system . Instead most people here seem to focus on the semantics, which indeed boil down to call/cc + handlers or previous condition systems.

Those 1970s/1980s conditioning systems specifically evolved from the inheritance-based type systems originally developed for object-oriented systems.

Computer science is a field that notoriously ignores the past, so these folks are far from the only people to reinvent something already well developed.

Re: Algebraic Effects for the Rest of Us

#98
post #6

I doubt if you need any new language construct to introduce this. Could you not simply pass an error handling function/object with all your functions/methods, which is called when an error occurs? This function/object could then resolve the error or throw an exception if it cannot resolve the error. It is possible, and relatively easy, to chain such error handling functions/methods to implement complex error handling…

Yes, you're absolutely right. The article gives the impression that algebraic effects give a new ability to decouple the code that uses some effects from the implementation of those effects. But that's absolutely not so: Simply passing down the implementation as an argument provides all the functionality that was described in the article.

So, in imperative/OOP languages, it's best to treat algebraic effects as inspiration for passing down objects to provide implementations; that gives you most of the same power, while using existing features of your language.

Some effect systems allow resuming multiple times, allowing more fancy features, but those features are niche, and even of questionable theoretical value because of their incompatibility with linearity.

Re: Algebraic Effects for the Rest of Us

#99
post #88

The author ought to look into and write about the Common Lisp condition system, which allows error handlers to invoke restarts at different parts of the call stack. [1] The long-story-short on them is that they decouple the treatment of exceptional situations (or conditions ) into three orthogonal roles: signaling the condition (akin to “throwing”), handling the condition (akin to “catching”), and recovering from the…

I was thinking throughout reading this: "Isn't this just call/cc?"

All monadic computation can be accomplished with continuations, which offer a way to thread the monadic bind between sub-programs. But at some point this is equivalent to saying that all continuations can be implemented with machine language... True, but beside the point.

The main purpose of ideas like algebraic effects is to build on a firm understanding of a model of computation. Implementing algebraic effects (whether with call/cc or otherwise) lets one specify a program's behaviour more precisely.

Whether this seems useful or not is probably closely aligned with whether you think static types and purity are useful or not, perhaps.

Re: Algebraic Effects for the Rest of Us

#100
post #97

Earlier quoted context omitted.

Sure but I mean most work on algebraic effects (or at least the papers I know of) deals with the associated type system . Instead most people here seem to focus on the semantics, which indeed boil down to call/cc + handlers or previous condition systems.

Those 1970s/1980s conditioning systems specifically evolved from the inheritance-based type systems originally developed for object-oriented systems. Computer science is a field that notoriously ignores the past, so these folks are far from the only people to reinvent something already well developed.

This is spectacular revisionism.

Conditions arose out of MIT's AI labs, a place full of entrepreneurial enthusiasm and practical work, conditions were described in the early 80s.

Algebraic effects come out of Endinborough, a place full of academic research focusing on abstract algebraic models of computing.

Algebraic effects builds on theoretical work by Wadler, Spivey, and Moggi on monadic computation, not on Lisp. Similarly, Lisp around that era built primarily on the previous work on Lisp out of MIT, not on models of computing from around the other side of the globe.

These labs had different focuses, goals, and approaches. Lisp is one of a dozen languages of the time that found clever ways to express control flow and exceptional flow, but none of them were trying to find a model for defining semantics.

Years later, we discover that many of those old constructions are almost equivalent to models derived by PL research. That's not surprising, as the models are meant to help us describe programming in general, and the problems were already there to be solved. Using the models usually (not always) gives a better end result than the ad-hoc approaches.

Or sometimes we keep ignoring the models because we've always done it some other way.

Post reply on HN