Safe Haskell | Safe-Inferred |
---|---|
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.
Synopsis
- data PRef s a
- type IOPRef = PRef (PrimState IO)
- asPRef :: PRef s a -> PRef s a
- data URef s a
- type IOURef = URef (PrimState IO)
- asURef :: URef s a -> URef s a
- data SRef s a
- type IOSRef = SRef (PrimState IO)
- asSRef :: SRef s a -> SRef s a
- data BRef s a
- type IOBRef = BRef (PrimState IO)
- 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 DLList s a
- asDLList :: DLList s a -> DLList 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
- class MutableCollection c => MutablePushFront c where
- class MutableCollection c => MutablePushBack c where
- 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 :: Type -> Type)
- type family PrimState (m :: Type -> Type)
- data RealWorld
- class Prim a
- class (Vector Vector a, MVector MVector a) => Unbox a
- class Storable a
Data types
Single-cell mutable references
A primitive ByteArray reference, supporting any monad.
Since 0.2.0
Instances
MutableContainer (PRef s a) Source # | |
Defined in Data.Mutable.PRef | |
Prim a => MutableRef (PRef s a) Source # | |
Defined in Data.Mutable.PRef type RefElement (PRef s a) Source # newRef :: (PrimMonad m, PrimState m ~ MCState (PRef s a)) => RefElement (PRef s a) -> m (PRef s a) Source # readRef :: (PrimMonad m, PrimState m ~ MCState (PRef s a)) => PRef s a -> m (RefElement (PRef s a)) Source # writeRef :: (PrimMonad m, PrimState m ~ MCState (PRef s a)) => PRef s a -> RefElement (PRef s a) -> m () Source # modifyRef :: (PrimMonad m, PrimState m ~ MCState (PRef s a)) => PRef s a -> (RefElement (PRef s a) -> RefElement (PRef s a)) -> m () Source # modifyRef' :: (PrimMonad m, PrimState m ~ MCState (PRef s a)) => PRef s a -> (RefElement (PRef s a) -> RefElement (PRef s a)) -> m () Source # | |
type MCState (PRef s a) Source # | |
Defined in Data.Mutable.PRef | |
type RefElement (PRef s a) Source # | |
Defined in Data.Mutable.PRef |
An unboxed vector reference, supporting any monad.
Since 0.2.0
Instances
MutableContainer (URef s a) Source # | |
Defined in Data.Mutable.URef | |
Unbox a => MutableRef (URef s a) Source # | |
Defined in Data.Mutable.URef type RefElement (URef s a) Source # newRef :: (PrimMonad m, PrimState m ~ MCState (URef s a)) => RefElement (URef s a) -> m (URef s a) Source # readRef :: (PrimMonad m, PrimState m ~ MCState (URef s a)) => URef s a -> m (RefElement (URef s a)) Source # writeRef :: (PrimMonad m, PrimState m ~ MCState (URef s a)) => URef s a -> RefElement (URef s a) -> m () Source # modifyRef :: (PrimMonad m, PrimState m ~ MCState (URef s a)) => URef s a -> (RefElement (URef s a) -> RefElement (URef s a)) -> m () Source # modifyRef' :: (PrimMonad m, PrimState m ~ MCState (URef s a)) => URef s a -> (RefElement (URef s a) -> RefElement (URef s a)) -> m () Source # | |
type MCState (URef s a) Source # | |
Defined in Data.Mutable.URef | |
type RefElement (URef s a) Source # | |
Defined in Data.Mutable.URef |
A storable vector reference, supporting any monad.
Since 0.2.0
Instances
MutableContainer (SRef s a) Source # | |
Defined in Data.Mutable.SRef | |
Storable a => MutableRef (SRef s a) Source # | |
Defined in Data.Mutable.SRef type RefElement (SRef s a) Source # newRef :: (PrimMonad m, PrimState m ~ MCState (SRef s a)) => RefElement (SRef s a) -> m (SRef s a) Source # readRef :: (PrimMonad m, PrimState m ~ MCState (SRef s a)) => SRef s a -> m (RefElement (SRef s a)) Source # writeRef :: (PrimMonad m, PrimState m ~ MCState (SRef s a)) => SRef s a -> RefElement (SRef s a) -> m () Source # modifyRef :: (PrimMonad m, PrimState m ~ MCState (SRef s a)) => SRef s a -> (RefElement (SRef s a) -> RefElement (SRef s a)) -> m () Source # modifyRef' :: (PrimMonad m, PrimState m ~ MCState (SRef s a)) => SRef s a -> (RefElement (SRef s a) -> RefElement (SRef s a)) -> m () Source # | |
type MCState (SRef s a) Source # | |
Defined in Data.Mutable.SRef | |
type RefElement (SRef s a) Source # | |
Defined in Data.Mutable.SRef |
A boxed vector reference, supporting any monad.
Since 0.2.0
Instances
Standard re-exports
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
Instances
a value of type STRef s a
is a mutable variable in state thread s
,
containing a value of type a
>>>
:{
runST (do ref <- newSTRef "hello" x <- readSTRef ref writeSTRef ref (x ++ "world") readSTRef ref ) :} "helloworld"
Instances
A MutVar
behaves like a single-element mutable array associated
with a primitive state token.
Instances
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
Instances
MVector v a => MutableCollection (Deque v s a) Source # | |
MutableContainer (Deque v s a) Source # | |
Defined in Data.Mutable.Deque | |
MVector v a => MutablePopBack (Deque v s a) Source # | |
MVector v a => MutablePopFront (Deque v s a) Source # | |
MVector v a => MutablePushBack (Deque v s a) Source # | |
MVector v a => MutablePushFront (Deque v s a) Source # | |
type CollElement (Deque v s a) Source # | |
Defined in Data.Mutable.Deque | |
type MCState (Deque v s a) Source # | |
Defined in Data.Mutable.Deque |
A doubly-linked list.
Since 0.3.0
Instances
MutableCollection (DLList s a) Source # | |
MutableContainer (DLList s a) Source # | |
Defined in Data.Mutable.DLList | |
MutablePopBack (DLList s a) Source # | |
MutablePopFront (DLList s a) Source # | |
MutablePushBack (DLList s a) Source # | |
MutablePushFront (DLList s a) Source # | |
type CollElement (DLList s a) Source # | |
Defined in Data.Mutable.DLList | |
type MCState (DLList s a) Source # | |
Defined in Data.Mutable.DLList |
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 primitive.
Since 0.2.0
Instances
MutableContainer (IORef a) Source # | |
Defined in Data.Mutable.Class | |
MutableContainer (STRef s a) Source # | |
Defined in Data.Mutable.Class | |
MutableContainer (BRef s a) Source # | |
Defined in Data.Mutable.BRef | |
MutableContainer (DLList s a) Source # | |
Defined in Data.Mutable.DLList | |
MutableContainer (PRef s a) Source # | |
Defined in Data.Mutable.PRef | |
MutableContainer (SRef s a) Source # | |
Defined in Data.Mutable.SRef | |
MutableContainer (URef s a) Source # | |
Defined in Data.Mutable.URef | |
MutableContainer (MutVar s a) Source # | |
Defined in Data.Mutable.Class | |
MutableContainer (Deque v s a) Source # | |
Defined in Data.Mutable.Deque |
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
Instances
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
Instances
MutableAtomicRef (IORef a) Source # | |
Defined in Data.Mutable.Class atomicModifyRef :: (PrimMonad m, PrimState m ~ MCState (IORef a)) => IORef a -> (RefElement (IORef a) -> (RefElement (IORef a), a0)) -> m a0 Source # atomicModifyRef' :: (PrimMonad m, PrimState m ~ MCState (IORef a)) => IORef a -> (RefElement (IORef a) -> (RefElement (IORef a), a0)) -> m a0 Source # | |
MutableAtomicRef (MutVar s a) Source # | |
Defined in Data.Mutable.Class atomicModifyRef :: (PrimMonad m, PrimState m ~ MCState (MutVar s a)) => MutVar s a -> (RefElement (MutVar s a) -> (RefElement (MutVar s a), a0)) -> m a0 Source # atomicModifyRef' :: (PrimMonad m, PrimState m ~ MCState (MutVar s a)) => MutVar s a -> (RefElement (MutVar s a) -> (RefElement (MutVar s a), a0)) -> m a0 Source # |
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
Instances
Monoid w => MutableCollection (IORef w) Source # | |
Monoid w => MutableCollection (STRef s w) Source # | |
Monoid w => MutableCollection (BRef s w) Source # | |
MutableCollection (DLList s a) Source # | |
Monoid w => MutableCollection (MutVar s w) Source # | |
MVector v a => MutableCollection (Deque v s a) Source # | |
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
Instances
IsSequence a => MutablePushFront (IORef a) Source # | |
IsSequence a => MutablePushFront (STRef s a) Source # | |
IsSequence seq => MutablePushFront (BRef s seq) Source # | |
MutablePushFront (DLList s a) Source # | |
IsSequence a => MutablePushFront (MutVar s a) Source # | |
MVector v a => MutablePushFront (Deque v s a) Source # | |
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
Instances
IsSequence a => MutablePushBack (IORef a) Source # | |
IsSequence a => MutablePushBack (STRef s a) Source # | |
IsSequence seq => MutablePushBack (BRef s seq) Source # | |
MutablePushBack (DLList s a) Source # | |
IsSequence a => MutablePushBack (MutVar s a) Source # | |
MVector v a => MutablePushBack (Deque v s a) Source # | |
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
Instances
IsSequence a => MutablePopFront (IORef a) Source # | |
IsSequence a => MutablePopFront (STRef s a) Source # | |
IsSequence seq => MutablePopFront (BRef s seq) Source # | |
MutablePopFront (DLList s a) Source # | |
IsSequence a => MutablePopFront (MutVar s a) Source # | |
MVector v a => MutablePopFront (Deque v s a) Source # | |
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
Instances
IsSequence a => MutablePopBack (IORef a) Source # | |
IsSequence a => MutablePopBack (STRef s a) Source # | |
IsSequence seq => MutablePopBack (BRef s seq) Source # | |
MutablePopBack (DLList s a) Source # | |
IsSequence a => MutablePopBack (MutVar s a) Source # | |
MVector v a => MutablePopBack (Deque v s a) Source # | |
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 Monad m => PrimMonad (m :: Type -> Type) #
Class of monads which can perform primitive state-transformer actions.
Instances
PrimMonad IO | |
PrimMonad (ST s) | |
PrimMonad (ST s) | |
PrimMonad m => PrimMonad (MaybeT m) | |
(Monoid w, PrimMonad m) => PrimMonad (AccumT w m) | Since: primitive-0.6.3.0 |
PrimMonad m => PrimMonad (ExceptT e m) | |
PrimMonad m => PrimMonad (IdentityT m) | |
PrimMonad m => PrimMonad (ReaderT r m) | |
PrimMonad m => PrimMonad (SelectT r m) | |
PrimMonad m => PrimMonad (StateT s m) | |
PrimMonad m => PrimMonad (StateT s m) | |
(Monoid w, PrimMonad m) => PrimMonad (WriterT w m) | |
(Monoid w, PrimMonad m) => PrimMonad (WriterT w m) | |
(Monoid w, PrimMonad m) => PrimMonad (WriterT w m) | |
PrimMonad m => PrimMonad (ContT r m) | Since: primitive-0.6.3.0 |
(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m) | |
(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m) | |
(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m) | |
type family PrimState (m :: Type -> Type) #
State token type.
Instances
Class of types supporting primitive array operations. This includes
interfacing with GC-managed memory (functions suffixed with ByteArray#
)
and interfacing with unmanaged memory (functions suffixed with Addr#
).
Endianness is platform-dependent.
sizeOf#, alignment#, indexByteArray#, readByteArray#, writeByteArray#, setByteArray#, indexOffAddr#, readOffAddr#, writeOffAddr#, setOffAddr#
Instances
class (Vector Vector a, MVector MVector a) => Unbox a #
Instances
The member functions of this class facilitate writing values of primitive types to raw memory (which may have been allocated with the above mentioned routines) and reading values from blocks of raw memory. The class, furthermore, includes support for computing the storage requirements and alignment restrictions of storable types.
Memory addresses are represented as values of type
, for some
Ptr
aa
which is an instance of class Storable
. The type argument to
Ptr
helps provide some valuable type safety in FFI code (you can't
mix pointers of different types without an explicit cast), while
helping the Haskell type system figure out which marshalling method is
needed for a given pointer.
All marshalling between Haskell and a foreign language ultimately
boils down to translating Haskell data structures into the binary
representation of a corresponding data structure of the foreign
language and vice versa. To code this marshalling in Haskell, it is
necessary to manipulate primitive data types stored in unstructured
memory blocks. The class Storable
facilitates this manipulation on
all types for which it is instantiated, which are the standard basic
types of Haskell, the fixed size Int
types (Int8
, Int16
,
Int32
, Int64
), the fixed size Word
types (Word8
, Word16
,
Word32
, Word64
), StablePtr
, all types from Foreign.C.Types,
as well as Ptr
.
sizeOf, alignment, (peek | peekElemOff | peekByteOff), (poke | pokeElemOff | pokeByteOff)