Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module corresponds to Control.Monad.STM in "stm" package
Synopsis
- class (Monad m, Monad (STM m)) => MonadSTM (m :: Type -> Type) where
- throwSTM :: forall (m :: Type -> Type) e a. (MonadSTM m, MonadThrow (STM m), Exception e) => e -> STM m a
- class MonadSTM m => MonadLabelledSTM (m :: Type -> Type)
- class MonadInspectSTM m => MonadTraceSTM (m :: Type -> Type) where
- traceTVar :: proxy m -> TVar m a -> (Maybe a -> a -> InspectMonad m TraceValue) -> STM m ()
- traceTMVar :: proxy m -> TMVar m a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad m TraceValue) -> STM m ()
- traceTQueue :: proxy m -> TQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m ()
- traceTBQueue :: proxy m -> TBQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m ()
- traceTSem :: proxy m -> TSem m -> (Maybe Integer -> Integer -> InspectMonad m TraceValue) -> STM m ()
- traceTVarIO :: TVar m a -> (Maybe a -> a -> InspectMonad m TraceValue) -> m ()
- traceTMVarIO :: TMVar m a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad m TraceValue) -> m ()
- traceTQueueIO :: TQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> m ()
- traceTBQueueIO :: TBQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> m ()
- traceTSemIO :: TSem m -> (Maybe Integer -> Integer -> InspectMonad m TraceValue) -> m ()
- data TraceValue where
- TraceValue :: forall tr. Typeable tr => {..} -> TraceValue
- pattern TraceDynamic :: () => Typeable tr => tr -> TraceValue
- pattern TraceString :: String -> TraceValue
- pattern DontTrace :: TraceValue
- class (MonadSTM m, Monad (InspectMonad m)) => MonadInspectSTM (m :: Type -> Type) where
- type InspectMonad (m :: Type -> Type) :: Type -> Type
- inspectTVar :: proxy m -> TVar m a -> InspectMonad m a
- inspectTMVar :: proxy m -> TMVar m a -> InspectMonad m (Maybe a)
Documentation
class (Monad m, Monad (STM m)) => MonadSTM (m :: Type -> Type) where Source #
The STM primitives parametrised by a monad m
.
atomically, newTVar, readTVar, writeTVar, retry, orElse, newTMVar, newEmptyTMVar, takeTMVar, tryTakeTMVar, putTMVar, tryPutTMVar, readTMVar, tryReadTMVar, swapTMVar, writeTMVar, isEmptyTMVar, newTQueue, readTQueue, tryReadTQueue, peekTQueue, tryPeekTQueue, flushTQueue, writeTQueue, isEmptyTQueue, unGetTQueue, newTBQueue, readTBQueue, tryReadTBQueue, peekTBQueue, tryPeekTBQueue, flushTBQueue, writeTBQueue, lengthTBQueue, isEmptyTBQueue, isFullTBQueue, unGetTBQueue, newTSem, waitTSem, signalTSem, signalTSemN, newTChan, newBroadcastTChan, dupTChan, cloneTChan, readTChan, tryReadTChan, peekTChan, tryPeekTChan, writeTChan, unGetTChan, isEmptyTChan
atomically :: HasCallStack => STM m a -> m a Source #
Atomically run an STM computation.
See atomically
.
See retry
.
orElse :: STM m a -> STM m a -> STM m a Source #
See orElse
.
check :: Bool -> STM m () Source #
See check
.
Instances
throwSTM :: forall (m :: Type -> Type) e a. (MonadSTM m, MonadThrow (STM m), Exception e) => e -> STM m a Source #
throwIO
specialised to stm
monad.
non standard extensions
The non standard extensions include MonadLabelledSTM
and MonadTraceSTM
/
MonadInspectSTM
. For IO
these are all no-op, however they greatly
enhance IOSim
capabilities.
They are not only useful for debugging concurrency issues, but also to write
testable properties.
class MonadSTM m => MonadLabelledSTM (m :: Type -> Type) Source #
Labelled TVar
s & friends.
The IO
instances is no-op, the IOSim
instance enhances simulation trace.
This is very useful when analysing low lever concurrency issues (e.g.
deadlocks, livelocks etc).
Instances
MonadLabelledSTM IO Source # | noop instance |
Defined in Control.Monad.Class.MonadSTM.Internal labelTVar :: TVar IO a -> String -> STM IO () Source # labelTMVar :: TMVar IO a -> String -> STM IO () Source # labelTQueue :: TQueue IO a -> String -> STM IO () Source # labelTBQueue :: TBQueue IO a -> String -> STM IO () Source # labelTArray :: (Ix i, Show i) => TArray IO i e -> String -> STM IO () Source # labelTSem :: TSem IO -> String -> STM IO () Source # labelTChan :: TChan IO a -> String -> STM IO () Source # labelTVarIO :: TVar IO a -> String -> IO () Source # labelTMVarIO :: TMVar IO a -> String -> IO () Source # labelTQueueIO :: TQueue IO a -> String -> IO () Source # labelTBQueueIO :: TBQueue IO a -> String -> IO () Source # labelTArrayIO :: (Ix i, Show i) => TArray IO i e -> String -> IO () Source # |
class MonadInspectSTM m => MonadTraceSTM (m :: Type -> Type) where Source #
MonadTraceSTM
allows to trace values of stm variables when stm
transaction is committed. This allows to verify invariants when a variable
is committed.
:: proxy m | |
-> TVar m a | |
-> (Maybe a -> a -> InspectMonad m TraceValue) | callback which receives initial value or |
-> STM m () |
Construct a trace output out of previous & new value of a TVar
. The
callback is called whenever an stm transaction which modifies the TVar
is
committed.
This is supported by IOSim
(and IOSimPOR
); IO
has a trivial instance.
The simplest example is:
traceTVar (Proxy @m) tvar (\_ -> TraceString . show)
Note that the interpretation of TraceValue
depends on the monad m
itself (see TraceValue
).
traceTMVar :: proxy m -> TMVar m a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad m TraceValue) -> STM m () Source #
default traceTMVar :: TMVar m a ~ TMVarDefault m a => proxy m -> TMVar m a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad m TraceValue) -> STM m () Source #
traceTQueue :: proxy m -> TQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m () Source #
traceTBQueue :: proxy m -> TBQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m () Source #
traceTSem :: proxy m -> TSem m -> (Maybe Integer -> Integer -> InspectMonad m TraceValue) -> STM m () Source #
default traceTSem :: TSem m ~ TSemDefault m => proxy m -> TSem m -> (Maybe Integer -> Integer -> InspectMonad m TraceValue) -> STM m () Source #
traceTVarIO :: TVar m a -> (Maybe a -> a -> InspectMonad m TraceValue) -> m () Source #
default traceTVarIO :: TVar m a -> (Maybe a -> a -> InspectMonad m TraceValue) -> m () Source #
traceTMVarIO :: TMVar m a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad m TraceValue) -> m () Source #
default traceTMVarIO :: TMVar m a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad m TraceValue) -> m () Source #
traceTQueueIO :: TQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> m () Source #
default traceTQueueIO :: TQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> m () Source #
traceTBQueueIO :: TBQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> m () Source #
default traceTBQueueIO :: TBQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> m () Source #
traceTSemIO :: TSem m -> (Maybe Integer -> Integer -> InspectMonad m TraceValue) -> m () Source #
default traceTSemIO :: TSem m -> (Maybe Integer -> Integer -> InspectMonad m TraceValue) -> m () Source #
Instances
MonadTraceSTM IO Source # | noop instance |
Defined in Control.Monad.Class.MonadSTM.Internal traceTVar :: proxy IO -> TVar IO a -> (Maybe a -> a -> InspectMonad IO TraceValue) -> STM IO () Source # traceTMVar :: proxy IO -> TMVar IO a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad IO TraceValue) -> STM IO () Source # traceTQueue :: proxy IO -> TQueue IO a -> (Maybe [a] -> [a] -> InspectMonad IO TraceValue) -> STM IO () Source # traceTBQueue :: proxy IO -> TBQueue IO a -> (Maybe [a] -> [a] -> InspectMonad IO TraceValue) -> STM IO () Source # traceTSem :: proxy IO -> TSem IO -> (Maybe Integer -> Integer -> InspectMonad IO TraceValue) -> STM IO () Source # traceTVarIO :: TVar IO a -> (Maybe a -> a -> InspectMonad IO TraceValue) -> IO () Source # traceTMVarIO :: TMVar IO a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad IO TraceValue) -> IO () Source # traceTQueueIO :: TQueue IO a -> (Maybe [a] -> [a] -> InspectMonad IO TraceValue) -> IO () Source # traceTBQueueIO :: TBQueue IO a -> (Maybe [a] -> [a] -> InspectMonad IO TraceValue) -> IO () Source # traceTSemIO :: TSem IO -> (Maybe Integer -> Integer -> InspectMonad IO TraceValue) -> IO () Source # | |
MonadTraceSTM m => MonadTraceSTM (ReaderT r m) Source # | |
Defined in Control.Monad.Class.MonadSTM.Internal traceTVar :: proxy (ReaderT r m) -> TVar (ReaderT r m) a -> (Maybe a -> a -> InspectMonad (ReaderT r m) TraceValue) -> STM (ReaderT r m) () Source # traceTMVar :: proxy (ReaderT r m) -> TMVar (ReaderT r m) a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad (ReaderT r m) TraceValue) -> STM (ReaderT r m) () Source # traceTQueue :: proxy (ReaderT r m) -> TQueue (ReaderT r m) a -> (Maybe [a] -> [a] -> InspectMonad (ReaderT r m) TraceValue) -> STM (ReaderT r m) () Source # traceTBQueue :: proxy (ReaderT r m) -> TBQueue (ReaderT r m) a -> (Maybe [a] -> [a] -> InspectMonad (ReaderT r m) TraceValue) -> STM (ReaderT r m) () Source # traceTSem :: proxy (ReaderT r m) -> TSem (ReaderT r m) -> (Maybe Integer -> Integer -> InspectMonad (ReaderT r m) TraceValue) -> STM (ReaderT r m) () Source # traceTVarIO :: TVar (ReaderT r m) a -> (Maybe a -> a -> InspectMonad (ReaderT r m) TraceValue) -> ReaderT r m () Source # traceTMVarIO :: TMVar (ReaderT r m) a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad (ReaderT r m) TraceValue) -> ReaderT r m () Source # traceTQueueIO :: TQueue (ReaderT r m) a -> (Maybe [a] -> [a] -> InspectMonad (ReaderT r m) TraceValue) -> ReaderT r m () Source # traceTBQueueIO :: TBQueue (ReaderT r m) a -> (Maybe [a] -> [a] -> InspectMonad (ReaderT r m) TraceValue) -> ReaderT r m () Source # traceTSemIO :: TSem (ReaderT r m) -> (Maybe Integer -> Integer -> InspectMonad (ReaderT r m) TraceValue) -> ReaderT r m () Source # |
data TraceValue where Source #
A GADT which instructs how to trace the value. The traceDynamic
will
use dynamic tracing, e.g. "Control.Monad.IOSim.traceM"; while traceString
will be traced with EventSay
. The IOSim
s dynamic tracing allows to
recover the value from the simulation trace (see
"Control.Monad.IOSim.selectTraceEventsDynamic").
TraceValue | |
|
pattern TraceDynamic :: () => Typeable tr => tr -> TraceValue | Use only a dynamic tracer. |
pattern TraceString :: String -> TraceValue | Use only string tracing. |
pattern DontTrace :: TraceValue | Do not trace the value. |
class (MonadSTM m, Monad (InspectMonad m)) => MonadInspectSTM (m :: Type -> Type) where Source #
This type class is indented for
'io-sim', where one might want
to access a TVar
in the underlying ST
monad.
inspectTVar :: proxy m -> TVar m a -> InspectMonad m a Source #
Return the value of a TVar
as an InspectMonad
computation.
inspectTVar
is useful if the value of a TVar
observed by traceTVar
contains other TVar
s.
inspectTMVar :: proxy m -> TMVar m a -> InspectMonad m (Maybe a) Source #
Return the value of a TMVar
as an InspectMonad
computation.
Instances
MonadInspectSTM IO Source # | |||||
Defined in Control.Monad.Class.MonadSTM.Internal
inspectTVar :: proxy IO -> TVar IO a -> InspectMonad IO a Source # inspectTMVar :: proxy IO -> TMVar IO a -> InspectMonad IO (Maybe a) Source # | |||||
MonadInspectSTM m => MonadInspectSTM (ReaderT r m) Source # | |||||
Defined in Control.Monad.Class.MonadSTM.Internal
inspectTVar :: proxy (ReaderT r m) -> TVar (ReaderT r m) a -> InspectMonad (ReaderT r m) a Source # inspectTMVar :: proxy (ReaderT r m) -> TMVar (ReaderT r m) a -> InspectMonad (ReaderT r m) (Maybe a) Source # |