| ||Ask HN: Are Monads Really That Hard?|
6 points by biscarch 1600 days ago | hide | past | web | 8 comments | favorite |
|I've been experiencing something lately. I don't understand the difficulty of monads. So here I present my understanding of Monads in the hope that someone will be able to point me in the right direction, or at least point out something that I'm missing.|
* Monads Hide Failure (kinda)
Monads allow you to call a function that may or may not (Maybe/Just/Nothing) return the value you need in the next function. If Nothing is returned, you can pass Nothing through your future function calls or composed functions with no ill effects.
* Nesting Monads
You can nest Monads, or use do notation, to create easily replaceable failure possible sections of code.
someMonadicFunction and someOtherMonadicFunction can be anything that returns Nothing or Integer and it doesn't matter if they fail because the do will return Nothing in that case.
foo :: Maybe Integer
foo = do
x <- someMonadicFunction
y <- someOtherMonadicFunction
Just (x + y)
I keep reading about how Monads are a really hard topic, so I think it's possible that I'm not looking at the right pieces here.
So my question is, where do I go from here? Do I understand Monads, or am I missing something here?
| Apply to YC