Copyright | Copyright (c) 2009-2017 David Sorokin <david.sorokin@gmail.com> |
---|---|
License | BSD3 |
Maintainer | David Sorokin <david.sorokin@gmail.com> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Tested with: GHC 8.0.1
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.
- data Signal m a = Signal {
- handleSignal :: (a -> Event m ()) -> Event m (DisposableEvent m)
- handleSignal_ :: MonadDES m => Signal m a -> (a -> Event m ()) -> Event m ()
- handleSignalComposite :: MonadDES m => Signal m a -> (a -> Event m ()) -> Composite m ()
- data SignalSource m a
- newSignalSource :: MonadDES m => Simulation m (SignalSource m a)
- newSignalSource0 :: (MonadDES m, MonadRef0 m) => m (SignalSource m a)
- publishSignal :: SignalSource m a -> Signal m a
- triggerSignal :: SignalSource m a -> a -> Event m ()
- mapSignal :: MonadDES m => (a -> b) -> Signal m a -> Signal m b
- mapSignalM :: MonadDES m => (a -> Event m b) -> Signal m a -> Signal m b
- apSignal :: MonadDES m => Event m (a -> b) -> Signal m a -> Signal m b
- filterSignal :: MonadDES m => (a -> Bool) -> Signal m a -> Signal m a
- filterSignal_ :: MonadDES m => (a -> Bool) -> Signal m a -> Signal m ()
- filterSignalM :: MonadDES m => (a -> Event m Bool) -> Signal m a -> Signal m a
- filterSignalM_ :: MonadDES m => (a -> Event m Bool) -> Signal m a -> Signal m ()
- emptySignal :: MonadDES m => Signal m a
- merge2Signals :: MonadDES m => Signal m a -> Signal m a -> Signal m a
- merge3Signals :: MonadDES m => Signal m a -> Signal m a -> Signal m a -> Signal m a
- merge4Signals :: MonadDES m => Signal m a -> Signal m a -> Signal m a -> Signal m a -> Signal m a
- merge5Signals :: MonadDES m => Signal m a -> Signal m a -> Signal m a -> Signal m a -> Signal m a -> Signal m a
- arrivalSignal :: MonadDES m => Signal m a -> Signal m (Arrival a)
- delaySignal :: MonadDES m => Double -> Signal m a -> Signal m a
- delaySignalM :: MonadDES m => Event m Double -> Signal m a -> Signal m a
- data SignalHistory m a
- signalHistorySignal :: SignalHistory m a -> Signal m a
- newSignalHistory :: MonadDES m => Signal m a -> Composite m (SignalHistory m a)
- newSignalHistoryStartingWith :: MonadDES m => Maybe a -> Signal m a -> Composite m (SignalHistory m a)
- readSignalHistory :: MonadDES m => SignalHistory m a -> Event m (Array Int Double, Array Int a)
- newSignalInTimes :: MonadDES m => [Double] -> Event m (Signal m Double)
- newSignalInIntegTimes :: MonadDES m => Event m (Signal m Double)
- newSignalInStartTime :: MonadDES m => Event m (Signal m Double)
- newSignalInStopTime :: MonadDES m => Event m (Signal m Double)
- newSignalInTimeGrid :: MonadDES m => Int -> Event m (Signal m Int)
- data Signalable m a = Signalable {
- readSignalable :: Event m a
- signalableChanged_ :: Signal m ()
- signalableChanged :: MonadDES m => Signalable m a -> Signal m a
- emptySignalable :: (MonadDES m, Monoid a) => Signalable m a
- appendSignalable :: (MonadDES m, Semigroup a) => Signalable m a -> Signalable m a -> Signalable m a
- traceSignal :: MonadDES m => String -> Signal m a -> Signal m a
Handling and Triggering Signal
The signal that can have disposable handlers.
Signal | |
|
handleSignal_ :: MonadDES m => Signal m a -> (a -> Event m ()) -> Event m () Source #
Subscribe the handler to the specified signal forever.
To subscribe the disposable handlers, use function handleSignal
.
handleSignalComposite :: MonadDES m => Signal m a -> (a -> Event m ()) -> Composite m () Source #
Like handleSignal
but within the Composite
computation.
data SignalSource m a Source #
The signal source that can publish its signal.
newSignalSource :: MonadDES m => Simulation m (SignalSource m a) Source #
Create a new signal source.
newSignalSource0 :: (MonadDES m, MonadRef0 m) => m (SignalSource m a) Source #
Create a new signal source within more low level computation than Simulation
.
publishSignal :: SignalSource m a -> Signal m a Source #
Publish the signal.
triggerSignal :: SignalSource m a -> a -> Event m () Source #
Trigger the signal actuating all its handlers at the current simulation time point.
Useful Combinators
mapSignal :: MonadDES m => (a -> b) -> Signal m a -> Signal m b Source #
Map the signal according the specified function.
mapSignalM :: MonadDES m => (a -> Event m b) -> Signal m a -> Signal m b Source #
Compose the signal.
apSignal :: MonadDES m => Event m (a -> b) -> Signal m a -> Signal m b Source #
Transform the signal.
filterSignal :: MonadDES m => (a -> Bool) -> Signal m a -> Signal m a Source #
Filter only those signal values that satisfy the specified predicate.
filterSignal_ :: MonadDES m => (a -> Bool) -> Signal m a -> Signal m () Source #
Filter only those signal values that satisfy the specified predicate, but then ignoring the values.
filterSignalM :: MonadDES m => (a -> Event m Bool) -> Signal m a -> Signal m a Source #
Filter only those signal values that satisfy the specified predicate.
filterSignalM_ :: MonadDES m => (a -> Event m Bool) -> Signal m a -> Signal m () Source #
Filter only those signal values that satisfy the specified predicate, but then ignoring the values.
emptySignal :: MonadDES m => Signal m a Source #
An empty signal which is never triggered.
merge3Signals :: MonadDES m => Signal m a -> Signal m a -> Signal m a -> Signal m a Source #
Merge three signals.
merge4Signals :: MonadDES m => Signal m a -> Signal m a -> Signal m a -> Signal m a -> Signal m a Source #
Merge four signals.
merge5Signals :: MonadDES m => Signal m a -> Signal m a -> Signal m a -> Signal m a -> Signal m a -> Signal m a Source #
Merge five signals.
Signal Arriving
arrivalSignal :: MonadDES m => Signal m a -> Signal m (Arrival a) Source #
Transform a signal so that the resulting signal returns a sequence of arrivals saving the information about the time points at which the original signal was received.
Delaying Signal
delaySignal :: MonadDES m => Double -> Signal m a -> Signal m a Source #
Delay the signal values for the specified time interval.
delaySignalM :: MonadDES m => Event m Double -> Signal m a -> Signal m a Source #
Delay the signal values for time intervals recalculated for each value.
Signal History
data SignalHistory m a Source #
Represents the history of the signal values.
signalHistorySignal :: SignalHistory m a -> Signal m a Source #
The signal for which the history is created.
newSignalHistory :: MonadDES m => Signal m a -> Composite m (SignalHistory m a) Source #
Create a history of the signal values.
newSignalHistoryStartingWith :: MonadDES m => Maybe a -> Signal m a -> Composite m (SignalHistory m a) Source #
Create a history of the signal values starting with the optional initial value.
readSignalHistory :: MonadDES m => SignalHistory m a -> Event m (Array Int Double, Array Int a) Source #
Read the history of signal values.
Creating Signal in Time Points
newSignalInTimes :: MonadDES m => [Double] -> Event m (Signal m Double) Source #
Return a signal that is triggered in the specified time points.
newSignalInIntegTimes :: MonadDES m => Event m (Signal m Double) Source #
Return a signal that is triggered in the integration time points.
It should be called with help of runEventInStartTime
.
newSignalInStartTime :: MonadDES m => Event m (Signal m Double) Source #
Return a signal that is triggered in the start time.
It should be called with help of runEventInStartTime
.
newSignalInStopTime :: MonadDES m => Event m (Signal m Double) Source #
Return a signal that is triggered in the final time.
newSignalInTimeGrid :: MonadDES m => Int -> Event m (Signal m Int) Source #
Return a signal that is trigged in the grid by specified size.
Return a signal that is trigged in the grid by specified size.
Signalable Computations
data Signalable m a Source #
Describes a computation that also signals when changing its value.
Signalable | |
|
MonadDES m => ResultComputing Signalable m Source # | |
Functor m => Functor (Signalable m) Source # | |
(MonadDES m, Semigroup a) => Semigroup (Signalable m a) Source # | |
(MonadDES m, Monoid a, Semigroup a) => Monoid (Signalable m a) Source # | |
(MonadDES m, ResultItemable (ResultValue [e])) => ResultProvider (Signalable m (Vector e)) m Source # | |
(Ix i, Show i, MonadDES m, ResultItemable (ResultValue [e])) => ResultProvider (Signalable m (Array i e)) m Source # | |
(MonadDES m, ResultItemable (ResultValue a), ResultItemable (ResultValue (TimingStats a))) => ResultProvider (Signalable m (TimingCounter a)) m Source # | |
(MonadDES m, ResultItemable (ResultValue a), ResultItemable (ResultValue (SamplingStats a))) => ResultProvider (Signalable m (SamplingCounter a)) m Source # | |
(MonadDES m, ResultItemable (ResultValue a)) => ResultProvider (Signalable m a) m Source # | |
signalableChanged :: MonadDES m => Signalable m a -> Signal m a Source #
Return a signal notifying that the value has changed.
emptySignalable :: (MonadDES m, Monoid a) => Signalable m a Source #
Return an identity.
appendSignalable :: (MonadDES m, Semigroup a) => Signalable m a -> Signalable m a -> Signalable m a Source #
An associative operation.