3 ms·
Just imagine C gave you the power to overload the semicolon operator. You could now write a series of expressions (separated by semicolons) to express other con
by chongli 13y ago
Just imagine C gave you the power to overload the semicolon operator. You could now write a series of expressions (separated by semicolons) to express other concepts (such as non-determinism, failure or state). This is scratching at the surface of what a monad does. It effectively allows you to define a context (with its own semantics) and gives you a set of powerful (overloaded) operators for working with values inside that context.
In Haskell, side effects are constrained to the IO monad. This allows one to see, at a glance, whether or not a particular function has the ability to perform side effects. In C, on the other hand, it could be said that all functions live in the IO monad and that no other monads exist. This makes it harder to reason about the behaviour of a function, as one does not know whether or not it will perform side effects.