Hacker News new | past | comments | ask | show | jobs | submit login

Great comment.

I think you are hitting the issue with monads tutorials. Most tutorials focus (or at that's where the reader will linger) on the flatMap "interface" and the box-or-container-of-things while mentioning monads laws only in passing.

So the reader is left wondering what's the big deal with an IFlatMappable interface other than, yes, it is a common pattern seen in the wild.

But the real power are the laws and the transformations. I suspect that for most procedural (with a sprinkle of FP) code those laws probably don't give you much, and if really needed the programmer might just derive the the specific transformation by local reasoning. An initiate of the FP arts will have internalized the transformations and will structure their code to take advantage of them as much as possible.

I say this as a boring procedural programmer that most definitely has not internalized monad laws.

As an aside, is it possible to further generalize monads and allow flatMap to interoperate with any monad instead of the same monad of its input? For example here the internal flatmap function might return an optional instead:

   [1, 2, 3].flatMap(x => [x + 1].flatMap(x => x < 4 ? Just(x) : None))



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

Search: