Settings

Theme

Ask HN: JavaScript Proposal – Algebraic Effects?

7 points by macabeus 6 years ago · 6 comments · 1 min read


Hey guys, I'm writing a Babel plugin to be able to use algebraic effects in JS https://github.com/macabeus/js-proposal-algebraic-effects

No more function color! Yes one-shot delimited continuation!

What the hell?! Well... I really recommend that you read this blog post by Dan Abramov explaining algebraic effects - and how it could be very useful on our JavaScript code: https://overreacted.io/algebraic-effects-for-the-rest-of-us/

This project is a runnable POC with a Babel's "plugin", so you could write some code and taste this new concept in JavaScript. Its features, syntax, and goals are very inspired by Dan Abramov's blog post mentioned above. In short, with algebraic effects, you could separate what from the how and have fewer refactors.

What do you think? Would that be a good feature for JS?

haecceity 6 years ago

So instead of requiring the callee to be async or not you have to make sure your caller is executing in the right effect handler context? Sounds like we replaced the coloring problem with another one? I can see how it benefits the language designer because you could implement try catch and async with this but how does it benefit the user?

  • macabeusOP 6 years ago

    Yeah. We need to ensure that we have a handler to catch the effect (there is an issue about that: https://github.com/macabeus/js-proposal-algebraic-effects/is...)

    For user, it could be useful to separate what from the how. For example, we could have a function that launches effects to manipulate the file system, and for test/mock purpose we could catch this effects with handlers that mock the file system.

    I know that the pattern dependency injection solve the same problem, but with effects you could do it with a more natural code.

pickdenis 6 years ago

Since JS lacks a static type system, isn't it a bit misleading to call these "algebraic" effects, when algebraic is referring to the type system? I'm still not clear where the "algebraic" part comes in here.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection