an erlang monad?

Matthias Kretschmer <>
Fri Mar 4 09:16:45 CET 2005


On Thu, 3 Mar 2005 08:41:42 +0100
"Vlad Dumitrescu" <> wrote:

> 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

that's very easy with my monad implementation, but of course it has drawbacks: one always has to give around the monad-type (as with Haskell, where everything is packed into IO a, ST a or whatever). You can simply read the state anywhere where you are generating monadic values. This makes it very simple: just read the state, print it to screen and you're, done.

Just another thought:
Another way to makes this nicer would be to use other combinators that make life easier. E.g. something like (forgive the pseudo-code):

lift(Fun, [Action0, Action1, ...]) -->
apply(Fun, [X0, X1, ...] <- (X0 <- Action0 >>= X1 <- Action1 >>- ...))

where Action_n is of course a monad-value. This would make it easier to write good looking code without using a parse_transform'er. The drawback is, that one is loosing some power if one is only using this lift function (this would be more a arrow-style combinator), because Action_n doesn't know of the outcome of Action_1 to Action_{n-1} and can't decide what to do depending on their outcome.

--
Matthias Kretschmer



More information about the erlang-questions mailing list