[erlang-questions] My biggest beef with Erlang

Torbjorn Tornkvist tobbe@REDACTED
Tue Nov 27 13:31:50 CET 2007

Christian S wrote:
> 2007/11/27, Robert Virding <rvirding@REDACTED>:
>> I actually defy anyone to come up with a safe, consistent and
>> *understandable* definition of guards which allow user defined functions. It
>> would also be nice if they were relatively easy to implement. Joe, remember
>> our ideas with pipes?
> Are not monads the proven way to constraint what side-effects a
> function is allowed to have? I'm not particularly excited about Erlang
> requiring Monads, but they do seem to be the way to help the compiler
> with static analysis of side-effects. Loadable code makes the problem
> more difficult for Erlang though.

He he, I recently wrote this little function:

%%% Example: monad([in(Key1,Val1), in(Key2,Val2)], empty())
monad([], Data)    -> Data;
monad([H|T], Data) -> monad(T, H(Data)).

in(Key, Value) ->
  fun(Data) -> in(Key, Value, Data) end.

in(Key, Value, Data) ->
    gb_trees:enter(Key, Value, Data).

This way you can 'thread' the 'environment/DB' through
a number of access functions in a compact manner.


More information about the erlang-questions mailing list