- 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 ()
- 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 whereSource
writeReference :: sr -> a -> m ()Source
Replace the existing value of the given reference with the provided value.
(Storable a, MonadIO m) => WriteRef (ForeignPtr a) m a | |
MonadIO m => WriteRef (TVar a) m a | |
WriteRef (TVar a) STM a | |
MonadIO m => WriteRef (IORef a) m a | |
WriteRef sr m a => WriteRef (UnsafeModifyRef sr) m a | |
WriteRef (STRef RealWorld a) IO a | |
WriteRef (Ref m a) m a | |
MonadIO m => WriteRef (Ref STM a) m a | |
Monad m => WriteRef (Accessor m a) m a | |
Monad m => WriteRef (Setter m a) m a | |
WriteRef (STRef s a) (ST s) a | |
WriteRef (STRef s a) (ST s) a |
class ReadRef sr m a | sr -> a whereSource
readReference :: sr -> m aSource
Get the current value referenced by the given state reference.
MonadIO m => ReadRef (IO a) m a | |
(Storable a, MonadIO m) => ReadRef (ForeignPtr a) m a | |
MonadIO m => ReadRef (STM a) m a | |
ReadRef (STM a) STM a | |
MonadIO m => ReadRef (TVar a) m a | |
ReadRef (TVar a) STM a | |
MonadIO m => ReadRef (IORef a) m a | |
ReadRef sr m a => ReadRef (UnsafeModifyRef sr) m a | |
MonadIO m => ReadRef (TMVar a) m (Maybe a) | |
ReadRef (TMVar a) STM (Maybe a) | |
MonadIO m => ReadRef (ST RealWorld a) m a | |
ReadRef (STRef RealWorld a) IO a | |
ReadRef (Ref m a) m a | |
MonadIO m => ReadRef (Ref STM a) m a | |
Monad m => ReadRef (Accessor m a) m a | |
Monad m => ReadRef (Getter m a) m a | |
ReadRef (ST s a) (ST s) a | |
ReadRef (STRef s a) (ST s) a | |
ReadRef (STRef s a) (ST s) a |
class (ReadRef sr m a, WriteRef sr m a) => ModifyRef sr m a | sr -> a whereSource
atomicModifyReference :: sr -> (a -> (a, b)) -> m bSource
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.
(Storable a, MonadIO m) => ModifyRef (ForeignPtr a) m a | |
MonadIO m => ModifyRef (TVar a) m a | |
ModifyRef (TVar a) STM a | |
MonadIO m => ModifyRef (IORef a) m a | |
(Monad m, ReadRef sr m a, WriteRef sr m a) => ModifyRef (UnsafeModifyRef sr) m a | |
ModifyRef (STRef RealWorld a) IO a | |
ModifyRef (Ref m a) m a | |
MonadIO m => ModifyRef (Ref STM a) m a | |
ModifyRef (STRef s a) (ST s) a | |
ModifyRef (STRef s a) (ST s) a |
class NewRef sr m a | sr -> a whereSource
Default implementation of atomicModifyReference in terms of readReference and writeReference
Default implementation of modifyReference in terms of readReference and writeReference
newReference :: a -> m srSource
Construct a new reference to the provided value.
Monad m => NewRef (IO a) m a | |
(Storable a, MonadIO m) => NewRef (ForeignPtr a) m a | |
MonadIO m => NewRef (TVar a) m a | |
NewRef (TVar a) STM a | |
MonadIO m => NewRef (IORef a) m a | |
MonadIO m => NewRef (MVar a) m (Maybe a) | |
MonadIO m => NewRef (TMVar a) m (Maybe a) | |
NewRef (TMVar a) STM (Maybe a) | |
Monad m => NewRef (ST s a) m a | |
NewRef (STRef RealWorld a) IO a | |
HasRef m => NewRef (Ref m a) m a | |
MonadIO m => NewRef (Ref STM a) m a | |
NewRef (STRef s a) (ST s) a | |
NewRef (STRef s a) (ST s) a |