aivika-0.6.1: A multi-paradigm simulation library

Stabilityexperimental
MaintainerDavid Sorokin <david.sorokin@gmail.com>
Safe HaskellSafe-Inferred

Simulation.Aivika.Dynamics.Signal

Description

Tested with: GHC 7.6.3

This module defines the signal which we can subscribe handlers to. These handlers can be disposed. The signal is triggered in the current time point actuating the corresponded computations from the handlers.

Synopsis

Documentation

data Signal a Source

The signal that can have disposable handlers.

Instances

data SignalSource a Source

The signal source that can publish its signal.

newSignalSource :: EventQueue -> Simulation (SignalSource a)Source

Create a new signal source when the state depends on the event queue.

Since version 0.6.1 its updateSignal function calls runQueueSyncBefore instead of runQueueSync as it was before. In case of need you can define your own update function with help of newSignalSourceWithUpdate.

The function has the following defintion:

 newSignalSource queue = 
   newSignalSourceWithUpdate $ runQueueSyncBefore queue

newSignalSourceWithUpdate :: Dynamics () -> Simulation (SignalSource a)Source

Create a new signal source with the specified update computation.

newSignalInTimes :: EventQueue -> [Double] -> Dynamics (Signal Double)Source

Return a signal that is triggered in the specified time points.

newSignalInIntegTimes :: EventQueue -> Dynamics (Signal Double)Source

Return a signal that is triggered in the integration time points. It should be called with help of runDynamicsInStartTime.

newSignalInStartTime :: EventQueue -> Dynamics (Signal Double)Source

Return a signal that is triggered in the start time. It should be called with help of runDynamicsInStartTime.

newSignalInStopTime :: EventQueue -> Dynamics (Signal Double)Source

Return a signal that is triggered in the stop time.

publishSignal :: SignalSource a -> Signal aSource

Publish the signal.

triggerSignal :: SignalSource a -> a -> Dynamics ()Source

Trigger the signal actuating all its handlers at the current simulation time point.

handleSignal :: Signal a -> (a -> Dynamics ()) -> Dynamics (Dynamics ())Source

Subscribe the handler to the specified signal and return a nested computation that, being applied, unsubscribes the handler from this signal.

If the signal is bound up with the event queue then the signal in the current time is not lost by the handler any more. Changed in version 0.6.1.

handleSignal_ :: Signal a -> (a -> Dynamics ()) -> Dynamics ()Source

Subscribe the handler to the specified signal. To subscribe the disposable handlers, use function handleSignal.

If the signal is bound up with the event queue then the signal in the current time is not lost by the handler any more. Changed in version 0.6.1.

updateSignal :: Signal a -> Dynamics ()Source

Update the signal to its actual state.

You will rarely need to call this function directly as it is usually called implicitly.

Since version 0.6.1 it processes only those events which time is less than the current simulation time if the signal is bound up with the event queue, although you can define your own updateSignal function when creating a new signal source with help of newSignalSourceWithUpdate.

awaitSignal :: Signal a -> Process aSource

Await the signal.

mapSignal :: (a -> b) -> Signal a -> Signal bSource

Map the signal according the specified function.

mapSignalM :: (a -> Dynamics b) -> Signal a -> Signal bSource

Compose the signal.

apSignal :: Dynamics (a -> b) -> Signal a -> Signal bSource

Transform the signal.

filterSignal :: (a -> Bool) -> Signal a -> Signal aSource

Filter only those signal values that satisfy to the specified predicate.

filterSignalM :: (a -> Dynamics Bool) -> Signal a -> Signal aSource

Filter only those signal values that satisfy to the specified predicate.

emptySignal :: Signal aSource

An empty signal which is never triggered.

merge2Signals :: Signal a -> Signal a -> Signal aSource

Merge two signals.

merge3Signals :: Signal a -> Signal a -> Signal a -> Signal aSource

Merge three signals.

merge4Signals :: Signal a -> Signal a -> Signal a -> Signal a -> Signal aSource

Merge four signals.

merge5Signals :: Signal a -> Signal a -> Signal a -> Signal a -> Signal a -> Signal aSource

Merge five signals.

data SignalHistory a Source

Represents the history of the signal values.

signalHistorySignal :: SignalHistory a -> Signal aSource

The signal for which the history is created.

newSignalHistory :: Signal a -> Dynamics (SignalHistory a)Source

Create a history of the signal values.

newSignalHistoryThrough :: EventQueue -> Signal a -> Dynamics (SignalHistory a)Source

Create a history of the signal values with delay through the event queue. The history will be created at the same simulation time, just the corresponded handler will be subscribed to the signal after the new event will be processed by the queue.

Since version 0.6.1, this function has less meaning than before. Please use carefully as the behavior depends on the state of the event queue.

readSignalHistory :: SignalHistory a -> Dynamics (Array Int Double, Array Int a)Source

Read the history of signal values.