Safe Haskell | Safe |
---|---|
Language | Haskell98 |
Data.StateRef.Types
- data Ref m a where
- class WriteRef sr m a | sr -> a where
- writeReference :: sr -> a -> m ()
- class ReadRef sr m a | sr -> a where
- readReference :: sr -> m a
- class (ReadRef sr m a, WriteRef sr m a) => ModifyRef sr m a | sr -> a where
- atomicModifyReference :: sr -> (a -> (a, b)) -> m b
- modifyReference :: sr -> (a -> a) -> m ()
- defaultAtomicModifyReference :: (Monad m, ReadRef sr m t, WriteRef sr m a) => sr -> (t -> (a, b)) -> m b
- defaultModifyReference :: (Monad m, ReadRef sr m t, WriteRef sr m a) => sr -> (t -> a) -> m ()
- class NewRef sr m a | sr -> a where
- newReference :: a -> m sr
- 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
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
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
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 :: (Monad m, ReadRef sr m t, WriteRef sr m a) => sr -> (t -> (a, b)) -> m b Source
Default implementation of atomicModifyReference in terms of readReference and writeReference
defaultModifyReference :: (Monad m, ReadRef sr m t, WriteRef sr m a) => sr -> (t -> a) -> m () Source
Default implementation of modifyReference in terms of readReference and writeReference