A software development enthusiast noted the following:
Current status: compulsively rewriting all my JS after making the intuitive connection between generator functions and monad comprehensions.
I felt like I missed something there. My solution to callback hell was to use something like js-csp
(ie a queue).
My question is: What is the connection between generator functions and monads in JavaScript?
There is none.
While generator functions may look very similar to monad comprehensions (i.e. do
notation), they are not as generic. The main problem is that ES6 generators are stateful, and can only be advanced once per continuation. Try implementing the list monad with them and see it fail.
True monad comprehensions can be achieved using a compile-to-JS language that supports them (like LatteJs, monadic, PureScript or LispyScript), or sweet.js macros. They typically desugar to callbacks - just like in Haskell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With