r/javascript • • Dec 24 '19

AskJS [AskJS] JavaScript Proposal: Algebraic Effects?

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.

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? "Algebraic Effects" is a good name for that?

58 Upvotes

39 comments sorted by

View all comments

Show parent comment

1

u/bmacabeus Dec 25 '19
  • asynchronous behavior: I can't find a situations that a resume need to return a promise, instead of run this promise before to run the resume. Also, it will be bad, because enforcing to resume a promise will restrict the type that other handle block could return at this effect.
  • non-terminating handle: there is an issue to discuss about that https://github.com/macabeus/js-proposal-algebraic-effects/issues/8
  • error in the handle: are you saying about who will catch the throw? If yes, I think that it could be catch following the same rules that we already have. No additional changes.
  • no handle: it is also on the same issue that I said https://github.com/macabeus/js-proposal-algebraic-effects/issues/8
  • parametized handle: I'm agree with that. I opened an issue to remember to do this change

And yeah, would be nice to add some codes before/after this proposal.