aivika-transformers-6.1.1: Transformers for the Aivika simulation library
CopyrightCopyright (c) 2009-2017 David Sorokin <david.sorokin@gmail.com>
LicenseBSD3
MaintainerDavid Sorokin <david.sorokin@gmail.com>
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Simulation.Aivika.Trans.Internal.Cont

Description

Tested with: GHC 8.0.1

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 ContParams m a Source #

The continuation parameters.

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.

newtype Cont m 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 m a -> Event m ()) 

Instances

Instances details
MonadDES m => MonadCompTrans Cont m Source # 
Instance details

Defined in Simulation.Aivika.Trans.Internal.Cont

Methods

liftComp :: m a -> Cont m a Source #

MonadDES m => DynamicsLift Cont m Source # 
Instance details

Defined in Simulation.Aivika.Trans.Internal.Cont

Methods

liftDynamics :: Dynamics m a -> Cont m a Source #

MonadDES m => EventLift Cont m Source # 
Instance details

Defined in Simulation.Aivika.Trans.Internal.Cont

Methods

liftEvent :: Event m a -> Cont m a Source #

MonadDES m => ParameterLift Cont m Source # 
Instance details

Defined in Simulation.Aivika.Trans.Internal.Cont

Methods

liftParameter :: Parameter m a -> Cont m a Source #

MonadDES m => SimulationLift Cont m Source # 
Instance details

Defined in Simulation.Aivika.Trans.Internal.Cont

Methods

liftSimulation :: Simulation m a -> Cont m a Source #

(MonadDES m, MonadIO m) => MonadIO (Cont m) Source # 
Instance details

Defined in Simulation.Aivika.Trans.Internal.Cont

Methods

liftIO :: IO a -> Cont m a #

MonadDES m => Applicative (Cont m) Source # 
Instance details

Defined in Simulation.Aivika.Trans.Internal.Cont

Methods

pure :: a -> Cont m a #

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

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

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

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

MonadDES m => Functor (Cont m) Source # 
Instance details

Defined in Simulation.Aivika.Trans.Internal.Cont

Methods

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

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

MonadDES m => Monad (Cont m) Source # 
Instance details

Defined in Simulation.Aivika.Trans.Internal.Cont

Methods

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

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

return :: a -> Cont m a #

MonadDES m => MonadCatch (Cont m) Source # 
Instance details

Defined in Simulation.Aivika.Trans.Internal.Cont

Methods

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

MonadDES m => MonadThrow (Cont m) Source # 
Instance details

Defined in Simulation.Aivika.Trans.Internal.Cont

Methods

throwM :: (HasCallStack, Exception e) => e -> Cont m a #

data ContId m Source #

It identifies the Cont computation.

Instances

Instances details
MonadDES m => Eq (ContId m) Source # 
Instance details

Defined in Simulation.Aivika.Trans.Internal.Cont

Methods

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

(/=) :: ContId m -> ContId m -> 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.

data FrozenCont m a Source #

Represents a temporarily frozen computation.

newContId :: MonadDES m => Simulation m (ContId m) Source #

Create a computation identifier.

contSignal :: ContId m -> Signal m ContEvent Source #

Signal when the computation state changes.

contCancellationInitiated :: MonadDES m => ContId m -> Event m Bool Source #

Whether the cancellation was initiated.

contCancellationInitiate :: MonadDES m => ContId m -> Event m () Source #

Initiate the cancellation.

contCancellationInitiating :: MonadDES m => ContId m -> Signal m () Source #

Signal when the cancellation is intiating.

contCancellationActivated :: MonadDES m => ContId m -> Event m Bool Source #

Whether the cancellation was activated.

contCancellationBind :: MonadDES m => ContId m -> [ContId m] -> Event m (DisposableEvent m) Source #

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

contCancellationConnect Source #

Arguments

:: MonadDES m 
=> ContId m

the parent

-> ContCancellation

how to connect

-> ContId m

the child

-> Event m (DisposableEvent m)

computation of the disposable handler

Connect the parent computation to the child one.

contPreemptionBegun :: MonadDES m => ContId m -> Event m Bool Source #

Whether the computation was preemtped.

contPreemptionBegin :: MonadDES m => ContId m -> Event m () Source #

Preempt the computation.

contPreemptionBeginning :: MonadDES m => ContId m -> Signal m () Source #

Signal when the computation is preempted.

contPreemptionEnd :: MonadDES m => ContId m -> Event m () Source #

Proceed with the computation after it was preempted earlier.

contPreemptionEnding :: MonadDES m => ContId m -> Signal m () Source #

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

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

Invoke the computation.

runCont Source #

Arguments

:: MonadDES m 
=> Cont m a

the computation to run

-> (a -> Event m ())

the main branch

-> (SomeException -> Event m ())

the branch for handing exceptions

-> (() -> Event m ())

the branch for cancellation

-> ContId m

the computation identifier

-> Bool

whether to support the exception handling from the beginning

-> Event m () 

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

rerunCont :: MonadDES m => Cont m a -> ContId m -> Cont m a Source #

Rerun the Cont computation with the specified identifier.

spawnCont :: MonadDES m => ContCancellation -> Cont m () -> ContId m -> Cont m () Source #

Run the Cont computation in parallel but connect the computations.

contParallel Source #

Arguments

:: MonadDES m 
=> [(Cont m a, ContId m)]

the list of pairs: the nested computation, the computation identifier

-> Cont m [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

:: MonadDES m 
=> [(Cont m a, ContId m)]

the list of pairs: the nested computation, the computation identifier

-> Cont m () 

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 :: (MonadDES m, Exception e) => Cont m a -> (e -> Cont m a) -> Cont m a Source #

Exception handling within Cont computations.

finallyCont :: MonadDES m => Cont m a -> Cont m b -> Cont m a Source #

A computation with finalization part.

throwCont :: (MonadDES m, Exception e) => e -> Cont m 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 :: MonadDES m => ContParams m a -> a -> Event m () Source #

Resume the computation by the specified parameters.

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

Resume the exception handling by the specified parameters.

reenterCont :: MonadDES m => ContParams m a -> a -> Event m () Source #

Reenter the computation parameters when needed.

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

Freeze the computation parameters temporarily.

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

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

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

Unfreeze the computation.

substituteCont :: MonadDES m => ContParams m a -> (a -> Event m ()) -> ContParams m a Source #

Substitute the continuation.

substituteContPriority :: MonadDES m => ContParams m a -> EventPriority -> ContParams m a Source #

Substitute the continuation priority.

contCanceled :: MonadDES m => ContParams m a -> Event m Bool Source #

Test whether the computation is canceled.

contAwait :: MonadDES m => Signal m a -> Cont m a Source #

Await the signal.

transferCont :: MonadDES m => Cont m () -> Cont m a Source #

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

traceCont :: MonadDES m => String -> Cont m a -> Cont m a Source #

Show the debug message with the current simulation time.