io-sim-0.2.0.0: A pure simlator for monadic concurrency with STM
Safe HaskellNone
LanguageHaskell2010

Control.Monad.IOSim

Synopsis

Simulation monad

data IOSim s a Source #

Instances

Instances details
Monad (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

(>>=)IOSim s a → (a → IOSim s b) → IOSim s b #

(>>)IOSim s a → IOSim s b → IOSim s b #

return ∷ a → IOSim s a #

Functor (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

fmap ∷ (a → b) → IOSim s a → IOSim s b #

(<$) ∷ a → IOSim s b → IOSim s a #

MonadFail (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

failStringIOSim s a #

Applicative (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

pure ∷ a → IOSim s a #

(<*>)IOSim s (a → b) → IOSim s a → IOSim s b #

liftA2 ∷ (a → b → c) → IOSim s a → IOSim s b → IOSim s c #

(*>)IOSim s a → IOSim s b → IOSim s b #

(<*)IOSim s a → IOSim s b → IOSim s a #

MonadThrow (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

throwMException e ⇒ e → IOSim s a #

MonadCatch (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

catchException e ⇒ IOSim s a → (e → IOSim s a) → IOSim s a #

MonadMask (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

mask ∷ ((∀ a. IOSim s a → IOSim s a) → IOSim s b) → IOSim s b #

uninterruptibleMask ∷ ((∀ a. IOSim s a → IOSim s a) → IOSim s b) → IOSim s b #

generalBracketIOSim s a → (a → ExitCase b → IOSim s c) → (a → IOSim s b) → IOSim s (b, c) #

MonadAsync (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Associated Types

type Async (IOSim s) ∷ TypeType Source #

Methods

asyncIOSim s a → IOSim s (Async (IOSim s) a) Source #

asyncThreadIdProxy (IOSim s) → Async (IOSim s) a → ThreadId (IOSim s) Source #

withAsyncIOSim s a → (Async (IOSim s) a → IOSim s b) → IOSim s b Source #

waitAsync (IOSim s) a → IOSim s a Source #

pollAsync (IOSim s) a → IOSim s (Maybe (Either SomeException a)) Source #

waitCatchAsync (IOSim s) a → IOSim s (Either SomeException a) Source #

cancelAsync (IOSim s) a → IOSim s () Source #

cancelWithException e ⇒ Async (IOSim s) a → e → IOSim s () Source #

uninterruptibleCancelAsync (IOSim s) a → IOSim s () Source #

waitAny ∷ [Async (IOSim s) a] → IOSim s (Async (IOSim s) a, a) Source #

waitAnyCatch ∷ [Async (IOSim s) a] → IOSim s (Async (IOSim s) a, Either SomeException a) Source #

waitAnyCancel ∷ [Async (IOSim s) a] → IOSim s (Async (IOSim s) a, a) Source #

waitAnyCatchCancel ∷ [Async (IOSim s) a] → IOSim s (Async (IOSim s) a, Either SomeException a) Source #

waitEitherAsync (IOSim s) a → Async (IOSim s) b → IOSim s (Either a b) Source #

waitEitherCatchAsync (IOSim s) a → Async (IOSim s) b → IOSim s (Either (Either SomeException a) (Either SomeException b)) Source #

waitEitherCancelAsync (IOSim s) a → Async (IOSim s) b → IOSim s (Either a b) Source #

waitEitherCatchCancelAsync (IOSim s) a → Async (IOSim s) b → IOSim s (Either (Either SomeException a) (Either SomeException b)) Source #

waitEither_Async (IOSim s) a → Async (IOSim s) b → IOSim s () Source #

waitBothAsync (IOSim s) a → Async (IOSim s) b → IOSim s (a, b) Source #

raceIOSim s a → IOSim s b → IOSim s (Either a b) Source #

race_IOSim s a → IOSim s b → IOSim s () Source #

concurrentlyIOSim s a → IOSim s b → IOSim s (a, b) Source #

concurrently_IOSim s a → IOSim s b → IOSim s () Source #

asyncWithUnmask ∷ ((∀ b. IOSim s b → IOSim s b) → IOSim s a) → IOSim s (Async (IOSim s) a) Source #

MonadDelay (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

threadDelayDiffTimeIOSim s () Source #

MonadTimer (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Associated Types

data Timeout (IOSim s) Source #

MonadMonotonicTime (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

MonadTime (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

MonadSTM (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Associated Types

type STM (IOSim s) ∷ TypeType Source #

Methods

atomicallyHasCallStackSTM (IOSim s) a → IOSim s a Source #

newTVarIO ∷ a → IOSim s (TVar (IOSim s) a) Source #

newTMVarIO ∷ a → IOSim s (TMVar (IOSim s) a) Source #

newEmptyTMVarIOIOSim s (TMVar (IOSim s) a) Source #

newTBQueueIONaturalIOSim s (TBQueue (IOSim s) a) Source #

MonadThrow (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

throwIOException e ⇒ e → IOSim s a Source #

bracketIOSim s a → (a → IOSim s b) → (a → IOSim s c) → IOSim s c Source #

bracket_IOSim s a → IOSim s b → IOSim s c → IOSim s c Source #

finallyIOSim s a → IOSim s b → IOSim s a Source #

MonadCatch (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

catchException e ⇒ IOSim s a → (e → IOSim s a) → IOSim s a Source #

catchJustException e ⇒ (e → Maybe b) → IOSim s a → (b → IOSim s a) → IOSim s a Source #

tryException e ⇒ IOSim s a → IOSim s (Either e a) Source #

tryJustException e ⇒ (e → Maybe b) → IOSim s a → IOSim s (Either b a) Source #

handleException e ⇒ (e → IOSim s a) → IOSim s a → IOSim s a Source #

handleJustException e ⇒ (e → Maybe b) → (b → IOSim s a) → IOSim s a → IOSim s a Source #

onExceptionIOSim s a → IOSim s b → IOSim s a Source #

bracketOnErrorIOSim s a → (a → IOSim s b) → (a → IOSim s c) → IOSim s c Source #

generalBracketIOSim s a → (a → ExitCase b → IOSim s c) → (a → IOSim s b) → IOSim s (b, c) Source #

MonadMask (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

mask ∷ ((∀ a. IOSim s a → IOSim s a) → IOSim s b) → IOSim s b Source #

uninterruptibleMask ∷ ((∀ a. IOSim s a → IOSim s a) → IOSim s b) → IOSim s b Source #

mask_IOSim s a → IOSim s a Source #

uninterruptibleMask_IOSim s a → IOSim s a Source #

MonadEvaluate (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

evaluate ∷ a → IOSim s a Source #

MonadSay (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

sayStringIOSim s () Source #

MonadST (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

withLiftST ∷ (∀ s0. (∀ a. ST s0 a → IOSim s a) → b) → b Source #

MonadThread (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Associated Types

type ThreadId (IOSim s) Source #

MonadFork (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

forkIOIOSim s () → IOSim s (ThreadId (IOSim s)) Source #

forkIOWithUnmask ∷ ((∀ a. IOSim s a → IOSim s a) → IOSim s ()) → IOSim s (ThreadId (IOSim s)) Source #

throwToException e ⇒ ThreadId (IOSim s) → e → IOSim s () Source #

killThreadThreadId (IOSim s) → IOSim s () Source #

MonadEventlog (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

traceEventIOStringIOSim s () Source #

traceMarkerIOStringIOSim s () Source #

type Async (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

type Async (IOSim s)
data Timeout (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

data Timeout (IOSim s)
type STM (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

type STM (IOSim s) = STM s
type ThreadId (IOSim s) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Run simulation

runSim ∷ ∀ a. (∀ s. IOSim s a) → Either Failure a Source #

IOSim is a pure monad.

runSimOrThrow ∷ ∀ a. (∀ s. IOSim s a) → a Source #

For quick experiments and tests it is often appropriate and convenient to simply throw failures as exceptions.

runSimStrictShutdown ∷ ∀ a. (∀ s. IOSim s a) → Either Failure a Source #

Like runSim but also fail if when the main thread terminates, there are other threads still running or blocked. If one is trying to follow a strict thread cleanup policy then this helps testing for that.

data Failure Source #

Simulation termination with failure

Constructors

FailureException SomeException

The main thread terminated with an exception

FailureDeadlock

The threads all deadlocked

FailureSloppyShutdown [LabeledThread]

The main thread terminated normally but other threads were still alive, and strict shutdown checking was requested. See runSimStrictShutdown

Instances

Instances details
Show Failure Source # 
Instance details

Defined in Control.Monad.IOSim

Methods

showsPrecIntFailureShowS #

showFailureString #

showList ∷ [Failure] → ShowS #

Exception Failure Source # 
Instance details

Defined in Control.Monad.IOSim

runSimTrace ∷ ∀ a. (∀ s. IOSim s a) → Trace a Source #

See runSimTraceST below.

runSimTraceST ∷ ∀ s a. IOSim s a → ST s (Trace a) Source #

The most general method of running IOSim is in ST monad. One can recover failures or the result from Trace with traceResult, or access TraceEvents generated by the computation with traceEvents. A slightly more convenient way is exposed by runSimTrace.

liftSTST s a → IOSim s a Source #

traceMTypeable a ⇒ a → IOSim s () Source #

Simulation time

setCurrentTimeUTCTimeIOSim s () Source #

Set the current wall clock time for the thread's clock domain.

unshareClockIOSim s () Source #

Put the thread into a new wall clock domain, not shared with the parent thread. Changing the wall clock time in the new clock domain will not affect the other clock of other threads. All threads forked by this thread from this point onwards will share the new clock domain.

Simulation trace

data Trace a Source #

Trace is a recursive data type, it is the trace of a IOSim computation. The trace will contain information about thread sheduling, blocking on TVars, and other internal state changes of IOSim. More importantly it also supports traces generated by the computation with say (which corresponds to using putStrLn in IO), traceEventM, or dynamically typed traces with traceM (which generalise the base library traceM)

See also: traceEvents, traceResult, selectTraceEvents, selectTraceEventsDynamic and printTraceEventsSay.

Instances

Instances details
Show a ⇒ Show (Trace a) Source # 
Instance details

Defined in Control.Monad.IOSim.Internal

Methods

showsPrecIntTrace a → ShowS #

showTrace a → String #

showList ∷ [Trace a] → ShowS #

selectTraceEvents ∷ (TraceEventMaybe b) → Trace a → [b] Source #

selectTraceEventsDynamic ∷ ∀ a b. Typeable b ⇒ Trace a → [b] Source #

Select all the traced values matching the expected type. This relies on the sim's dynamic trace facility.

For convenience, this throws exceptions for abnormal sim termination.

selectTraceEventsSayTrace a → [String] Source #

Get a trace of EventSay.

For convenience, this throws exceptions for abnormal sim termination.

printTraceEventsSayTrace a → IO () Source #

Print all EventSay to the console.

For convenience, this throws exceptions for abnormal sim termination.

Eventlog

newtype EventlogEvent Source #

Wrapper for Eventlog events so they can be retrieved from the trace with selectTraceEventsDynamic.

Constructors

EventlogEvent String 

newtype EventlogMarker Source #

Wrapper for Eventlog markers so they can be retrieved from the trace with selectTraceEventsDynamic.

Constructors

EventlogMarker String 

Low-level API

execReadTVar ∷ TVar s a → ST s a Source #

Deprecated interfaces

type SimM s = IOSim s Source #

Deprecated: Use IOSim

type SimSTM = STM Source #

Deprecated: Use STMSim