8 ms·
My takeaway from all this is that monads are kinda hard to explain. If something is hard to explain, that further suggests to me that it's probably the wrong ab
by cabalamat 5y ago
My takeaway from all this is that monads are kinda hard to explain. If something is hard to explain, that further suggests to me that it's probably the wrong abstraction.
(Personally I find the railway abstraction makes a lot of sense, but maybe that's just me.)
- SquishyPanda23 5y agoThere is an element of truth to this, but they are easier to use than explain. Part of the hardness comes from people wanting to use monads as an entry point to category theory.
- ModernMech 5y agoPeople get hung up on the terminology, but I’ve found if you don’t use the words functor and monad and just focus on the actual use case, second year college students learning functional programming for the first time can grok this concept. The way I have found success is to have them write a program first where a monad would be useful, and then ask them to implement it without monads. They will identify the need for a monad themselves, and then you can show them the tool they want. Then they use it to solve the problem, and at that point you start giving them a more rigorous theory.
- rkangel 5y agoThis is roughly Socratic programming teaching! It's for this reason that I think one of the better monad explanations is this one: http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html http://blog.sigfpe.com/2006/08/you-could-have-invented-monad...
- thewakalix 5y agoMonads are simple enough to explain them in a single blog post; the problem is, nobody can agree on which blog post.
- fartcannon 5y agoI assume I'm displaying my ignorance, but it feels almost tautological to me.
- marcosdumay 5y agoOh, well, being easy to explain is a feature. Monads lack this one (so do pointers, mutable variables, recursive functions, macros., Boolean logic, Boolean values, metadata..) Still, that's far from the most important feature for anything you will use daily.
- ninkendo 5y agoI disagree that anything on your "so do" list is hard to explain. At least, I feel like I understand all of them, but I still don't understand Monads. And I've probably spent 10x the amount of time reading (and still not comprehending) Monad tutorials than I have all of the other concepts combined.
- kelseyfrog 5y agoI'm curious how much time you're spent "doing monads" compared to reading about monads. The reason that I bring this up is that monads didn't click for me until I had hands on experience with a few different monad instances and could see the abstraction take shape in different ways. If that doesn't apply to you, that's ok too. It's fun to understand other people's methods of conceptualization.
- ninkendo 5y agoI have no idea how much time I’ve spent doing monads because I still don’t know what they are. It’s possible I’ve done “monadic” things in the code I already write, but I have no idea. I don’t know any Haskell at all, and it seems to be the only language out there where people think monads are a thing you need to learn, so I definitely have no motivation to learn them outside of curiosity. But I am curious about them, enough to read every tutorial I come across about them. But I still have no idea what they are.
- kelseyfrog 5y agoIt's definitely possible you've already done monadic things in code. If it's any consolation, I would not have ever been able to grasp monads by reading tutorials alone and the monad laws are simply too abstract for me to have envision a concrete usage. I learned without touching Haskell at all and it's my opinion is that Scala + Cats is a much easier onramp to monads than Haskell. You sound like a kind and curious person. If you ever want a one-on-one walkthrough please reach out to me (email in bio). Everyone deserves the chance to understand something if they want to.
- chongli 5y agoMonads are very easy to explain to anyone used to reading mathematical definitions. It’s the people without a math background that struggle so much. They insist on all of these real world analogies. The problem with that stipulation is that monads are too abstract and general to have a real world analogue. They are a fantastic and incredibly powerful abstraction though. Their mathematical properties, termed the monad laws, make sure of that.
- bluepoint 5y agoI have a strong mathematical background, I get the definitions, I understand very well the typical examples like the IO monad, yet I frequently have a hard time following more complex monad use examples. Especially transformers. So, I suppose it is not enough to understand the definitions, you really need to think of them as some form of a language.
- chongli 5y agoI think that’s the case with any concept in computer science or math. It’s easy enough to explain integration to someone using simple examples like f(x) = x^2 but it gets a lot more difficult when you introduce Stokes’s theorem and differential forms. Most of the people complaining about monads are not in your situation. They are struggling to grasp even the most basic examples because they understand concepts only by analogy to other things they already know and monads don’t map to anything they know.
- Zababa 5y agoYou can also explain them as interfaces, although as you said it gets harder when you get to the "why".
- cabalamat 5y ago> It’s the people without a math background that struggle so much. You mean like most programmers?
- franknine 5y agoQuoted from Bartosz Milewski's 'Category Theory for Programmers chapter 20: Let me set the record straight: The whole mysticism around the monad is the result of a misunderstanding. The monad is a very simple concept. It’s the diversity of applications of the monad that causes the confusion. As part of research for this post I looked up duct tape (a.k.a., duck tape) and its applications. Here’s a little sample of things that you can do with it: - sealing ducts - fixing CO2 scrubbers on board Apollo 13 - wart treatment - fixing Apple’s iPhone 4 dropped call issue - making a prom dress - building a suspension bridge Now imagine that you didn’t know what duct tape was and you were trying to figure it out based on this list. Good luck! So I’d like to add one more item to the collection of “the monad is like…” clichés: The monad is like duct tape. Its applications are widely diverse, but its principle is very simple: it glues things together. More precisely, it composes things. === Also would like to recommand: Functors and Monads For People Who Have Read Too Many "Tutorials" http://www.jerf.org/iri/post/2958 http://www.jerf.org/iri/post/2958 I got a feeling that Monad has no good metaphor to real life objects. Trying to make up an analogy just makes things worse.
- flipflip 5y agoWhen I realised that everything following a couple of simple laws was a monad, I started to notice them alot and was also able to implement them. The tutorials with pictures or analogies like containers only made me confused.
- ttymck 5y agoQuantum mechanics is a bit hard to explain, but it turns out to be quite a good model of our physical observations. Monads are hard to explain, they are _not_ hard to use, and use with great effect. Option#{map, flatMap} changed how I approached programming, and did not require a full understanding of why they existed or what they were a part of.