dejafu-0.1.0.0: Overloadable primitives for testable, potentially non-deterministic, concurrency.

Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Monad.STM.Class

Description

This module provides an abstraction over STM, which can be used with MonadConc.

Synopsis

Documentation

class (Applicative m, Monad m, MonadCatch m, MonadThrow m) => MonadSTM m where Source

MonadSTM is an abstraction over STM.

This class does not provide any way to run transactions, rather each MonadConc has an associated MonadSTM from which it can atomically run a transaction.

A minimal implementation consists of retry, orElse, newCTVar, readCTVar, and writeCTVar.

Minimal complete definition

retry, orElse, newCTVar, readCTVar, writeCTVar

Associated Types

type CTVar m :: * -> * Source

The mutable reference type. These behave like TVars, in that they always contain a value and updates are non-blocking and synchronised.

Methods

retry :: m a Source

Retry execution of this transaction because it has seen values in CTVars that it shouldn't have. This will result in the thread running the transaction being blocked until any CTVars referenced in it have been mutated.

orElse :: m a -> m a -> m a Source

Run the first transaction and, if it retrys, run the second instead. If the monad is an instance of 'Alternative'/'MonadPlus', orElse should be the '(|)'/'mplus' function.

check :: Bool -> m () Source

Check whether a condition is true and, if not, call retry.

check b = unless b retry

newCTVar :: a -> m (CTVar m a) Source

Create a new CTVar containing the given value.

readCTVar :: CTVar m a -> m a Source

Return the current value stored in a CTVar.

writeCTVar :: CTVar m a -> a -> m () Source

Write the supplied value into the CTVar.

throwSTM :: Exception e => e -> m a Source

Throw an exception. This aborts the transaction and propagates the exception.

throwSTM = Control.Monad.Catch.throwM

catchSTM :: Exception e => m a -> (e -> m a) -> m a Source

Handling exceptions from throwSTM.

catchSTM = Control.Monad.Catch.catch

Instances

MonadSTM STM 
MonadSTM m => MonadSTM (ReaderT r m) 
MonadSTM m => MonadSTM (StateT s m) 
MonadSTM m => MonadSTM (StateT s m) 
(MonadSTM m, Monoid w) => MonadSTM (WriterT w m) 
(MonadSTM m, Monoid w) => MonadSTM (WriterT w m) 
Monad n => MonadSTM (STMLike t n r) 
(MonadSTM m, Monoid w) => MonadSTM (RWST r w s m) 
(MonadSTM m, Monoid w) => MonadSTM (RWST r w s m)