stateref-0.3: Abstraction for things that work like IORef.

Safe Haskell | Safe-Inferred
Language | Haskell98

Data.StateRef.Types

Synopsis

- data Ref (m :: Type -> Type) a where
  - Ref :: forall sr (m :: Type -> Type) a. ModifyRef sr m a => !sr -> Ref m a
- class WriteRef sr (m :: Type -> Type) a | sr -> a where
  - writeReference :: sr -> a -> m ()
- class ReadRef sr (m :: Type -> Type) a | sr -> a where
  - readReference :: sr -> m a
- class (ReadRef sr m a, WriteRef sr m a) => ModifyRef sr (m :: Type -> Type) 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 :: Type -> Type) a | sr -> a where
  - newReference :: a -> m sr
- class HasRef (m :: Type -> Type) where
  - newRef :: a -> m (Ref m a)

# Documentation

data Ref (m :: Type -> Type) a where Source #

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.

Constructors

Ref :: forall sr (m :: Type -> Type) a. ModifyRef sr m a => !sr -> Ref m a |

#### Instances

Instances details

MonadIO m => ModifyRef (Ref STM a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods atomicModifyReference :: Ref STM a -> (a -> (a, b)) -> m b Source # modifyReference :: Ref STM a -> (a -> a) -> m () Source #
ModifyRef (Ref m a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods atomicModifyReference :: Ref m a -> (a -> (a, b)) -> m b Source # modifyReference :: Ref m a -> (a -> a) -> m () Source #
MonadIO m => NewRef (Ref STM a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods newReference :: a -> m (Ref STM a) Source #
HasRef m => NewRef (Ref m a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> m (Ref m a) Source #
MonadIO m => ReadRef (Ref STM a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: Ref STM a -> m a Source #
ReadRef (Ref m a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: Ref m a -> m a Source #
MonadIO m => WriteRef (Ref STM a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods writeReference :: Ref STM a -> a -> m () Source #
WriteRef (Ref m a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods writeReference :: Ref m a -> a -> m () Source #

class WriteRef sr (m :: Type -> Type) a | sr -> a where Source #

Methods

writeReference :: sr -> a -> m () Source #

Replace the existing value of the given reference with the provided value.

#### Instances

Instances details

WriteRef (TVar a) STM a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods writeReference :: TVar a -> a -> STM () Source #
MonadIO m => WriteRef (TVar a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods writeReference :: TVar a -> a -> m () Source #
(Storable a, MonadIO m) => WriteRef (ForeignPtr a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods writeReference :: ForeignPtr a -> a -> m () Source #
MonadIO m => WriteRef (IORef a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods writeReference :: IORef a -> a -> m () Source #
WriteRef sr m a => WriteRef (UnsafeModifyRef sr) m a Source # |
Instance details Defined in Data.StateRef.Instances.Undecidable Methods writeReference :: UnsafeModifyRef sr -> a -> m () Source #
WriteRef (STRef RealWorld a) IO a Source # |
Instance details Defined in Data.StateRef.Instances Methods writeReference :: STRef RealWorld a -> a -> IO () Source #
Monad m => WriteRef (Accessor m a) m a Source # |
Instance details Defined in Data.Accessor Methods writeReference :: Accessor m a -> a -> m () Source #
Monad m => WriteRef (Setter m a) m a Source # |
Instance details Defined in Data.Accessor Methods writeReference :: Setter m a -> a -> m () Source #
MonadIO m => WriteRef (Ref STM a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods writeReference :: Ref STM a -> a -> m () Source #
WriteRef (Ref m a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods writeReference :: Ref m a -> a -> m () Source #
WriteRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods writeReference :: STRef s a -> a -> ST s () Source #
WriteRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods writeReference :: STRef s a -> a -> ST s () Source #

class ReadRef sr (m :: Type -> Type) a | sr -> a where Source #

Methods

readReference :: sr -> m a Source #

Get the current value referenced by the given state reference.

#### Instances

Instances details

ReadRef (STM a) STM a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: STM a -> STM a Source #
MonadIO m => ReadRef (STM a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: STM a -> m a Source #
ReadRef (TVar a) STM a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: TVar a -> STM a Source #
MonadIO m => ReadRef (TVar a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: TVar a -> m a Source #
(Storable a, MonadIO m) => ReadRef (ForeignPtr a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: ForeignPtr a -> m a Source #
MonadIO m => ReadRef (IORef a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: IORef a -> m a Source #
MonadIO m => ReadRef (IO a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: IO a -> m a Source #
ReadRef sr m a => ReadRef (UnsafeModifyRef sr) m a Source # |
Instance details Defined in Data.StateRef.Instances.Undecidable Methods readReference :: UnsafeModifyRef sr -> m a Source #
ReadRef (TMVar a) STM (Maybe a) Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: TMVar a -> STM (Maybe a) Source #
MonadIO m => ReadRef (TMVar a) m (Maybe a) Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: TMVar a -> m (Maybe a) Source #
MonadIO m => ReadRef (ST RealWorld a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: ST RealWorld a -> m a Source #
ReadRef (STRef RealWorld a) IO a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: STRef RealWorld a -> IO a Source #
Monad m => ReadRef (Accessor m a) m a Source # |
Instance details Defined in Data.Accessor Methods readReference :: Accessor m a -> m a Source #
Monad m => ReadRef (Getter m a) m a Source # |
Instance details Defined in Data.Accessor Methods readReference :: Getter m a -> m a Source #
MonadIO m => ReadRef (Ref STM a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods readReference :: Ref STM a -> m a Source #
ReadRef (Ref m a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: Ref m a -> m a Source #
ReadRef (ST s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: ST s a -> ST s a Source #
ReadRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: STRef s a -> ST s a Source #
ReadRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods readReference :: STRef s a -> ST s a Source #

class (ReadRef sr m a, WriteRef sr m a) => ModifyRef sr (m :: Type -> Type) 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.

#### Instances

Instances details

ModifyRef (TVar a) STM a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods atomicModifyReference :: TVar a -> (a -> (a, b)) -> STM b Source # modifyReference :: TVar a -> (a -> a) -> STM () Source #
MonadIO m => ModifyRef (TVar a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods atomicModifyReference :: TVar a -> (a -> (a, b)) -> m b Source # modifyReference :: TVar a -> (a -> a) -> m () Source #
(Storable a, MonadIO m) => ModifyRef (ForeignPtr a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods atomicModifyReference :: ForeignPtr a -> (a -> (a, b)) -> m b Source # modifyReference :: ForeignPtr a -> (a -> a) -> m () Source #
MonadIO m => ModifyRef (IORef a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods atomicModifyReference :: IORef a -> (a -> (a, b)) -> m b Source # modifyReference :: IORef a -> (a -> a) -> m () Source #
(Monad m, ReadRef sr m a, WriteRef sr m a) => ModifyRef (UnsafeModifyRef sr) m a Source # |
Instance details Defined in Data.StateRef.Instances.Undecidable Methods atomicModifyReference :: UnsafeModifyRef sr -> (a -> (a, b)) -> m b Source # modifyReference :: UnsafeModifyRef sr -> (a -> a) -> m () Source #
ModifyRef (STRef RealWorld a) IO a Source # |
Instance details Defined in Data.StateRef.Instances Methods atomicModifyReference :: STRef RealWorld a -> (a -> (a, b)) -> IO b Source # modifyReference :: STRef RealWorld a -> (a -> a) -> IO () Source #
MonadIO m => ModifyRef (Ref STM a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods atomicModifyReference :: Ref STM a -> (a -> (a, b)) -> m b Source # modifyReference :: Ref STM a -> (a -> a) -> m () Source #
ModifyRef (Ref m a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods atomicModifyReference :: Ref m a -> (a -> (a, b)) -> m b Source # modifyReference :: Ref m a -> (a -> a) -> m () Source #
ModifyRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods atomicModifyReference :: STRef s a -> (a -> (a, b)) -> ST s b Source # modifyReference :: STRef s a -> (a -> a) -> ST s () Source #
ModifyRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods atomicModifyReference :: STRef s a -> (a -> (a, b)) -> ST s b Source # modifyReference :: STRef s a -> (a -> a) -> ST s () Source #

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

class NewRef sr (m :: Type -> Type) a | sr -> a where Source #

Methods

newReference :: a -> m sr Source #

Construct a new reference to the provided value.

#### Instances

Instances details

NewRef (TVar a) STM a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods newReference :: a -> STM (TVar a) Source #
MonadIO m => NewRef (TVar a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods newReference :: a -> m (TVar a) Source #
(Storable a, MonadIO m) => NewRef (ForeignPtr a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> m (ForeignPtr a) Source #
MonadIO m => NewRef (IORef a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> m (IORef a) Source #
Monad m => NewRef (IO a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> m (IO a) Source #
MonadIO m => NewRef (MVar a) m (Maybe a) Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: Maybe a -> m (MVar a) Source #
NewRef (TMVar a) STM (Maybe a) Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods newReference :: Maybe a -> STM (TMVar a) Source #
MonadIO m => NewRef (TMVar a) m (Maybe a) Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods newReference :: Maybe a -> m (TMVar a) Source #
Monad m => NewRef (ST s a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> m (ST s a) Source #
NewRef (STRef RealWorld a) IO a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> IO (STRef RealWorld a) Source #
MonadIO m => NewRef (Ref STM a) m a Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods newReference :: a -> m (Ref STM a) Source #
HasRef m => NewRef (Ref m a) m a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> m (Ref m a) Source #
NewRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> ST s (STRef s a) Source #
NewRef (STRef s a) (ST s) a Source # |
Instance details Defined in Data.StateRef.Instances Methods newReference :: a -> ST s (STRef s a) Source #

class HasRef (m :: Type -> Type) where Source #

Methods

newRef :: a -> m (Ref m a) Source #

Construct a new mutable reference (of an unspecified implementation type) containing the provided value.

#### Instances

Instances details

HasRef STM Source # |
Instance details Defined in Data.StateRef.Instances.STM Methods newRef :: a -> STM (Ref STM a) Source #
HasRef IO Source # |
Instance details Defined in Data.StateRef.Instances Methods newRef :: a -> IO (Ref IO a) Source #
HasRef (ST s) Source # |
Instance details Defined in Data.StateRef.Instances Methods newRef :: a -> ST s (Ref (ST s) a) Source #
HasRef (ST s) Source # |
Instance details Defined in Data.StateRef.Instances Methods newRef :: a -> ST s (Ref (ST s) a) Source #