Why I won't be writing a monad tutorial
Last updated
Was this helpful?
Last updated
Was this helpful?
"A ?newbie', in Haskell, is someone who hasn't yet implemented a compiler. They've only written a monad tutorial" -
Let's start with a story...
Young Alice and her father (who happens to be a mathematician) are visiting a petting zoo...
Alice: Look at those kitties.
Daddy: Aren't they cute. There are two of them.
Alice: Look at those doggies.
Daddy: That's right. Can you count? There are two doggies.
Alice: Look at those horsies.
Daddy: Yes darling. Do you know what the kitties and doggies and horsies all have in common?
Alice: No. Nothing in common!
Daddy: Well, actually they do have something in common. Can you see what it is?
Alice: No! A doggy is not a kitty. A horsie is not a kitty.
Alice: [Bursts into tears]
No (sensible) parent would ever try to explain how to count by starting with a formal definition of ordinal numbers.
So why is it that many people feel compelled to explain a concept like monads by emphasizing their formal definition?
That might be fine for a college-level math class, but it plainly does not work for regular programmers, who just want to create something useful.
Here's the truth: You don't need to understand monads to write useful functional code. This is especially true for F# compared to say, Haskell.
So really, don't worry about them.
So this is why I won't be writing a monad tutorial. I don't think it will help people learn about functional programming. If anything, it just creates confusion and anxiety.
On the other hand, I do think that you should write a monad tutorial. When you try to explain something to somebody else, you end up understanding it better yourself.
Here's the process I think you should follow:
First, write lots of practical code involving lists, sequences, options, async workflows, computation expressions, etc.
As you become more experienced, you will start to use more abstractions, focusing on the shapes of things rather than the details.
At some point, you will have an aha! moment -- a sudden insight that all the abstractions have something in common.
Bingo! Time to write your monad tutorial!
Good luck with your tutorial -- I'm off to eat a burrito.
Daddy: How about I explain for you? First, let us consider . Does that give you a clue?
As an unfortunate result of this approach, though, there is now a whole mystique around the concept of monads. It has become on the way to true enlightenment. And there are, of course, a to help you cross it.
Monads are not a . They won't make you any more productive. They won't make your code less buggy.
Yes, I will use examples of monads in different , but, other than right here, I will try to avoid using the word "monad" anywhere on this site. In fact, it has pride of place on my !
The key point is that -- you cannot jump straight to the last step and then work backwards. It is the very act of working your way through the details that enables you to understand the abstraction when you see it.