Without even defining any instances of these classes,
we can give simple examples to illustrate how they work
in practice. The expression at the top of this slides
is a short program, written in monadic style using the
donotation, and using the "new", "get" and "set" operations
from the previous slide. The second half of the slide shows
the type of this expression, which is calculated
automatically by the standard type inference algorithm for
Haskell. We can see three distinct elements here: the monad
in which the computation takes place; the type of the result
that it produces; and, most interestingly, an inferred
collection of effects. In the past, some people have
developed whole type systems just to information like
this about effects. Here, we are able to use existing
and wellunderstood mechanisms for type inference to achieve
the same result. Moreover, we can also take advantage of
properties of that algorithm about soundness and existence
of principal types. Note, for example, that there are two
separate region variables "r1" and "r2" in the type here,
reflecting the fact that, in general, the two reference
cells bound to "x" and "y" could be allocated in separate
regions.
Next...
