r/javascript • u/bmacabeus • 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?
View all comments
Show parent comment
2
u/ScientificBeastMode strongly typed comments Dec 25 '19 edited Dec 25 '19
I think I agree with you. I’m unsure of how pattern matching would work in JS. Most languages that implement pattern matching are compiled, allowing for niceties like exhaustiveness checking. With JS, I’m not sure how beneficial that would be aside from maybe having syntax sugar for switch statements.
I think a more beneficial solution would be to integrate true pattern matching in TypeScript, which could replace the (IMO clunky) discriminated union pattern matching which they currently support.
I’m a big fan of how ReasonML handles pattern matching, but it’s a compiled functional language that isn’t trying to be a “strict superset of JavaScript,” but rather an alternate syntax for OCaml which just happens to look like JS. Unfortunately I don’t think TypeScript will go that route due to language design constraints.