Hacker News new | ask | show | jobs
by mattgreenrocks 4406 days ago
Disclaimer: still reckoning with monads.

The explanation is better than most I've seen, but it also feels a bit too reductive. IO is probably the best way to start understanding monads (futures also helped), but this idea of decorating instructions means you can do things like implement your own exception handling mechanism if need be. Lingual features of this scope usually aren't given to users, excepting a Lisp.

The hard part for me is grappling with how abstract a monad is. To this end, it almost seems easier to observe the uses of them rather than trying to fit them in a box (for now). Every explanation I read on them now sheds a bit more light on them, so it's just a matter of time and persistence.

1 comments

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