IORef
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 carrier for
Accum effects. This carrier performs its append
operations strictly and thus avoids the space leaks inherent in lazy
writer monads. These appends are left-associative; as such,
[] is a poor choice of monoid for computations that entail
many calls to
add. The
Seq or
DList monoids may
be a superior choice. This carrier also uses an
IORef to store
its accumulator, which allows it a
MonadUnliftIO instance, but
precludes backtracking when run in conjunction with
NonDet.
A carrier for the
State effect. It uses an
IORef
internally to handle its state, and thus admits a
MonadUnliftIO
instance. Because the state operations are performed impurely, this
carrier will not lose state effects even with nefarious uses of
liftWith.
Unlike the other carriers for
State, this carrier's effects
will not backtrack when run in conjuction with
NonDet effects.
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.