[erlang-questions] Re: Concept of Side-effect
Fri Sep 18 11:48:39 CEST 2009
> 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
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. :)
CTO, Erlang Training & Consulting Ltd
More information about the erlang-questions