4 ms·
Monad tutorials are hard to understand because nobody actually wants to tell you what a monad is, because that would defeat elitist thinking. A monad is just a
by kerblang 5y ago
Monad tutorials are hard to understand because nobody actually wants to tell you what a monad is, because that would defeat elitist thinking.
A monad is just a very concise definition of a List. In java terms it's as if you're defining the List interface in only 5 methods. It is of course a very restrictive definition, but this makes it easy to redefine listy/listlike things as Monads with minimal fuss, and it turns out that when you put on listy glasses, you find listiness everywhere, because it's a fundamental concept in computing. For example, a string is a list of characters; a map is a list of keys, a list of values, and a list of key-value pairs; a byte is a list of bits. Java programmers get excited about the new Optional<> class, which in the monad world is famously a list of 0 or 1 generic things.
Monads enable a sort of programming-language parlor trick where you can flatten a bunch of nested for-loops into a single "for-comprehension" (or do-comprehension, list- comprehension, whatever) that looks like a fancy for-each-loop but is actually desugared calls to the Monad methods. The semi-magical part is that because Monad methods are all callback-based (lambdas), this makes it easier to resolve the problem of "callback hell" where you discovered lambdas, got carried away, and then you have a nested mess that you really want to flatten out.
That's pretty much it. Monads are clever, but not remotely close to being some kind of window into ultimate truth of everything. Elitism==extinction, and so we don't get to have nice things.
- dragonwriter 5y ago> Monad tutorials are hard to understand because nobody actually wants to tell you what a monad is, because that would defeat elitist thinking. Tutorials aren't for telling you what a thing is but for developing an intuition around why, in practical terms, it is. Telling you what a monad is is easy, brief, and fully handled by the typeclass definition and monad laws. But a tutorial which just presented them, while perfectly accurate at telling what a monad is, would be a crap tutorial. > A monad is just a very concise definition of a List Its not, because monads are much broader than lists, and the definition of a monad is less concise than that of a list. So its pretty much exactly not that. That monads encapsulate something like your vague concept of “listiness” in some sense is usually part of tutorials, because its a useful fuzzy intuitive handle. But its not alone sufficient to develop enough understanding to use, any more than the definition and laws are, so tutorials need to, and do, present more. They tend to suck because monads are a very abstract concept, and one which doesn't closely correspond to thing people tend to have a good concept of outside of people versed in category theory (I assume, not being one of those people I can't say for sure.) But the high level of abstraction is why they are useful, because they capture related parts of behavior of things that intuitively don’t seem very similar.
- mbrodersen 5y agoNo Monads are not “just a very concise definition of a List”. I do agree that some developers love to obfuscate rather than clarify because it makes them seem smart. But not everybody. I agree with the article that you really have to try and implement your own Monads to understand them. Reading articles won’t help. However unless you are programming in a pure functional language you don’t need to learn/use Monads. So just ignore it if that’s the case.