> I thought one big selling argument of monads was also that the type of
> the functions shows which effect it performs. As I understand it, it
> is not the case for effects, at least not in existing implementations
> like multicore ocaml. ... Also, would you know a reference that shows
> that effects compose indeed a lot more easily than monads?
How expressive are the types of effectful computations pretty much
depends on a particular type system in use. Let me cite from the message
that I received from Nick Palladinos (CCed) the other week, who implemented
extensible effects in F#, a rather close relative of OCaml. You can
write the code as below
let example () =
eff {
do! put 1
let! x = get ()
let! y = ask ()
return x + y
}
(Here, `eff' is a tag of so-called computational expressions of F#, a
very handy feature).
The *inferred* type is as follows
val example : unit -> Eff<'U,int> when 'U :> Reader<int> and 'U :> State<int>
clearly stating that example is an effectful expression that uses at
least Reader and State effects. The example also illustrates
composability, your second question: put/get and ask are operations of two
distinct effects (State and Reader, resp). You can combine them freely
within the same program.
(I hope Nick will write a paper explaining his implementation so that
we can all learn from it.)
To give more references (in addition to Leo's work), I should point to Koka
https://koka-lang.github.io/koka/doc/kokaspec.html
which is an OCaml-like language based on effects and
effect-typing. The language is mature enough to write a web server in
it (as Daan Leijen described in his talk at the ML Family workshop
this year).
Other references are the recent Effekt library in Scala
http://b-studios.de/scala-effekt/
and extensible-effect library
http://okmij.org/ftp/Haskell/extensible/
which, although being first proposed for Haskell has also been ported
to Scala (and now F#). Purescript's extensible effects are also
similar.