views:

142

answers:

3

At the moment I'm aware of the following methods to integrate side-effects into purely functional programming languages:

  • effect systems
  • continuations
  • unique types
  • monads

Monads are often cited to be the most effective and most general way to do this.

Which other methods exist? How do they compare?

+2  A: 

Arrows, which are more general than monads.

Pavel Minaev
+1  A: 

The very simplest method is to simply pass around the environment between the functions. This is often used to teach scheme.

Imagist
A: 

To me a more general way is via a monad/comonad pair. This generalizes the common "monad" approach which should correctly be called the "strong monad" approach, since it only works with strong monads.

Moving to a monad/comonad pair allows effects to be modeled that result in some variables no longer being available. An example where this is useful is the effect of migrating a thread to another host in a distributed setting.

An additional method of historical interest is to make the whole program a function mapping a stream/list of input events to a stream/list of output events. See: "How to Declare an Imperative" by Phil Wadler: http://www.cs.bell-labs.com/~wadler/topics/monads.html#monadsdeclare

RD1