Hacker News new | ask | show | jobs
by groovy2shoes 4408 days ago
This is hands-down the best introduction to monads:

http://blog.sigfpe.com/2006/08/you-could-have-invented-monad...

It starts with some motivation, then gives some specific examples, then generalizes to monads. It gave me a TON of insight about monads when I was first starting out, and I'm genuinely surprised that it doesn't get mentioned every time the monad discussion comes up.

Monads are so difficult to approach because they're so abstract and general -- all the theory in the world won't help you understand how they're useful. Once you've got the basics, the only way to grok monads is to use them. The IO monad alone is a good start but it's not enough. Try using a bunch of them to get a feel for what they have in common. The Maybe and Error monads come in handy a lot.

While most tutorials introduce monads with return and bind, monads can also be characterized by fmap and join. I'd recommend learning about that as the next step towards monad enlightenment. It helped to give me more insight into what a monad is, conceptually speaking. It's not strictly necessary but I found it interesting and helpful.

As an aside, if you find yourself struggling with Applicative Functors, try playing around with Elm [1] (Signals are applicative functors, and the <~ and ~ operators are the same as Haskell's <$> and <*> operators). That's what did it for me :)

[1]: http://elm-lang.org/Elm.elm