Ask HN: Are Monads Really That Hard?

https://news.ycombinator.com/item?id=4768477
by biscarch • 14 years ago
6 8 14 years ago

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.

    foo :: Maybe Integer
    foo = do
        x <- someMonadicFunction
        y <- someOtherMonadicFunction
        Just (x + y)
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.

# End

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?

Related Stories

Loading related stories...

Source preview

news.ycombinator.com