There are many perspectives one can use to understand Monads. The operational one is valid - and useful for many beginners. Of course, it's not the only way to look at them, as you point out.
There are many perspectives one can use to understand Monads. The operational one is valid - and useful for many beginners. Of course, it's not the only way to look at them, as you point out.
Meanwhile I find monads very useful in Scala, even without any laziness in sight.
> Meanwhile I find monads very useful in Scala, even without any laziness in sight.
But do you use monads for all the things Haskell programmers use them for? Or only a subset of those things?
Almost all projects end up needing to care about performance at some point or other, if only a little. (So yes, Haskell is probably not a suitable language for most projects, sadly)
> But do you use monads for all the things Haskell programmers use them for? Or only a subset of those things?
All the things, as far as I'm aware. Certainly the obvious ones like IO.
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`)
(I believe there are good reasons you would want to use monads, but only from a denotational perspective, not an operational one)
This is in contrast to Haskell that uses monads to declare the computation graph (well, functions, but monads are under discussion here). In this world, data is computed lazily as needed. The questions you ask about the code center around functions and their dependencies, not necessarily computation order.
A task that is trivial to express with on paradigm might be non-trivial to express on the other: haskell is excellent about expressing lazy computation and side effects, whereas a CSP language will offer easy reasoning about the specific and correct order of execution.
Note I am not a PL expert, just an enthusiast. My diction may be off for the domain.
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.673...