4 ms·
I have always thought that monads are just side effects and that's it.
by ReptileMan 6mo ago
I have always thought that monads are just side effects and that's it.
- hocuspocus 6mo agoMost monadic effects aren't executing side effects.
- lmm 6mo agoOn the contrary, every monadic effect is a side effect. It's just that what exactly that means is specific to the monad in question.
- chuckadams 6mo agoMonads 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.
- bazoom42 6mo agoNope. For example lists are monads, but doesn’t have anything to do with side-effects. Monads are just a pattern for chaining functions.