7 ms·
Monads Are Not Metaphors (2010)
- olavk 11y agoMetaphors a tricky. Reminds me of the many attempts to explain objects and classes in terms of real-world object. (Cars, fruits, persons etc.) These explanations are often more confusing than enlightening, since object and classes are actually not like real world objects at all.
- Tomte 11y agoRelevant: https://web.archive.org/web/20110829152110/http://lists.canonical.org/pipermail/kragen-tol/2011-August/000937.html https://web.archive.org/web/20110829152110/http://lists.cano...
- TuringTest 11y ago> These explanations are often more confusing than enlightening, since object and classes are actually not like real world objects at all. I desagree. While it's true that metaphors can be over-stretched and cause problems later, a well-placed metaphor at the beginning of the learning process can do wonders to quickstart understanding of a topic about which you know nothing at all. At the very least, the metaphor will provide meaning to the very act of learning, explaining why you should bother at all with that topic. Experts explaining their subject often forget what it's like to not know how two concepts in their domain relate to each other and the uncertainty when reading a sentence that connects them in a way that has not been seen yet.
- saurik 11y agoRelated: https://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ https://byorgey.wordpress.com/2009/01/12/abstraction-intuiti...
- crimsonalucard 11y agoAnybody who didn't know what monads were and now reached an epiphany thanks to this article please comment. Also is there anyone here who understands what monads are but has never programmed in haskell or a functional language?
- dkarapetyan 11y agoMonads come from category theory. You can certainly know what they are without ever having programmed. "Basic Category Theory for Computer Scientists" and "Category Theory (Oxford Logic Guides)" are good places to start.
- crimsonalucard 11y agoRightly so, but look at the replies to my post. Essentially nobody responded to my query. Looks like mostly Nobody knows what monads are without learning functional programming AND this article totally failed to help anyone understand what monads are.
- olavk 11y agoI don't believe monads are worth the bother without some syntactic sugar. Without sugar, it is just a sequence of operations converted into a chain of nested lambdas with one lambda for each operation. Cool, but far to convoluted to write for any real-world programs. The attempts to introduce monads in other languages like Python, Ruby etc. is missing what make them a useful tool in Haskell.
- exDM69 11y ago> The attempts to introduce monads in other languages like Python, Ruby etc. is missing what make them a useful tool in Haskell. While I agree that the syntactic sugar of the "do" notation in Haskell makes Monads vastly more useful, there are examples where Monads have been applied in other programming languages without any syntactic sugar. For example, there are parser combinator libraries (influenced by Parsec) in many languages. E.g. Python's pyparsec is internally using monads that are defined just as they are in Haskell. Monads are a great idea for many practical tasks in programming, their use in Haskell is often emphasized becuse they're required for IO (which is not the case for imperative languages). For many of the non-IO applications of monads, they're just as useful in other languages too.
- tikhonj 11y agoI've used Async and LWT in OCaml—libraries for monadic asynchronous programming—and the abstraction can still be useful without syntax sugar. Hell, JavaScript promises are basically a bastardized and slightly inconsistent monad, and they're still useful even without syntax sugar. If we could generalize over the API and use them for other things it would be even better, but that's not the JavaScript way.
- runnig 11y agoCould someone translate this to Python?
- GreaterFool 11y agoDid bad high-school mathematics education conditioned us all to hate everything that's related to mathematics? Label a concept "this is just engineering practice" or "this is just physics. this equation describes how universe works" and people will happily accept it as is. But label it "mathematics" and explanations are in order because maths is hard to understand... I don't see any posts where authors concern themselves with metaphors for Maxwell's equations (or anything else in physics; maybe I'm hanging out in the wrong circles though). What is a process of understanding a mathematical equation? Stare at it until you grok it? Use it to solve problems to get a feel of what it means? Write proofs about it so you can state some properties with certainty? I don't know what the best/structured process is, but the core is "take this equation and do something with it". Do the same with monads! I think people having problems understanding monads are those that defer writing any code until they feel "they get it". Instead of "now I get it, monads are burritos, time to write some code" one should write some code in order to understand monads
- ch 11y agoI think it has much to do with the abstractness of mathematics (especially category theory). Some just have a hard time anchoring the ideas to something concrete, and they are in need of that anchoring to make the ideas stick. With engineering and physics equations there is always something physical to relate them to (at least somewhere in the universe(s)) -- not to say there aren't harder equations to grasp in those fields too, but again that is typically trending into the more abstract (less macro) areas of the field. The trouble with math is sometimes you just have to work through equations enough until you form some intuition about how they work. Some folks just want to skip that step and others Oblidge them by assisting their mental model with metaphors which seem to never be universal enough -- if it were it would just be math.
- GreaterFool 11y agoJust thought about something that I think is analogous to explaining monads. I remember reading few articles about "core math" in the States and it had example problems related to addition, subtraction, multiplication. The complaint was that those problems where incomprehensible gibberish and kids and adults alike had really hard time figuring them out. From what I recall the core of the issue was that the question authors had some specific mental model of how addition and multiplication works and the questions were structured in a way that required figuring out what that model was (otherwise it was very hard to understand what was being asked). Why does 2 + 3 = 5? Well, because it does. I don't even know what my mental model of addition is. I just do it. I stared at it long enough as a kid and I developed neural circuits that compute the result. Instead if I asked: I have two stars in a box. How many squares do I have to put in the box to have 5 shapes? | * * | + | ??? | = | * * # # # | Which is how I recall those weird maths questions were structured. Now you a have a (terrible IMHO) model of addition. That's what I think those monad tutorials do for you.
- TuringTest 11y agoThis coming from the "you don't really understand a topic until you learn its maths" school. I don't mind that position as there's some truth to it, up until they commit the mistake to consider metaphors harmful and an obstacle. I greatly benefited from the "conveyor belt" metaphor for learning monads; it made me grasp instantly something that I would have never understood from a pure theoretical explanation - namely why they are so useful and widespread in functional programming, as a building tool to distribute logic among several composable functions over a data type. Sentences like "We start with one thing and use its value to compute a new thing" and "Monads are an abstract, mathematical label affixed to a pattern found in almost all code" will never convey information about how it's intended to be used in the same vivid way as the metaphor. I know for true that the pure mathematical approach leaves me hanging. I learned linear algebra in the theorem-proof style, and as of today I still don't know when it's an adequate technique to use. I can't tell what matrix ranks, kernels or tensors are good for even though I can calculate their values very precisely.
- jessaustin 11y ago...the "conveyor belt" metaphor for learning monads; Thanks for that! Here's a link: http://web.archive.org/web/20100910074354/http://www.haskell.org/all_about_monads/html/analogy.html http://web.archive.org/web/20100910074354/http://www.haskell...
- wyager 11y agoThis article seems a bit heavy on the computational monads. Monads don't necessarily have anything to do with sequencing or computation, and the author is objectively incorrect to say "monads are a pattern, not a specific type". In fact, monads are an algebraic structure, defined only by the types of the operations defined on them and the laws those operations obey. That's not to say that concrete examples like the one here aren't useful, but the author is not covering the full scope of what monads are.
- orkoden 11y agohttp://fuckingmonads.com http://fuckingmonads.com
- a3n 11y agoBrushing aside "you can do anything in one language that you can in another," what do monads allow me to do better that I can only approach without them? I've tried reading (but not coding), and all I hear is sequence of operations, chaining, and similar. I know I'm missing something. Basically I haven't seen or synthesized the tl;dr that makes me want to learn a language that has them.
- AnimalMuppet 11y agoIf you're in a pure functional language, monads are the way you do sequencing while still being purely functional. If you regard pure functional as the "better" (for reasons of, say, controlling the state space explosion of your code, or reasons of understandability and therefore maintainability), then monads are part of the necessary tooling to get you there (if your problems have any parts at all that are necessarily sequential). As far as other uses: The best explanation that I've seen is that they let you hide the parts that you need to do, but that aren't the real thing your doing. Logging, for instance. You can add logging to something, and just string functions together as if there were no logging going on. (Of course, if you were doing non-pure-functional programming, you could just add logging statements wherever you wanted, and string your functions together just the same...)
- TheCoelacanth 11y agoAll useful languages have monads. It's a pattern that is nearly impossible to avoid. Where Haskell is different than most languages is that it lets you write generic code that operates on any monad.
- AnimalMuppet 11y agoMeaning that any language that doesn't have monads, you're defining to not be useful? Or meaning that monad-the-pattern is everywhere, in every even barely useful language, even if there's no explicit monads in the language?
- TheCoelacanth 11y ago