3 ms·
Don't let people waste your time with metaphors. A monad is something that you can use `flatMap` on. That's it. It's not it, of course, but that's all you need
by jim-jim-jim 5y ago
Don't let people waste your time with metaphors. A monad is something that you can use `flatMap` on. That's it.
It's not it, of course, but that's all you need to know. You can open up the js console in your browser right now and play around with `map` vs `flatMap` since lists are monads.
It's not a very useful function on lists, but if you take pains to simulate an optional type with it, where an empty list is Nothing/failure and a list with a value indicates Just/success, you can see how it might be an exciting form of control flow: chaining together optimistic functions, but short circuiting if any of them fail. Happy path only programming.
I wouldn't worry too much if this is yet another shit explanation. Monads will eventually be added in earnest to your language of choice, you will use them, and think "oh, why could nobody explain that?"
- monads 5y agoYes, I think metaphors are used to put the formal definition of computation monads into some concrete situations (for getting intuition). But "too many bad metaphors" will make monads something mysterious, incomprehensible.
- ParetoOptimal 5y agoHm, small addition: > A monad is something that you can use `flatMap` on that cannot act in a surprising way. That's it.