Mutable variable: Difference between revisions
(add StateVar) |
m (corrected order) |
||
Line 6: | Line 6: | ||
* {{HackagePackage|id=ArrayRef}}, module <hask>Data.Ref.Universal</hask> | * {{HackagePackage|id=ArrayRef}}, module <hask>Data.Ref.Universal</hask> | ||
* {{HackagePackage|id=binding-core}}, module <hask>Data.Variable</hask> | * {{HackagePackage|id=binding-core}}, module <hask>Data.Variable</hask> | ||
* {{HackagePackage|id=monad-statevar}} | * {{HackagePackage|id=monad-statevar}} | ||
* {{HackagePackage|id=ref-fd}} | * {{HackagePackage|id=ref-fd}} | ||
Line 13: | Line 12: | ||
* {{HackagePackage|id=reference}} | * {{HackagePackage|id=reference}} | ||
* {{HackagePackage|id=stateref}} | * {{HackagePackage|id=stateref}} | ||
* {{HackagePackage|id=StateVar}} | |||
== See also == | == See also == |
Revision as of 18:11, 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):
- ArrayRef, module
Data.Ref.Universal
- binding-core, module
Data.Variable
- monad-statevar
- ref-fd
- ref-tf
- ref-mtl
- reference
- stateref
- StateVar
See also
- Haskell Libraries mailing list on "suggestion: A common type class for mutable variables" in May and June, 2013
- Library/ArrayRef
- A unified interface to mutable variables as an example for Multi-parameter type classes