Data.Primitive.MutVar

primitive-0.6.1.0: Primitive memory-related operations

Copyright | (c) Justin Bonnar 2011, Roman Leshchinskiy 2011-2012
License | BSD-style
Maintainer | Roman Leshchinskiy <rl@cse.unsw.edu.au>
Portability | non-portable
Safe Haskell | None
Language | Haskell2010

Data.Primitive.MutVar

Description

Primitive boxed mutable variables

Synopsis

- data MutVar s a = MutVar (MutVar# s a)
- newMutVar :: PrimMonad m => a -> m (MutVar (PrimState m) a)
- readMutVar :: PrimMonad m => MutVar (PrimState m) a -> m a
- writeMutVar :: PrimMonad m => MutVar (PrimState m) a -> a -> m ()
- atomicModifyMutVar :: PrimMonad m => MutVar (PrimState m) a -> (a -> (a, b)) -> m b
- atomicModifyMutVar' :: PrimMonad m => MutVar (PrimState m) a -> (a -> (a, b)) -> m b
- modifyMutVar :: PrimMonad m => MutVar (PrimState m) a -> (a -> a) -> m ()
- modifyMutVar' :: PrimMonad m => MutVar (PrimState m) a -> (a -> a) -> m ()

# Documentation

data MutVar s a

A `MutVar` behaves like a single-element mutable array associated with a primitive state token.

Constructors

MutVar (MutVar# s a) |

Instances

Eq (MutVar s a) |

newMutVar :: PrimMonad m => a -> m (MutVar (PrimState m) a)

Create a new `MutVar` with the specified initial value

readMutVar :: PrimMonad m => MutVar (PrimState m) a -> m a

Read the value of a `MutVar`

writeMutVar :: PrimMonad m => MutVar (PrimState m) a -> a -> m ()

Write a new value into a `MutVar`

atomicModifyMutVar :: PrimMonad m => MutVar (PrimState m) a -> (a -> (a, b)) -> m b

Atomically mutate the contents of a `MutVar`

atomicModifyMutVar' :: PrimMonad m => MutVar (PrimState m) a -> (a -> (a, b)) -> m b

Strict version of `atomicModifyMutVar`. This forces both the value stored in the `MutVar` as well as the value returned.

modifyMutVar :: PrimMonad m => MutVar (PrimState m) a -> (a -> a) -> m ()

Mutate the contents of a `MutVar`

modifyMutVar' :: PrimMonad m => MutVar (PrimState m) a -> (a -> a) -> m ()

Strict version of `modifyMutVar`