Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nice idea, but that must be the worst explanation of monads I've seen so far :)


Can you recommend a good one? I've read several but still don't get it. And I hardly have time to write code to learn it like people say is necessary.


I think most people would need to write some code to really grok it, I would anyway. It's a simple enough idea in context, but there's no royal road to understanding.

The explanations I know of (all from the Haskell community) are either

1) formal, referring to ideas from category theory,

2) metaphorical, conveying the ideas by intuitions you may already have about burritos or whatever, or

3) pragmatic, focused on how and why you use them in code.

I think this last category, pioneered by byorgey's wonderful TypeClassopedia [1], is by far the most useful in teaching people about monads but it depends on observing them yourself. (Ditching the metaphors actually seemed quite radical to me at the time -- I presumed they were necessary because everyone else did.) It builds up from understanding what a Functor is, then the next abstraction up, and so on until Monads seem like an obvious idea. The same approach is used in Learn You a Haskell for Great Good [2] but you need to doing the exercises to follow the book. sigfpe's classic explanation [3] is also by example and goes into a bit more depth. It still contains exercises for the reader though :)

[1] https://wiki.haskell.org/Typeclassopedia

[2] http://learnyouahaskell.com/functors-applicative-functors-an...

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


I like how mpj explains it. Monad - FunFunFunction #21 https://www.youtube.com/watch?v=9QveBbn7t_c

Furthermore, the creator of Elm has a fun explanation too. Evan Czaplicki - Let's be mainstream! User focused design in Elm - Curry On https://youtu.be/oYk8CKH7OhE?t=1454

More serious computer scientist explains monads in the following. Erik Meijer: Functional Programming https://www.youtube.com/watch?v=z0N1aZ6SnBk&feature=youtu.be... and here too https://www.infoq.com/interviews/meijer-monads


  Can you recommend a good one? ... I hardly have time to 
  write code to learn it like people say is necessary.
The _easiest_ way to learn monads is through code (in haskell they're just a tricky typeclass: http://dev.stephendiehl.com/hask/#eightfold-path-to-monad-sa...) If you don't want to write code you could learn them like a mathematician from first principles (https://en.wikipedia.org/wiki/Monad_(category_theory)), but that seems so much harder to me I'm not sure why you would.


Is there a non-haskell resource on monads you could recommend? Anything that starts with "first, learn haskell" is probably not the easiest way, assertions from people who already know haskell notwithstanding.


Great point! I found this for python: https://www.stephanboyer.com/post/9/monads-part-1-a-design-p..., but it definitely focuses more on explanation than practical use. A list of "how to practice with monads in various languages" would be a neat thing to have.


Precious few mathematicians ever learn what monads are...


If you use JS, if you get how Promises work your probably 90% of the way there; abstracting that pattern out to use in other contexts will probably get you the rest of the way.


Here's one from LYAH: http://www.learnyouahaskell.com/a-fistful-of-monads

There are a couple of other links here [0] including "Don't fear the Monad" by Brian Beckman.

[0] https://github.com/0xmohit/talks


My favorite:

You could have invented monads (and maybe you already have) [1]

[1] https://news.ycombinator.com/item?id=958789




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: