Safe Haskell | None |
---|---|
Language | Haskell2010 |
Classes and concrete implementations for mutable data structures.
For more information on the design of this library, see the README file, also available at http://www.stackage.org/package/mutable-containers.
- data PRef s a
- asPRef :: PRef s a -> PRef s a
- data URef s a
- asURef :: URef s a -> URef s a
- data SRef s a
- asSRef :: SRef s a -> SRef s a
- data BRef s a
- asBRef :: BRef s a -> BRef s a
- data IORef a :: * -> *
- asIORef :: IORef a -> IORef a
- data STRef s a :: * -> * -> *
- asSTRef :: STRef s a -> STRef s a
- data MutVar s a :: * -> * -> *
- asMutVar :: MutVar s a -> MutVar s a
- data Deque v s a
- type UDeque = Deque MVector
- asUDeque :: UDeque s a -> UDeque s a
- type SDeque = Deque MVector
- asSDeque :: SDeque s a -> SDeque s a
- type BDeque = Deque MVector
- asBDeque :: BDeque s a -> BDeque s a
- data DList s a
- asDList :: DList s a -> DList s a
- class MutableContainer c where
- type MCState c
- class MutableContainer c => MutableRef c where
- type RefElement c
- newRef :: (PrimMonad m, PrimState m ~ MCState c) => RefElement c -> m c
- readRef :: (PrimMonad m, PrimState m ~ MCState c) => c -> m (RefElement c)
- writeRef :: (PrimMonad m, PrimState m ~ MCState c) => c -> RefElement c -> m ()
- modifyRef :: (PrimMonad m, PrimState m ~ MCState c) => c -> (RefElement c -> RefElement c) -> m ()
- modifyRef' :: (PrimMonad m, PrimState m ~ MCState c) => c -> (RefElement c -> RefElement c) -> m ()
- class MutableRef c => MutableAtomicRef c where
- atomicModifyRef :: (PrimMonad m, PrimState m ~ MCState c) => c -> (RefElement c -> (RefElement c, a)) -> m a
- atomicModifyRef' :: (PrimMonad m, PrimState m ~ MCState c) => c -> (RefElement c -> (RefElement c, a)) -> m a
- class MutableContainer c => MutableCollection c where
- type CollElement c
- newColl :: (PrimMonad m, PrimState m ~ MCState c) => m c
- class MutableCollection c => MutablePushFront c where
- pushFront :: (PrimMonad m, PrimState m ~ MCState c) => c -> CollElement c -> m ()
- class MutableCollection c => MutablePushBack c where
- pushBack :: (PrimMonad m, PrimState m ~ MCState c) => c -> CollElement c -> m ()
- class MutableCollection c => MutablePopFront c where
- class MutableCollection c => MutablePopBack c where
- type MutableQueue c = (MutablePopFront c, MutablePushBack c)
- type MutableStack c = (MutablePopFront c, MutablePushFront c)
- type MutableDeque c = (MutableQueue c, MutablePushFront c, MutablePopBack c)
- class Monad m => PrimMonad m where
- type PrimState m :: *
- type family PrimState m :: *
- data RealWorld :: *
Data types
Single-cell mutable references
A primitive ByteArray reference, supporting any monad.
Since 0.2.0
Prim a => MutableRef (PRef s a) | |
MutableContainer (PRef s a) | |
type RefElement (PRef s a) = a | |
type MCState (PRef s a) = s |
An unboxed vector reference, supporting any monad.
Since 0.2.0
Unbox a => MutableRef (URef s a) | |
MutableContainer (URef s a) | |
type RefElement (URef s a) = a | |
type MCState (URef s a) = s |
A storable vector reference, supporting any monad.
Since 0.2.0
Storable a => MutableRef (SRef s a) | |
MutableContainer (SRef s a) | |
type RefElement (SRef s a) = a | |
type MCState (SRef s a) = s |
A boxed vector reference, supporting any monad.
Since 0.2.0
IsSequence seq => MutablePushBack (BRef s seq) | |
IsSequence seq => MutablePopBack (BRef s seq) | |
IsSequence seq => MutablePushFront (BRef s seq) | |
IsSequence seq => MutablePopFront (BRef s seq) | |
Monoid w => MutableCollection (BRef s w) | |
MutableRef (BRef s a) | |
MutableContainer (BRef s a) | |
type CollElement (BRef s w) = Element w | |
type RefElement (BRef s a) = a | |
type MCState (BRef s a) = s |
Standard re-exports
data IORef a :: * -> *
A mutable variable in the IO
monad
Eq (IORef a) | |
IsSequence a => MutablePushBack (IORef a) | |
IsSequence a => MutablePopBack (IORef a) | |
IsSequence a => MutablePushFront (IORef a) | |
IsSequence a => MutablePopFront (IORef a) | |
Monoid w => MutableCollection (IORef w) | |
MutableAtomicRef (IORef a) | |
MutableRef (IORef a) | |
MutableContainer (IORef a) | |
Typeable (* -> *) IORef | |
type CollElement (IORef w) = Element w | |
type RefElement (IORef a) = a | |
type MCState (IORef a) = PrimState IO |
data STRef s a :: * -> * -> *
a value of type STRef s a
is a mutable variable in state thread s
,
containing a value of type a
Eq (STRef s a) | |
IsSequence a => MutablePushBack (STRef s a) | |
IsSequence a => MutablePopBack (STRef s a) | |
IsSequence a => MutablePushFront (STRef s a) | |
IsSequence a => MutablePopFront (STRef s a) | |
Monoid w => MutableCollection (STRef s w) | |
MutableRef (STRef s a) | |
MutableContainer (STRef s a) | |
type CollElement (STRef s w) = Element w | |
type RefElement (STRef s a) = a | |
type MCState (STRef s a) = s |
data MutVar s a :: * -> * -> *
A MutVar
behaves like a single-element mutable array associated
with a primitive state token.
Eq (MutVar s a) | |
IsSequence a => MutablePushBack (MutVar s a) | |
IsSequence a => MutablePopBack (MutVar s a) | |
IsSequence a => MutablePushFront (MutVar s a) | |
IsSequence a => MutablePopFront (MutVar s a) | |
Monoid w => MutableCollection (MutVar s w) | |
MutableAtomicRef (MutVar s a) | |
MutableRef (MutVar s a) | |
MutableContainer (MutVar s a) | |
Typeable (* -> * -> *) MutVar | |
type CollElement (MutVar s w) = Element w | |
type RefElement (MutVar s a) = a | |
type MCState (MutVar s a) = s |
Collections/queues
A double-ended queue supporting any underlying vector type and any monad.
This implements a circular double-ended queue with exponential growth.
Since 0.2.0
MVector v a => MutablePushBack (Deque v s a) | |
MVector v a => MutablePopBack (Deque v s a) | |
MVector v a => MutablePushFront (Deque v s a) | |
MVector v a => MutablePopFront (Deque v s a) | |
MVector v a => MutableCollection (Deque v s a) | |
MutableContainer (Deque v s a) | |
type CollElement (Deque v s a) = a | |
type MCState (Deque v s a) = s |
A doubly-linked list.
Since 0.2.0
MutablePushBack (DList s a) | |
MutablePopBack (DList s a) | |
MutablePushFront (DList s a) | |
MutablePopFront (DList s a) | |
MutableCollection (DList s a) | |
MutableContainer (DList s a) | |
type CollElement (DList s a) = a | |
type MCState (DList s a) = s |
Type classes
class MutableContainer c Source
The parent typeclass for all mutable containers.
Since 0.2.0
Associated type giving the primitive state token for the given
container, much like PrimState
from primtive.
Since 0.2.0
MutableContainer (IORef a) | |
MutableContainer (STRef s a) | |
MutableContainer (MutVar s a) | |
MutableContainer (URef s a) | |
MutableContainer (SRef s a) | |
MutableContainer (PRef s a) | |
MutableContainer (BRef s a) | |
MutableContainer (DList s a) | |
MutableContainer (Deque v s a) |
class MutableContainer c => MutableRef c where Source
Typeclass for single-cell mutable references.
Since 0.2.0
type RefElement c Source
Associated type giving the type of the value inside the mutable reference.
Since 0.2.0
newRef :: (PrimMonad m, PrimState m ~ MCState c) => RefElement c -> m c Source
Create a new mutable reference with the given value.
Since 0.2.0
readRef :: (PrimMonad m, PrimState m ~ MCState c) => c -> m (RefElement c) Source
Read the current value in the mutable reference.
Since 0.2.0
writeRef :: (PrimMonad m, PrimState m ~ MCState c) => c -> RefElement c -> m () Source
Write a new value to the mutable reference.
Since 0.2.0
modifyRef :: (PrimMonad m, PrimState m ~ MCState c) => c -> (RefElement c -> RefElement c) -> m () Source
Modify the value in the mutable reference, without necessarily forcing the result.
Note: some implementations will force the result, in particular
PRef
, SRef
, and URef
.
Since 0.2.0
modifyRef' :: (PrimMonad m, PrimState m ~ MCState c) => c -> (RefElement c -> RefElement c) -> m () Source
Modify the value in the mutable reference, forcing the result.
Since 0.2.0
MutableRef (IORef a) | |
MutableRef (STRef s a) | |
MutableRef (MutVar s a) | |
Unbox a => MutableRef (URef s a) | |
Storable a => MutableRef (SRef s a) | |
Prim a => MutableRef (PRef s a) | |
MutableRef (BRef s a) |
class MutableRef c => MutableAtomicRef c where Source
MutableRef
s that provide for atomic modifications of their contents.
Since 0.2.0
atomicModifyRef :: (PrimMonad m, PrimState m ~ MCState c) => c -> (RefElement c -> (RefElement c, a)) -> m a Source
Modify the value without necessarily forcing the result.
Since 0.2.0
atomicModifyRef' :: (PrimMonad m, PrimState m ~ MCState c) => c -> (RefElement c -> (RefElement c, a)) -> m a Source
Modify the value, forcing the result.
Since 0.2.0
MutableAtomicRef (IORef a) | |
MutableAtomicRef (MutVar s a) |
class MutableContainer c => MutableCollection c where Source
Containers which contain 0 or more values.
Since 0.2.0
type CollElement c Source
The type of each value in the collection.
Since 0.2.0
newColl :: (PrimMonad m, PrimState m ~ MCState c) => m c Source
Create a new, empty collection.
Since 0.2.0
Monoid w => MutableCollection (IORef w) | |
Monoid w => MutableCollection (STRef s w) | |
Monoid w => MutableCollection (MutVar s w) | |
Monoid w => MutableCollection (BRef s w) | |
MutableCollection (DList s a) | |
MVector v a => MutableCollection (Deque v s a) |
class MutableCollection c => MutablePushFront c where Source
Place a value at the front of the collection.
Since 0.2.0
pushFront :: (PrimMonad m, PrimState m ~ MCState c) => c -> CollElement c -> m () Source
Place a value at the front of the collection.
Since 0.2.0
IsSequence a => MutablePushFront (IORef a) | |
IsSequence a => MutablePushFront (STRef s a) | |
IsSequence a => MutablePushFront (MutVar s a) | |
IsSequence seq => MutablePushFront (BRef s seq) | |
MutablePushFront (DList s a) | |
MVector v a => MutablePushFront (Deque v s a) |
class MutableCollection c => MutablePushBack c where Source
Place a value at the back of the collection.
Since 0.2.0
pushBack :: (PrimMonad m, PrimState m ~ MCState c) => c -> CollElement c -> m () Source
Place a value at the back of the collection.
Since 0.2.0
IsSequence a => MutablePushBack (IORef a) | |
IsSequence a => MutablePushBack (STRef s a) | |
IsSequence a => MutablePushBack (MutVar s a) | |
IsSequence seq => MutablePushBack (BRef s seq) | |
MutablePushBack (DList s a) | |
MVector v a => MutablePushBack (Deque v s a) |
class MutableCollection c => MutablePopFront c where Source
Take a value from the front of the collection, if available.
Since 0.2.0
popFront :: (PrimMonad m, PrimState m ~ MCState c) => c -> m (Maybe (CollElement c)) Source
Take a value from the front of the collection, if available.
Since 0.2.0
IsSequence a => MutablePopFront (IORef a) | |
IsSequence a => MutablePopFront (STRef s a) | |
IsSequence a => MutablePopFront (MutVar s a) | |
IsSequence seq => MutablePopFront (BRef s seq) | |
MutablePopFront (DList s a) | |
MVector v a => MutablePopFront (Deque v s a) |
class MutableCollection c => MutablePopBack c where Source
Take a value from the back of the collection, if available.
Since 0.2.0
popBack :: (PrimMonad m, PrimState m ~ MCState c) => c -> m (Maybe (CollElement c)) Source
Take a value from the back of the collection, if available.
Since 0.2.0
IsSequence a => MutablePopBack (IORef a) | |
IsSequence a => MutablePopBack (STRef s a) | |
IsSequence a => MutablePopBack (MutVar s a) | |
IsSequence seq => MutablePopBack (BRef s seq) | |
MutablePopBack (DList s a) | |
MVector v a => MutablePopBack (Deque v s a) |
Constraint kinds
type MutableQueue c = (MutablePopFront c, MutablePushBack c) Source
Collections which allow pushing and popping at the front (aka FIFOs).
Since 0.2.0
type MutableStack c = (MutablePopFront c, MutablePushFront c) Source
Collections which allow pushing at the back and popping at the front (aka FILOs).
Since 0.2.0
type MutableDeque c = (MutableQueue c, MutablePushFront c, MutablePopBack c) Source
Collections which allow pushing and popping at the front and back.
Since 0.2.0
Convenience re-exports
Class of primitive state-transformer monads
type PrimState m :: *
State token type
data RealWorld :: *
RealWorld
is deeply magical. It is primitive, but it is not
unlifted (hence ptrArg
). We never manipulate values of type
RealWorld
; it's only used in the type system, to parameterise State#
.