Diego Dainese wrote:
| there no way to move smoothly from no monad (no
| interaction), to one monad (a single form of
| interaction), to many monad (several independent forms
| of interaction).
It takes some work to move from no monad to using a monad,
but once you have made that decision, it is easy to equip
that monad with more features without having to change your
program very much.
| - IO
| - ST
| - Maybe (modeling exception)
| - List (modeling nondeterminism)
Take a look at:
http://www.cse.ogi.edu/~andy/monads/
There are a number of monads. Common monads you left out are
"reader" monads (monads which distribute an environment to
every sub-computation) and "writer" monads (monads which
collect output from every subcomputation).
One kind of monad that many people seem to be forgetting
when talking about monads is expression trees. Here is an
example:
data Expr a
= Var a
| Expr a :+: Expr a
| Int Int
This is, surprisingly, a monad! (The original categorical
definition is motivated by these kinds of monads, if I
recall correctly.)
To demonstrate this, we have to define a "unit" and "bind"
for Expr. "unit" introduces a variable, and "bind" is just
substitution!
instance Monad Expr where
return x = Var x
Var x >>= subst = subst x
(a :+: b) >>= subst = (a >>= subst) :+: (b >>= subst)
Int n >>= subst = Int n
Regards,
Koen.
PS. Moved the discussion to haskell-cafe
--
Koen Claessen http://www.cs.chalmers.se/~koen
phone:+46-31-772 5424 mailto:[EMAIL PROTECTED]
-----------------------------------------------------
Chalmers University of Technology, Gothenburg, Sweden