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

Data.MRef.Types

Description

This module defines the "MRef" abstraction, which is a set of type-classes for things that behave like Control.Concurrent.MVar.MVars. See the documentation there for more info.

This interface may be subject to future expansion. Presently, rather than providing something like Control.Concurrent.MVar.tryTakeMVar, instances for "Data.StateRef.Types.ReadRef sr m (Maybe a)" are provided, giving Data.StateRef.Types.readReference the same type tryTakeMRef would have if it existed. There is currently nothing like Control.Concurrent.MVar.tryPutMVar, though. Perhaps there should be. Or, perhaps this is the sort of thing the weird (to me) signature of Data.IORef.atomicModifyIORef is for, and an argument for a similar signature for Data.StateRef.Types.modifyStateRef or the addition of a new atomicModifyStateRef function.

I would like to resolve these questions in version 0.3 of this package.

Documentation

data MRef m a whereSource

Constructors

MRef :: (TakeMRef sr m a, PutMRef sr m a) => !sr -> MRef m a 

Instances

PutMRef (MRef STM a) IO a 
TakeMRef (MRef STM a) IO a 
NewMRef (MRef STM a) IO a 

class HasMRef m whereSource

Methods

newMRef :: a -> m (MRef m a)Source

newEmptyMRef :: m (MRef m a)Source

Instances

class Monad m => NewMRef sr m a | sr -> a whereSource

Methods

newMReference :: a -> m srSource

See Control.Concurrent.MVar.newMVar

newEmptyMReference :: m srSource

See Control.Concurrent.MVar.newEmptyMVar

Instances

NewMRef (TVar (Maybe a)) IO a 
NewMRef (TVar (Maybe a)) STM a 
MonadIO m => NewMRef (MVar a) m a 
NewMRef (TMVar a) IO a 
NewMRef (TMVar a) STM a 
NewMRef (MRef STM a) IO a 

class Monad m => TakeMRef sr m a | sr -> a whereSource

Methods

takeMReference :: sr -> m aSource

See Control.Concurrent.MVar.takeMVar

Instances

TakeMRef (TVar (Maybe a)) IO a 
TakeMRef (TVar (Maybe a)) STM a 
MonadIO m => TakeMRef (MVar a) m a 
TakeMRef (TMVar a) IO a 
TakeMRef (TMVar a) STM a 
TakeMRef (MRef STM a) IO a 

class Monad m => PutMRef sr m a | sr -> a whereSource

Methods

putMReference :: sr -> a -> m ()Source

See Control.Concurrent.MVar.putMVar

Instances

PutMRef (TVar (Maybe a)) IO a 
PutMRef (TVar (Maybe a)) STM a 
MonadIO m => PutMRef (MVar a) m a 
PutMRef (TMVar a) IO a 
PutMRef (TMVar a) STM a 
PutMRef (MRef STM a) IO a