2 ms·
Monads are popular for side effects because they have an implicit notion of sequencing, so evaluating a monadic expression enforces the sequence of operations.
by chuckadams 6mo ago
Monads are popular for side effects because they have an implicit notion of sequencing, so evaluating a monadic expression enforces the sequence of operations. Works out nice for IO and Futures and so on. But List is also a monad, and flatMap (as many other languages call it) doesn't inherently have any side effects at all. Same goes for Maybe/Option (essentially a list of zero or one element), and State (which does take advantage of sequencing).
It's all about getting an intuition for how many things fit the shape:
flatMap :: m a -> (a -> m b) -> m b
Where "flatMap" might have different names in different types. Once you see that pattern in some code, you'll start seeing it in a lot of other places.