aivika-5.7: A multi-method simulation library

CopyrightCopyright (c) 2009-2017 David Sorokin <david.sorokin@gmail.com>
LicenseBSD3
MaintainerDavid Sorokin <david.sorokin@gmail.com>
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Simulation.Aivika.Internal.Cont

Description

Tested with: GHC 8.0.1

This is an internal implementation module that should never be used directly.

The Cont monad is a variation of the standard Cont monad and F# async workflow, where the result of applying the continuations is the Event computation.

Synopsis

Documentation

data ContCancellation Source #

It defines how the parent and child computations should be cancelled.

Constructors

CancelTogether

Cancel the both computations together.

CancelChildAfterParent

Cancel the child if its parent is cancelled.

CancelParentAfterChild

Cancel the parent if its child is cancelled.

CancelInIsolation

Cancel the computations in isolation.

data ContId Source #

It identifies the Cont computation.

Instances

Eq ContId Source # 

Methods

(==) :: ContId -> ContId -> Bool #

(/=) :: ContId -> ContId -> Bool #

data ContEvent Source #

The event that occurs within the Cont computation.

Constructors

ContCancellationInitiating

Cancel the computation.

ContPreemptionBeginning

Preempt the computation.

ContPreemptionEnding

Proceed with the computation after if was preempted.

newtype Cont a Source #

The Cont type is similar to the standard Cont monad and F# async workflow but only the result of applying the continuations return the Event computation.

Constructors

Cont (ContParams a -> Event ()) 

Instances

Monad Cont Source # 

Methods

(>>=) :: Cont a -> (a -> Cont b) -> Cont b #

(>>) :: Cont a -> Cont b -> Cont b #

return :: a -> Cont a #

fail :: String -> Cont a #

Functor Cont Source # 

Methods

fmap :: (a -> b) -> Cont a -> Cont b #

(<$) :: a -> Cont b -> Cont a #

Applicative Cont Source # 

Methods

pure :: a -> Cont a #

(<*>) :: Cont (a -> b) -> Cont a -> Cont b #

liftA2 :: (a -> b -> c) -> Cont a -> Cont b -> Cont c #

(*>) :: Cont a -> Cont b -> Cont b #

(<*) :: Cont a -> Cont b -> Cont a #

MonadIO Cont Source # 

Methods

liftIO :: IO a -> Cont a #

MonadThrow Cont Source # 

Methods

throwM :: Exception e => e -> Cont a #

MonadCatch Cont Source # 

Methods

catch :: Exception e => Cont a -> (e -> Cont a) -> Cont a #

ParameterLift Cont Source # 
SimulationLift Cont Source # 
DynamicsLift Cont Source # 

Methods

liftDynamics :: Dynamics a -> Cont a Source #

EventLift Cont Source # 

Methods

liftEvent :: Event a -> Cont a Source #

data ContParams a Source #

The continuation parameters.

data FrozenCont a Source #

Represents a temporarily frozen computation.

newContId :: Simulation ContId Source #

Create a computation identifier.

contSignal :: ContId -> Signal ContEvent Source #

Signal when the computation state changes.

contCancellationInitiated :: ContId -> Event Bool Source #

Whether the cancellation was initiated.

contCancellationInitiate :: ContId -> Event () Source #

Initiate the cancellation.

contCancellationInitiating :: ContId -> Signal () Source #

Signal when the cancellation is intiating.

contCancellationActivated :: ContId -> IO Bool Source #

Whether the cancellation was activated.

contCancellationBind :: ContId -> [ContId] -> Event DisposableEvent Source #

If the main computation is cancelled then all the nested ones will be cancelled too.

contCancellationConnect Source #

Arguments

:: ContId

the parent

-> ContCancellation

how to connect

-> ContId

the child

-> Event DisposableEvent

computation of the disposable handler

Connect the parent computation to the child one.

contPreemptionBegun :: ContId -> Event Bool Source #

Whether the computation was preemtped.

contPreemptionBegin :: ContId -> Event () Source #

Preempt the computation.

contPreemptionBeginning :: ContId -> Signal () Source #

Signal when the computation is preempted.

contPreemptionEnd :: ContId -> Event () Source #

Proceed with the computation after it was preempted earlier.

contPreemptionEnding :: ContId -> Signal () Source #

Signal when the computation is proceeded after it was preempted before.

invokeCont :: ContParams a -> Cont a -> Event () Source #

Invoke the computation.

runCont Source #

Arguments

:: Cont a

the computation to run

-> (a -> Event ())

the main branch

-> (SomeException -> Event ())

the branch for handing exceptions

-> (() -> Event ())

the branch for cancellation

-> ContId

the computation identifier

-> Bool

whether to support the exception handling from the beginning

-> Event () 

Run the Cont computation with the specified cancelation source and flag indicating whether to catch exceptions from the beginning.

rerunCont :: Cont a -> ContId -> Cont a Source #

Rerun the Cont computation with the specified identifier.

spawnCont :: ContCancellation -> Cont () -> ContId -> Cont () Source #

Run the Cont computation in parallel but connect the computations.

contParallel Source #

Arguments

:: [(Cont a, ContId)]

the list of: the nested computation, the computation identifier

-> Cont [a] 

Execute the specified computations in parallel within the current computation and return their results. The cancellation of any of the nested computations affects the current computation. The exception raised in any of the nested computations is propogated to the current computation as well (if the exception handling is supported).

Here word parallel literally means that the computations are actually executed on a single operating system thread but they are processed simultaneously by the event queue.

contParallel_ Source #

Arguments

:: [(Cont a, ContId)]

the list of: the nested computation, the computation identifier

-> Cont () 

A partial case of contParallel when we are not interested in the results but we are interested in the actions to be peformed by the nested computations.

catchCont :: Exception e => Cont a -> (e -> Cont a) -> Cont a Source #

Exception handling within Cont computations.

finallyCont :: Cont a -> Cont b -> Cont a Source #

A computation with finalization part.

throwCont :: Exception e => e -> Cont a Source #

Throw the exception with the further exception handling.

By some reason, an exception raised with help of the standard throw function is not handled properly within Cont computation, altough it will be still handled if it will be wrapped in the IO monad. Therefore, you should use specialised functions like the stated one that use the throw function but within the IO computation, which allows already handling the exception.

resumeCont :: ContParams a -> a -> Event () Source #

Resume the computation by the specified parameters.

resumeECont :: ContParams a -> SomeException -> Event () Source #

Resume the exception handling by the specified parameters.

reenterCont :: ContParams a -> a -> Event () Source #

Reenter the computation parameters when needed.

freezeCont :: ContParams a -> Event (FrozenCont a) Source #

Freeze the computation parameters temporarily.

freezeContReentering :: ContParams a -> a -> Event () -> Event (FrozenCont a) Source #

Freeze the computation parameters specifying what should be done when reentering the computation.

unfreezeCont :: FrozenCont a -> Event (Maybe (ContParams a)) Source #

Unfreeze the computation.

substituteCont :: ContParams a -> (a -> Event ()) -> ContParams a Source #

Substitute the continuation.

contCanceled :: ContParams a -> IO Bool Source #

Test whether the computation is canceled.

contAwait :: Signal a -> Cont a Source #

Await the signal.

transferCont :: Cont () -> Cont a Source #

Like the GoTo statement it transfers the direction of computation, but raises an exception when used within catchCont or finallyCont.

traceCont :: String -> Cont a -> Cont a Source #

Show the debug message with the current simulation time.