Copyright | (c) 2017--2019 Michael Walker |
---|---|
License | MIT |
Maintainer | Michael Walker <mike@barrucadu.co.uk> |
Stability | experimental |
Portability | CPP, ExistentialQuantification, NoMonoLocalBinds, RecordWildCards, TypeFamilies |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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
- = forall a e.Exception e => SCatch (e -> ModelSTM n a) (ModelSTM n a) (a -> STMAction n)
- | forall a. SRead (ModelTVar n a) (a -> STMAction n)
- | forall a. SWrite (ModelTVar n a) a (STMAction n)
- | forall a. SOrElse (ModelSTM n a) (ModelSTM n a) (a -> STMAction n)
- | forall a. SNew String a (ModelTVar n a -> STMAction n)
- | forall e.Exception e => SThrow e
- | SRetry
- | SStop (n ())
- data ModelTVar n a = ModelTVar {}
- data Result a
- runTransaction :: MonadDejaFu n => ModelSTM n a -> IdSource -> n (Result a, n (), IdSource, [TAction])
- doTransaction :: MonadDejaFu n => ModelSTM n a -> IdSource -> n (Result a, n (), n (), IdSource, [TAction])
- stepTrans :: MonadDejaFu n => STMAction n -> IdSource -> n (STMAction n, 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.
ModelSTM | |
|
Instances
MonadFail (ModelSTM n) Source # | |
Defined in Test.DejaFu.Conc.Internal.STM | |
Alternative (ModelSTM n) Source # | |
Applicative (ModelSTM n) Source # | |
Defined in Test.DejaFu.Conc.Internal.STM | |
Functor (ModelSTM n) Source # | |
Monad (ModelSTM n) Source # | |
MonadPlus (ModelSTM n) Source # | |
MonadSTM (ModelSTM n) Source # | |
MonadCatch (ModelSTM n) Source # | |
MonadThrow (ModelSTM n) Source # | |
Defined in Test.DejaFu.Conc.Internal.STM | |
type TVar (ModelSTM n) Source # | |
Defined in Test.DejaFu.Conc.Internal.STM |
Primitive actions
STM transactions are represented as a sequence of primitive actions.
forall a e.Exception e => SCatch (e -> ModelSTM n a) (ModelSTM n a) (a -> STMAction n) | |
forall a. SRead (ModelTVar n a) (a -> STMAction n) | |
forall a. SWrite (ModelTVar n a) a (STMAction n) | |
forall a. SOrElse (ModelSTM n a) (ModelSTM n a) (a -> STMAction n) | |
forall a. SNew String a (ModelTVar n a -> STMAction n) | |
forall e.Exception e => SThrow e | |
SRetry | |
SStop (n ()) |
TVar
s
A TVar
is modelled as a unique ID and a reference holding a
value.
Output
The result of an STM transaction, along with which TVar
s it
touched whilst executing.
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 :: MonadDejaFu n => ModelSTM n a -> IdSource -> n (Result a, n (), IdSource, [TAction]) Source #
Run a transaction, returning the result and new initial TVarId
.
If the transaction failed, any effects are undone.
doTransaction :: MonadDejaFu n => ModelSTM n a -> IdSource -> n (Result a, n (), n (), IdSource, [TAction]) Source #
Run a STM transaction, returning an action to undo its effects.
If the transaction fails, its effects will automatically be undone,
so the undo action returned will be pure ()
.