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.
Let’s steel-man the parent comment. Obviously “just following orders” is not generally a morally sufficient argument even if you end up not facing repercussions for your actions.
To be fair, that’s the recommended way to put out an alkali metal fire. At least according to my grandfather who helped write safety regulations for nuclear subs whose reactors were cooled by liquid sodium.
Not really something I’d want to try out in practice, seems like a fire in a nuclear reactor under the ocean, where the source of the fire explodes on contact with water, is a less-than-ideal situation.
reply