3 ms·
(The problem, in fact, is that the significance of monads in Haskell in terms of the side-effect model has nothing to do with category theory. The "side-effects
by rmrfrmrf 8y ago
(The problem, in fact, is that the significance of monads in Haskell in terms of the side-effect model has nothing to do with category theory. The "side-effects" quite literally occur outside of these theoretical constructs.)
- danidiaz 8y agoThe laws are important though. They ensure that the "statement-like" things we build out of expressions do behave like statements. For example, it would be weird if we had three statements A B C that wrote to console, and sequencing A with B and then sequencing the result with C resulted in a different program than sequencing B with C and then sequencing A with the result. Or, for non-IO things: it would be weird if we had three levels of nested lists, and concatenating two times "from the outside" resulted in a different list than concatenating each inner list first, and then the outer list.
- zozbot123 8y agoOn the contrary, the significance has everything to do with the category-theoretical pattern, albeit the reasoning for that is not immediately obvious and has to do with a further category-theoretical tool known as the Kleisli category. A monad with no enforced "outside" structure is known as a free monad, and is basically the equivalent of what most people outside FP call the Command pattern (or rather, a well-behaved version thereof). And "Commands" have everything to do with specifying side effects!
- pwm 8y agoThe historical context helps here. Monads came to Haskell to deal with IO. Once there, people realised that a whole host of things are monads under the hood, most of which are pure. The word "effectful", somewhat confusingly, is often used for applicative/monadic code that is in fact pure under the hood. A good example is the State monad which does not mutate state in any way, it's completely pure computation that happens to model state.
- mormegil 8y agoIn other words, IO Monad Considered Harmful. https://blog.jle.im/entry/io-monad-considered-harmful.html https://blog.jle.im/entry/io-monad-considered-harmful.html