Personal tools

Mutable variable

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(initialized from mailing list)
 
(See also: example for Multi-parameter type classes)
Line 17: Line 17:
 
* Haskell Libraries mailing list on "suggestion: A common type class for mutable variables" in [http://www.haskell.org/pipermail/libraries/2013-May/020131.html May] and [http://www.haskell.org/pipermail/libraries/2013-June/020152.html June], 2013
 
* Haskell Libraries mailing list on "suggestion: A common type class for mutable variables" in [http://www.haskell.org/pipermail/libraries/2013-May/020131.html May] and [http://www.haskell.org/pipermail/libraries/2013-June/020152.html June], 2013
 
* [[Library/ArrayRef]]
 
* [[Library/ArrayRef]]
  +
* A unified interface to mutable variables as an example for [[Multi-parameter type class]]es
   
 
[[Category:Packages]]
 
[[Category:Packages]]

Revision as of 17:54, 3 June 2013

Although the functional programming paradigm emphasises the virtues of immutable variables, sometimes you need mutable variables nonetheless.

You can either simulate mutable variables using the state monad provided for instance by
Control.Monad.Trans.State
in the transformers package or you can use really mutable variables as provided by
Data.IORef
or
Data.STRef
or
Control.Concurrent.STM.TVar
from the stm package. In either case you need a monad in order to cope with mutability, while staying purely functional.

There are several packages that provide a single interface to these different implementations of mutable variables (in alphabetical order):

See also