Skip to content

Comment on Monads for Normal Programmers

Comments

These "monad tutorials" drive me nuts. I wasted a week trying to understand monads from random "You can do monads in Python, JavaScript and Brainfuck!" tutorials that all had different (and sometimes inconsistent) perspectives on what they were and what they were good for before I gave up and learned Haskell. In my case, I was laboring under the false assumption that because I knew language X, it would be easier to learn about monads in X than to learn Haskell. In Haskell, the value of monadic computation falls out naturally from the type system and syntax. Yes, you still have to verify the laws, but Haskell's purity makes this easier as well.

I think the jQuery analogy has some didactic value for understanding combinators, but calling it a monad and falsely asserting that the laws hold is not doing "normal programmers" any favors. In the comments, he analogizes demonstrating the map function to C programmers, but this analogy is false because he clearly understands map and what it's used for but the same cannot be said for his understanding of monads.

For "normal programmers" out there who want to (for whatever reason) learn about monads, my recommendation is to ignore these tutorials and learn Haskell or an equivalent. I learned Haskell specifically to develop an understanding of monads, but what I got out of it was much, much more valuable than just an understanding of monads.

Having used them I came to the conclusion that the monad itself is just not a useful concept; it's only when you're trying to do something that it makes sense. I tried to write up my experiences as http://m50d.github.com/2013/01/16/generic-contexts.html (very scala-oriented), would be interested to hear whether that's useful to anyone.

Yes, that is a much better explanation of Monads. My experiences mirror yours. Monads didn't make sense to me, while at the same time I was happily using option and future and thinking how cool it was I could nest flatmap calls by using the for syntax. Then one day.....

Couldn't agree more. I read somewhere (I forget where): "You don't need to learn Category Theory in order to learn Haskell. Learn Haskell, and you'll develop an intuition for Category Theory as a side-effect."

I think the best "Monad tutorial" is Learn You A Haskell For Great Good[1], in its entirety.

[1]: http://learnyouahaskell.com/

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.