3 ms·
Most monads I'm aware of have an operational interpretation. The `Maybe` (or `Option`) monad, for instance, has the single effect fail :: Maybe a fail = N
by alipang 8y ago
Most monads I'm aware of have an operational interpretation.
The `Maybe` (or `Option`) monad, for instance, has the single effect
fail :: Maybe a
fail = Nothing
as soon as `fail` is "evaluated". Evaluation here is in the monadic sense - and is not related to the evaluation strategy of the host language.
List monads have a non-determinism operational interpretation. The `State`, `Writer` and `Continuation` monads obviously do as well.
You could say the `Reader` monad has the single effect
ask :: Reader e e
but thinking about this operationally is certainly not that helpful as this returns a single constant value from the environemnt.
The same thing goes for `Free` which is essentially a data structure for the abstract syntax of Monads. However in some sense even for this part of you understanding of free monads is likely based in providing a natural transformation to an interpretation in another monad (i.e. `iterM`)
- lmm 8y agoLike I said, operational interpretations are valid, but they don't help explain why monads are useful, because if you only want the operational interpretation then why not build the operational functionality directly into the host language (particularly since most host languages already offer that kind of thing)? E.g. the operational version of Maybe/Option just seems like an overcomplicated version of exceptions - if all you want is a "fail" effect, why not just have it throw an exception and avoid all the extra monadic plumbing. (I believe there are good reasons you would want to use monads, but only from a denotational perspective, not an operational one)