(Personally I find the railway abstraction makes a lot of sense, but maybe that's just me.)
(Personally I find the railway abstraction makes a lot of sense, but maybe that's just me.)
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
I got a feeling that Monad has no good metaphor to real life objects. Trying to make up an analogy just makes things worse.
They are a fantastic and incredibly powerful abstraction though. Their mathematical properties, termed the monad laws, make sure of that.
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.
You mean like most programmers?
Part of the hardness comes from people wanting to use monads as an entry point to category theory.
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.
http://blog.sigfpe.com/2006/08/you-could-have-invented-monad...
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.
Still, that's far from the most important feature for anything you will use daily.
Explaining things to people that already knows them is always easy.
I'd say that your list is full of things that have practical examples when you consider how real, physical computers work. Boolean logic can be shown by example by showing physical transistor circuits, and I'd argue that people can understand them quite easily. Pointers/variables can be shown by explaining how memory addressing works on real machines, and what CPU instructions correspond with the actual code you're writing.
Monads however, seem to be this purely abstract mathematical concept that comes from CS-as-a-math-discipline, which although useful, requires you understand ton more theoretical background before you can approach it. At least that's my experience -- I still don't understand them and every tutorial I've read either makes them look like magic (ie. doesn't actually explain them) or tries to take a mathematically rigorous approach and I get lost in the weeds.
I know intuitiveness is very subjective, but I'd wager that by numbers, many more people are able to understand pointers/mutable variables/macros/boolean logic/etc more easily than they can Monads.
Young man, in mathematics you don't understand things. You just get used to them.
—- John von Neumann
Honestly I think a lot of effort is wasted starting with this stuff rather than more motivated examples... But the interest is the harder thing to come by, so at least they're learning something.
You could basically rephrase it as “you don’t need a lot of math, you just need a lot of math”.
Well, if they were, all those people wouldn't be trying to understand them.
They are applied on Haskell (and Javascript, Rust, C#... but they are way more visible on Haskell). Write some Haskell and you will get them.
But, well, I don't have any reason for you to do that. You just asked how, and I gave you a way. If you don't have any interest in learning it, there's absolutely no problem, but posting "I never really tried, but that thing is bad because I haven't learned it already" FUD is pretty bad.
But so far, no monad tutorial has made a good case for why they’re actually useful, other than for learning Haskell. And most advice for how to learn them sounds exactly like what you said: “oh if you still don’t get it, you just need to write more Haskell.” You can see why that’s a bit of a disappointment, right?
Basically, you have people making this argument:
- monads are important outside of Haskell
- to understand why, you have to learn them
- to learn them, you should write Haskell
Which I’m sure you can understand comes off as a bit unconvincing.If you want to use a language to program, knowing them will help you with approximately nothing, because most languages either have awful ergonomics for that kind of abstraction or bring them on much more limited ways that you are better learning how they specifically apply to the language than the general concept. If you learn the general concept, the specific cases will be easier, but unless you plan on learning several languages, it's not worth it.
Anyway, one large exception is if you plan on doing heavily abstract C# libraries. The C# support for monads is almost as general as Haskell.
http://www.jerf.org/iri/post/2958
https://philipnilsson.github.io/Badness10k/escaping-hell-wit...
The first one I think cuts through all of the crap surrounding them. They're just a design pattern. And the second one helps motivate them, showing the many contexts where the design pattern many apply.
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.
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.
I disagree -- these all seem pretty easy to explain to me.