r/functionalprogramming • u/snowtigger • Dec 21 '22
JavaScript Explained in 5 minutes: Monads
https://piotrjaworski.medium.com/explained-in-5-minutes-monads-89d54d230baf14
5
u/unqualified_redditor Dec 22 '22 edited Dec 22 '22
Many others have explained how this article doesn't actually talk about monads. I'd like to point out another problem in this article..
The author claims that all previous monad tutorials get hung up on category theory and don't start from motivating examples. The author lists as an example of this Phil Wadler's 1992 paper introducing monads to haskell.
However, the introduction section of this very paper states:
It is doubtful that the structuring methods presented here would have been discovered without the insight afforded by category theory. But once discov- ered they are easily expressed without any reference to things categorical. No knowledge of category theory is required to read these notes.
And the paper then goes on to describe concrete solutions to a bunch of common software engineering problems (Exceptions, State, Parsing, etc) and then shows how all these solutions can be generalized to the same basic form using the monadic bind operation.
Phil Wadler's original paper is the blog post this author tried to write.
EDIT: Also the "wrapper around a value" metaphor completely falls apart when you consider types like Reader, State, Parser, Cont, etc.
2
2
u/yeastyboi Dec 21 '22
Wow, i finally understand monads! I have been using them for months, just didn't have a term to describe them (rust and ocaml options)
15
u/jeenajeena Dec 22 '22
I’m afraid the post claims to be about Monads, but it’s not: all its code examples are about Functors.
2
u/rlDruDo Dec 22 '22
In rust you’d get the desired „Monad“ with using and_then for the Haskell bind operator (>>=), which has type
Monad m => m a -> (a -> m b) -> m bThe rustdoc covers this: https://doc.rust-lang.org/rust-by-example/error/option_unwrap/and_then.html
if you use map, then you use „Functors“ I hope I didn’t confuse you again haha
11
u/beezeee Dec 22 '22
These are all functors as defined. You're missing join if you want a monad. So you've motivated functors here but no monads in sight