Methods for side-effects in purely functional programming languages

361 views Asked by At

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?

3

There are 3 answers

0
RD1 On

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

0
Pavel Minaev On

Arrows, which are more general than monads.

0
Imagist On

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