an erlang monad?

Ulf Wiger (AL/EAB) ulf.wiger@REDACTED
Thu Mar 3 11:30:40 CET 2005


One problem with the with/2 is that is not obvious how to 
pass intermediate results to the next function without having
to put everything in the dictionary.

This is how I decided to do it, after tiring once more of 
constantly renumbering variables:

    Dict1 =
	with(
	  Dict,
	  [fun(D) ->
		   {_BeforeApp, _Dict1} = pickup_key(before, App, D)
	   end,
	   fun({BeforeApp, D}) ->
		   {RequiredBy, Dict1} = pickup_key(required_by, App, D),
		   {BeforeApp, RequiredBy, Dict1}
	   end,
	   fun({BeforeApp, RequiredBy, D}) ->
		   dict:store(App, #info{waitfor = BeforeApp ++ Apps,
                                     required_by = RequiredBy,
                                     requires = Apps}, D)
	   end,
	   fun(D) ->
		   enter_key(required_by, Apps,
			     fun(#info{required_by = RB} = I) ->
				     I#info{required_by = [App|RB]}
			     end, App, D)
	   end,
	   fun(D) ->
		   case Ps of
		       undefined ->
			   D;
		       Phases when is_list(Phases) ->
			   load_phases(Phases, App, D)
		   end
	   end]),
       {reply, ok, S#state{dict = Dict1}};

On a beauty scale of 1-10, it's definitely not a 10.
But I don't think it's all that bad either.

/Uffe

> -----Original Message-----
> From: owner-erlang-questions@REDACTED
> [mailto:owner-erlang-questions@REDACTED]On Behalf Of Vlad Dumitrescu
> Sent: den 3 mars 2005 08:42
> To: erlang-questions@REDACTED
> Subject: Re: an erlang monad?
> 
> 
> Hi,
> 
> Just a thought about this.
> 
> It is important to be able to access the state even somewhere 
> in-between the
> sequence, and it should be easy to do so too.
> 
> The reasons are two:
>   * one may need this state later on (I almost never have 
> more than 3 levels
> where the intermediary state isn't needed)
>   * easily inserting (and removing) debugging traces is very 
> useful for finding
> out what went wrong.
> 
> regards,
> Vlad
> 



More information about the erlang-questions mailing list