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

@hintymad thanks for sharing! For me, monads seemed hugely difficult to learn, and so I never got started with them at all. Had I just known that they were not as hard as I thought they were (which I think is different from not hard) I might have started earlier. I’m hoping that by sharing some of my understandings I can help people avoid some of my own hesitation.

What I really like about the HN community is the notion of shipping even if you’re embarrassed by it, because the future good or bad is built by the people who show up.



It only seems not-hard for people that already understand them. Here's where the post shows just how simple monads can be.

> A monad is a data type (e.g. int) that encapsulates some control flow (e.g. try/catch).

But... I'm already lost. How would an integer "encapsulate" control flow? Like different integer values would represent different errors that could occur? Or you could use integers as a representation for a language that has try/catch as a feature? Even in this simplest case, if you don't already grok monads, it's somehow not illuminating for me. YMMV


that's just poor wording -- the first example wasn't supposed to be linked to the second example;

A better sentence is probably

A monad is a datatype (e.g. Either<T,U>) that encapsulates some control flow (e.g. if T != null return T else U)

if I understand it correctly




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

Search: