IORef -package:fused-effects
Mutable references in the IO monad.
A mutable variable in the
IO monad.
>>> import GHC.Internal.Data.IORef
>>> r <- newIORef 0
>>> readIORef r
0
>>> writeIORef r 1
>>> readIORef r
1
>>> atomicWriteIORef r 2
>>> readIORef r
2
>>> modifyIORef' r (+ 1)
>>> readIORef r
3
>>> atomicModifyIORef' r (\a -> (a + 1, ()))
>>> readIORef r
4
See also
STRef and
MVar.
A mutable variable in the
IO monad.
>>> import GHC.Internal.Data.IORef
>>> r <- newIORef 0
>>> readIORef r
0
>>> writeIORef r 1
>>> readIORef r
1
>>> atomicWriteIORef r 2
>>> readIORef r
2
>>> modifyIORef' r (+ 1)
>>> readIORef r
3
>>> atomicModifyIORef' r (\a -> (a + 1, ()))
>>> readIORef r
4
See also
STRef and
MVar.
A mutable variable in the
IO monad.
>>> import Data.IORef
>>> r <- newIORef 0
>>> readIORef r
0
>>> writeIORef r 1
>>> readIORef r
1
>>> atomicWriteIORef r 2
>>> readIORef r
2
>>> modifyIORef' r (+ 1)
>>> readIORef r
3
>>> atomicModifyIORef' r (\a -> (a + 1, ()))
>>> readIORef r
4
See also
STRef and
MVar.
A mutable variable in the
IO monad
A mutable variable in the
IO monad.
>>> import Data.IORef
>>> r <- newIORef 0
>>> readIORef r
0
>>> writeIORef r 1
>>> readIORef r
1
>>> atomicWriteIORef r 2
>>> readIORef r
2
>>> modifyIORef' r (+ 1)
>>> readIORef r
3
>>> atomicModifyIORef' r (\a -> (a + 1, ()))
>>> readIORef r
4
See also
STRef and
MVar.
A mutable variable in a mutation capable monad (IO) holding a
Unboxed value. This allows fast modification because of
unboxed storage.
Multithread Consistency Notes
In general, any value that straddles a machine word cannot be
guaranteed to be consistently read from another thread without a lock.
GHC heap objects are always machine word aligned, therefore, a
IORef is also word aligned. On a 64-bit platform, writing a
64-bit aligned type from one thread and reading it from another thread
should give consistent old or new value. The same holds true for
32-bit values on a 32-bit platform.
Deprecated: Use IORef from MutByteArray module.
Utilities for Data.IORef.
Mutable references in a concurrency monad.
Deviations: There is no Eq instance for
MonadConc the IORef type. Furthermore, the
mkWeakIORef function is not provided.
Lifted
Data.IORef.
Note: it requires
Prim because
MutVar from the
primitive library is a generalization of
IORef.
Mutable references in the IO monad.
A strict (WHNF) variant of
IORef.