[erlang-questions] Re: Concept of Side-effect

Ulf Wiger <>
Fri Sep 18 11:48:39 CEST 2009


Masklinn wrote:
> 
> Not so. The inner fun() executes within a transactional context (that of 
> mnesia) and only uses functions relative to that context, which means 
> the context manager can handle errors & retries gracefully.

Associating freely and spinning the whole thing into
a much more abstract sphere, mnesia transactions are
in some ways similar to Transaction Monads in Haskell,
except in Haskell, the compiler can actually enforce
these things for you.

Haskell is special in that it identifies side effects
as a very special operation, with its own type.
It handles side effects using a special construct,
called the monad. This scares the life out of most
people, but allows Haskell programmers to apply a
whole set of sound laws on expressions that contain
side effects, and determine, e.g. if different expressions
containing side effects are equivalent.

This presentation from the ICFP Haskell workshop in Edinburgh,
given by "Oscar winner" Dan Piponi, is a wonderful attempt at
describing these monad laws in terms that mere mortals can
understand.

http://www.vimeo.com/6590617

Simon Peyton-Jones once said that they should have called
monads "warm fuzzy things" instead. Perhaps not, but at least,
many of the important aspects of monads can be illustrated
using warm fuzzy things.

Tying back to the initial question (and apologies for raising
it into the stratosphere), you could say that if you _do_
clearly separate pure logic from side effects, and you do it
right, infinite power lies within your reach. :)

BR,
Ulf W
-- 
Ulf Wiger
CTO, Erlang Training & Consulting Ltd
http://www.erlang-consulting.com


More information about the erlang-questions mailing list