Safe Haskell | Safe |
---|---|
Language | Haskell98 |
Data.StateRef.Types
- data Ref m a where
- class WriteRef sr m a | sr -> a where
- class ReadRef sr m a | sr -> a where
- class (ReadRef sr m a, WriteRef sr m a) => ModifyRef sr m a | sr -> a where
- defaultAtomicModifyReference :: (WriteRef sr m a, ReadRef sr m t, Monad m) => sr -> (t -> (a, b)) -> m b
- defaultModifyReference :: (WriteRef sr m a, ReadRef sr m t, Monad m) => sr -> (t -> a) -> m ()
- class NewRef sr m a | sr -> a where
- class HasRef m where
Documentation
A simple reference type, hiding the complexity of all these type classes,
since most of the time the only thing you care about is that you want a reference.
The full complexity is still there, though, so FFI types or other reference-like
things can still be made into Ref
s.
class WriteRef sr m a | sr -> a where Source #
Minimal complete definition
Methods
writeReference :: sr -> a -> m () Source #
Replace the existing value of the given reference with the provided value.
class ReadRef sr m a | sr -> a where Source #
Minimal complete definition
Methods
readReference :: sr -> m a Source #
Get the current value referenced by the given state reference.
class (ReadRef sr m a, WriteRef sr m a) => ModifyRef sr m a | sr -> a where Source #
Minimal complete definition
Methods
atomicModifyReference :: sr -> (a -> (a, b)) -> m b Source #
Atomically modify the contents of a reference. This is implemented in a separate class (rather than a function with context (ReadRef sr m a, WriteRef sr m a)) because in most cases the default implementation cannot act atomically.
modifyReference :: sr -> (a -> a) -> m () Source #
Same thing, but don't thread out the extra return. Could perhaps
be implemented slightly more efficiently than atomicModifyReference
in many cases.
Note that implementations are expected to be atomic, if at all possible,
but not strictly required to be.
defaultAtomicModifyReference :: (WriteRef sr m a, ReadRef sr m t, Monad m) => sr -> (t -> (a, b)) -> m b Source #
Default implementation of atomicModifyReference in terms of readReference and writeReference
defaultModifyReference :: (WriteRef sr m a, ReadRef sr m t, Monad m) => sr -> (t -> a) -> m () Source #
Default implementation of modifyReference in terms of readReference and writeReference