3 ms·
Fancy chained method calls are equivalent to do notation without any binds, which only needs Applicative. Monad is sufficient but not necessary. That said, th
by dllthomas 13y ago
Fancy chained method calls are equivalent to do notation without any binds, which only needs Applicative. Monad is sufficient but not necessary.
That said, this does appear to be a monad - they implemented bind correctly.
Haskell:
instance Monad Maybe where
Nothing >>= _ = Nothing
(Just x) >>= k = k x
From the article:
var Nothing = {
bind: function(fn) {
return this;
}
};
var Something = function(value) {
return {
bind: function(fn) {
return Maybe(fn.call(this, value));
}
};
};
It doesn't really use it right, for the most part, though (... I think; I only skimmed).
- jerf 13y agoI think bind is essentially correct too, but the failure to use it properly tends to suggest a level of understanding too small to be writing Yet Another Monad Tutorial. I've seen real JS monads, and I believe they are irretrievably ugly to use, with the need for nested functions.