monads in Erlang?

Ulf Wiger <>
Thu Feb 20 10:08:02 CET 2003


On Thu, 20 Feb 2003, Peter-Henry Mander wrote:

>Good morning everyone,
>
>I've stumbled across monads[1] and their use in Haskell[2],
>and they seem very useful. Not being a computer scientist
>as such (I studied cybernetics and comp.sci. jointly), only
>an engineer, I didn't know of them until now. I tried to
>find an equivalent example in Erlang, but a quick search
>found nothing. Can anyone here enlighten me further?
>
>Pete.
>
>[1] http://www.dcs.gla.ac.uk/~nww/Monad.html
>[2] http://www.haskell.org

I'm no computer scientist either, so the CS scholars of
this list may feel free to correct me if I'm wrong. (:

I think monads could probably be added to Erlang, but the
gains would not be as obvious as in Haskell. I'm also not
quite sure if the lack of currying will prevent an elegant
implementation of monads.

Erlang has an explicit side effect: message passing (all
other side effects could be described using processes and
message passing, even if they're not implemented that way
today.) This means that Erlang is based on an assumption
that it will never be - as a whole - referentially
transparent. The Erlang alternative then to e.g. Monadic IO
is to not care about it. Side effects are allowed in Erlang,
and there is no requirement that functions be soundly and
strictly typed.

The issues of combinators and state threading are supported
in Erlang through funs and iterator functions like fold,
map, etc. Monads offer a cleaner foundation for it, but I'm
not sure the difference in Erlang would be dramatic, as you
rely on dynamic typing, and thus have no requirement for
sane type specifications of functions.

Using lots of processes, the state of an application is
broken into lots of small pieces. ETS tables (which could be
modeled using processes and message passing) allow for
further division into lots of small states. This alleviates
the need for combinators and state threading, even though
they're still useful.

My feeling is that Monads can serve as a foundation for
concurrency, IO, and other things. Thus you could build
something rather similar to Erlang in Haskell (and they
almost have: Concurrent Haskell) using Monads. That may be
the best way to marry "Erlang with Monads". (:

/Uffe
-- 
Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson AB, Connectivity and Control Nodes




More information about the erlang-questions mailing list