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 |
MonadSTM
testing implementation, internal types and definitions.
This module is NOT considered to form part of the public interface
of this library.
- 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.
ModelSTM | |
|
Monad (ModelSTM n) Source # | |
Functor (ModelSTM n) Source # | |
MonadFail (ModelSTM n) Source # | |
Applicative (ModelSTM n) Source # | |
Alternative (ModelSTM n) Source # | |
MonadPlus (ModelSTM n) Source # | |
MonadSTM (ModelSTM n) Source # | |
MonadThrow (ModelSTM n) Source # | |
MonadCatch (ModelSTM n) Source # | |
type TVar (ModelSTM n) Source # | |
Primitive actions
STM transactions are represented as a sequence of primitive actions.
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 ()) |
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 :: 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.