[Haskell-cafe] Tutorial: Haskell for the Evil Genius
Tillmann Rendel
rendel at informatik.uni-marburg.de
Sun Sep 16 16:48:50 CEST 2012
Hi,
Kristopher Micinski wrote:
> Everyone in the Haskell cafe probably has a secret dream to give the
> best "five minute monad talk."
(1) Most programming languages support side effects. There are different
kinds of side effects such as accessing mutable variables, reading
files, running in parallel, raising exceptions, nondeterministically
returning more than one answer, and many more. Most languages have some
of these effects built into their semantics, and do not support the
others at all.
(2) Haskell is pure, so it doesn't support any side effects. Instead,
when Haskell programmers want to perform a side effect, they explicitly
construct a description of the side effecting computation as a value.
For every group of related side effects, there is a Haskell type that
describes computations that can have that group of side effects.
(3) Some of these types are built in, such as IO for accessing the world
outside the processor and ST for accessing local mutable variables.
Other such types are defined in Haskell libraries, such as for
computations that can fail and for computations that can return multiple
answers. Application programmers often define their own types for the
side effects they need to describe, tailoring the language to their needs.
(4) All computation types have a common interface for operations that
are independent of the exact side effects performed. Some functions work
with arbitrary computations, just using this interface. For example, we
can compose a computation with itself in order to run it twice. Such
generic operations are highly reusable.
(5) The common interface for constructing computations is called
"Monad". It is inspired by the mathematical theory that some computer
scientists use when they describe what exactly the semantics of a
programming language with side effects is. So most other languages
support some monad natively without the programmer ever noticing,
whereas Haskell programmers can choose (and even implement) exactly the
monads they want. This makes Haskell a very good language for side
effecting computation.
Tillmann
More information about the Haskell-Cafe
mailing list