[erlang-questions] Re: Concept of Side-effect
Masklinn
masklinn@REDACTED
Fri Sep 18 15:01:57 CEST 2009
On 18 Sep 2009, at 11:48 , Ulf Wiger wrote:
> 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.
>
Very much so, but I didn't want to delve too deep into it as I don't
have a very good knowledge of Haskell's STM.
> 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.
It handles many things going far beyond mere side-effects using monads
(Haskell's lists are monads for example, and so is its option type
Maybe, which has pretty nice properties), but yes Haskell does use
monads quite a lot to segregate side-effecting code from "pure" code
(and has various monad types for various kinds of side-effects to
ensure "incompatible" side-effects -- such as transactions & IO --
can't be interleaved)
More information about the erlang-questions
mailing list