| Copyright | (c) 2017--2018 Michael Walker |
|---|---|
| License | MIT |
| Maintainer | Michael Walker <mike@barrucadu.co.uk> |
| Stability | experimental |
| Portability | ExistentialQuantification, NoMonoLocalBinds, RecordWildCards, TypeFamilies |
| Safe Haskell | None |
| Language | Haskell2010 |
Test.DejaFu.Conc.Internal.STM
Description
MonadSTM testing implementation, internal types and definitions.
This module is NOT considered to form part of the public interface
of this library.
Synopsis
- newtype ModelSTM n a = ModelSTM {
- runModelSTM :: (a -> STMAction n) -> STMAction n
- data STMAction n
- = Exception e => SCatch (e -> ModelSTM n a) (ModelSTM n a) (a -> STMAction n)
- | SRead (ModelTVar n a) (a -> STMAction n)
- | SWrite (ModelTVar n a) a (STMAction n)
- | SOrElse (ModelSTM n a) (ModelSTM n a) (a -> STMAction n)
- | SNew String a (ModelTVar n a -> STMAction n)
- | Exception e => SThrow e
- | SRetry
- | SStop (n ())
- data ModelTVar n a = ModelTVar {}
- data Result a
- runTransaction :: MonadConc n => ModelSTM n a -> IdSource -> n (Result a, IdSource, [TAction])
- doTransaction :: MonadConc n => ModelSTM n a -> IdSource -> n (Result a, n (), IdSource, [TAction])
- stepTrans :: MonadConc n => STMAction n -> IdSource -> n (STMAction n, n (), IdSource, [TVarId], [TVarId], TAction)
The ModelSTM monad
The underlying monad is based on continuations over primitive actions.
This is not Cont because we want to give it a custom MonadFail
instance.
Constructors
| ModelSTM | |
Fields
| |
Instances
| Monad (ModelSTM n) Source # | |
| Functor (ModelSTM n) Source # | |
| MonadFail (ModelSTM n) Source # | |
Defined in Test.DejaFu.Conc.Internal.STM | |
| Applicative (ModelSTM n) Source # | |
Defined in Test.DejaFu.Conc.Internal.STM | |
| Alternative (ModelSTM n) Source # | |
| MonadPlus (ModelSTM n) Source # | |
| MonadSTM (ModelSTM n) Source # | |
Defined in Test.DejaFu.Conc.Internal.STM | |
| MonadThrow (ModelSTM n) Source # | |
Defined in Test.DejaFu.Conc.Internal.STM | |
| MonadCatch (ModelSTM n) Source # | |
| type TVar (ModelSTM n) Source # | |
Defined in Test.DejaFu.Conc.Internal.STM | |
Primitive actions
STM transactions are represented as a sequence of primitive actions.
Constructors
| Exception e => SCatch (e -> ModelSTM n a) (ModelSTM n a) (a -> STMAction n) | |
| SRead (ModelTVar n a) (a -> STMAction n) | |
| SWrite (ModelTVar n a) a (STMAction n) | |
| SOrElse (ModelSTM n a) (ModelSTM n a) (a -> STMAction n) | |
| SNew String a (ModelTVar n a -> STMAction n) | |
| Exception e => SThrow e | |
| SRetry | |
| SStop (n ()) |
TVars
A TVar is modelled as a unique ID and a reference holding a
value.
Output
The result of an STM transaction, along with which TVars it
touched whilst executing.
Constructors
| Success [TVarId] [TVarId] a | The transaction completed successfully, reading the first list
|
| Retry [TVarId] | The transaction aborted by calling |
| Exception SomeException | The transaction aborted by throwing an exception. |
Execution
runTransaction :: MonadConc n => ModelSTM n a -> IdSource -> n (Result a, IdSource, [TAction]) Source #
Run a transaction, returning the result and new initial TVarId.
If the transaction failed, any effects are undone.