by cabalamat · 5y ago · 0 comments
(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.
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.
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.
I disagree -- these all seem pretty easy to explain to me.