How do functional languages model side-effects?

Viewed 6277

Since side-effects break referential transparency, don't they go against the point of functional languages?

4 Answers

Since side-effects break referential transparency, don't they go against the point of functional languages?

It depends on the functional language:

  • Standard ML allows the liberal use of side-effects like most procedural languages e.g. Fortran, Algol, Pascal, C, etc.

  • Haskell restricts side-effects through the use of abstract data types like IO, ST and STM, which helps to preserve referential transparency.

  • Clean also restricts side-effects, but does this with its extended type system.

  • The functional language Coq uses - Gallina - provides no access to side-effects at all.


How do functional languages model side-effects?

One approach which isn't regularly mentioned relies on pseudo-data: individual single-use abstract values conveyed in an accessible structured value (commonly a tree), with the side effects only occuring when each abstract value is initially used. For more information, see F. Warren Burton's Nondeterminism with Referential Transparency in Functional Programming Language. An working example can also be found in GHC: its Unique name-suppy type.

Related