Safe Haskell | None |
---|---|
Language | Haskell2010 |
Use ByteArray
s containing one element for mutable references.
This is similar to URef
s, but avoids the overhead of storing the length of
the Vector
, which we statically know will always be 1. This allows it to
be a bit faster.
Motivated by: http://stackoverflow.com/questions/27261813/why-is-my-little-stref-int-require-allocating-gigabytes and ArrayRef.
- data PRef s a
- type IOPRef = PRef (PrimState IO)
- asPRef :: PRef s a -> PRef s a
- 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 ()
Types
A primitive ByteArray reference, supporting any monad.
Prim a => MutableRef (PRef s a) | |
MutableContainer (PRef s a) | |
type RefElement (PRef s a) = a | |
type MCState (PRef s a) = s |
Functions
class MutableContainer c => MutableRef c where Source
type RefElement c Source
newRef :: (PrimMonad m, PrimState m ~ MCState c) => RefElement c -> m c Source
readRef :: (PrimMonad m, PrimState m ~ MCState c) => c -> m (RefElement c) Source
writeRef :: (PrimMonad m, PrimState m ~ MCState c) => c -> RefElement c -> m () Source
modifyRef :: (PrimMonad m, PrimState m ~ MCState c) => c -> (RefElement c -> RefElement c) -> m () Source
modifyRef' :: (PrimMonad m, PrimState m ~ MCState c) => c -> (RefElement c -> RefElement c) -> m () Source
MutableRef (IORef a) | |
MutableRef (STRef s a) | |
MutableRef (MutVar s a) | |
Unbox a => MutableRef (URef s a) | |
Prim a => MutableRef (PRef s a) | |
MutableRef (VRef s a) | |
Storable a => MutableRef (SRef s a) |