3 ms·
"Monads embody the concept of "chaining" functions." No, it doesn't. Monad implementations may call the provided function zero times, or multiple times. Chaini
by jerf 2y ago
"Monads embody the concept of "chaining" functions."
No, it doesn't. Monad implementations may call the provided function zero times, or multiple times. Chaining implies exactly once, one of the common misconceptions about the monad interface.
Flatmap is another common attractive nuisance; flatmap is the monad implementation for lists but is not "monad" in general, any more than "an iterator on linked lists" is "iterator" in general.
- chuckadams 2y agoChaining implies sticking one function to another, with the implication that some data is being threaded through them. Whatever extra semantics go on top of that are gravy, it's a vague term for a vague concept. I even gave examples where the function might be invoked zero times (Maybe) or multiple times (List). And in some languages (I specifically mention one) flatmap is a function on all monads, not just lists.
- jerf 2y agoIf you understand it correctly, then use correct terms to describe it. And I don't mean the mathematically correct pristine words that some particular FP language uses, I mean, terms that will create correct impressions in the audience and not incorrect ones. You don't help by using the most commonly misunderstood terms and reinforcing the widespread misconceptions about how it works. Both "flatmap" and "chaining" create completely wrong impressions. You just leave people having to clear out the misunderstandings to get to the real and not really that complicated truth.
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]
- chuckadams 2y agoFeel free to jump in with your corrections or suggestions for more appropriate phrasing then instead of sniping at my terminology. I'm done.