[erlang-questions] Monads in Erlang?

Malcolm Dowse malcolm@REDACTED
Fri Mar 20 16:19:56 CET 2009

On Thu, Mar 19, 2009 at 4:40 PM, Robert Raschke <rtrlists@REDACTED>wrote:

> Hi,
> all this very interesting discussion about patterns and state carrying
> from one expression to the next makes me think a lot of state monads.
> I've never really delved into Haskell all too deeply (it's on my list
> of things to learn much more of), but would some of the objections and
> issues to do with numbered "state patterns" be addressed by something
> similar to state monads? I'm guessing that tuple patterns involving
> atoms as signifiers for results make this tricky, but maybe someone
> has thought about this in more detail?

I haven't thought that hard about it, but it I do know a bit about Haskell.

Unlike Richard, I personally don't think that there is a very strong case
for trying to add monads to Erlang, because Erlang is such a different
language to Haskell.

Haskell is a language very much concerned about elegant semantics, but the
upshot of that is that understanding efficiency issues become very hard.
Monads were introduced to solve many of these problems. The ST monad allows
you to manage large datastructures destructively, ensuring that they will be
garbage collected - if computers had limitless CPU and RAM, it wouldn't be
needed. The IO monad handles all I/O, non-determinism, concurrency; all the
more messy, unpredictable areas of language behaviour are confined to the IO
monad. So, in my opinion, monads were not really added into Haskell to make
it more elegant. They were instead added to make it much more practical,
without poisoning the elegance of the rest of the language.

But Erlang is totally different. It is already, at its heart, a really
practical language. With a strict reduction order, managing datastructures
efficiently is straighforward enough, and side-effecting is everywhere, so
you're not trying to protect the rest of the language from "impure"

Much of the discussion about state handling was about syntax. But although
there is a special imperative-like syntax for monadic programming in
Haskell, that's not really the point of monads. The internal state variable
*has* to be hidden for reasons related to Haskell's static type system, as
is the case for I/O. (The Clean language, closely related to Haskell, uses a
different type system, where there's actually a variable usually called
"World" which is explicitly passed around when doing I/O)

So, in my opinion, if you were to add monads into Erlang, you would just get
a monad-like syntax, without any other benefits. And it's debatable whether
this is really an improvement - it's more concise, but at the same time,
more is hidden from view.

kind regards,


> Robby
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090320/333df87b/attachment.htm>

More information about the erlang-questions mailing list