You're using jquery as a functor not a monad.
You're using jquery as a functor not a monad.
> No, you have a completely incorrect understanding of Monads.
To re-use your slightly ad-hominem argument structure: "No, you have a completely incorrect understanding of Monads!" Of course the word "completely" here is just an unnecessarily flamebaity word choice in describing either of us. Clearly, we both have some understanding of monads. Let's look at the facts instead:
A functor applies an operation to a wrapped value. But monads apply functions that also return a wrapped value. It should be easy to see why people think the jQuery chain pattern is indeed monadic.
For what it's worth, I'm far from alone in asserting that jQuery is indeed a monad.
Since Haskell people claim to be the only enablers of "true monads", they would of course nitpick about patterns implemented in other languages. But religion aside, the OP asked for the possible uses of monads, and there they are. That the example also shows functors is just an added benefit, though not at all relevant to the discussion.
And a lot of people think that the reason astronauts float on the ISS is because there's no gravity there.
> Since Haskell people claim to be the only enablers of "true monads", they would of course nitpick about patterns implemented in other languages.
Yes, because monad is an actual term and calling something a monad just because it sort of looks like it if you squint doesn't make it one. You can't write return in the 'jQuery monad', because there's no way to wrap arbitrary data types, only things like DOM elements. Something like a promise is closer to a monad, because you can turn any value into a promise, but IIRC there are still issues around it that I don't remember offhand.
He describes monads as "a loophole" in the idea of function purity. This isn't true; monads aren't a way to 'cheat' any more than passing an accumulator through like
factorial acc 1 = acc
factorial acc n = factorial (acc * n) (n - 1)
is. He says something about state and functions and closures that I can't understand and how the state is 'always different', and it's just nonsense as far as I can tell.He also calls values 'monads', which isn't accurate terminology at all; they're usually called monadic actions.
Yes, but they also must follow the monad laws.
>It should be easy to see why people think the jQuery chain pattern is indeed monadic.
It is not easy for me to see. In any of your examples are you returning the same encapsulated structure in your lambda you pass in? It doesn't look like it.
>For what it's worth, I'm far from alone in asserting that jQuery is indeed a monad.
Yes, a lot of people have a misunderstanding of monads.
>Since Haskell people claim to be the only enablers of "true monads",
I'm not a Haskell person. I write monadic code in both Scala and C# to great effect.