Copyright | Copyright (c) 2009-2014, 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 7.8.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.
- data Signal m a = Signal {
- handleSignal :: (a -> Event m ()) -> Event m (DisposableEvent m)
- handleSignal_ :: MonadComp m => Signal m a -> (a -> Event m ()) -> Event m ()
- data SignalSource m a
- newSignalSource :: MonadComp m => Simulation m (SignalSource m a)
- publishSignal :: SignalSource m a -> Signal m a
- triggerSignal :: SignalSource m a -> a -> Event m ()
- mapSignal :: MonadComp m => (a -> b) -> Signal m a -> Signal m b
- mapSignalM :: MonadComp m => (a -> Event m b) -> Signal m a -> Signal m b
- apSignal :: MonadComp m => Event m (a -> b) -> Signal m a -> Signal m b
- filterSignal :: MonadComp m => (a -> Bool) -> Signal m a -> Signal m a
- filterSignalM :: MonadComp m => (a -> Event m Bool) -> Signal m a -> Signal m a
- emptySignal :: MonadComp m => Signal m a
- merge2Signals :: MonadComp m => Signal m a -> Signal m a -> Signal m a
- merge3Signals :: MonadComp m => Signal m a -> Signal m a -> Signal m a -> Signal m a
- merge4Signals :: MonadComp m => Signal m a -> Signal m a -> Signal m a -> Signal m a -> Signal m a
- merge5Signals :: MonadComp m => Signal m a -> Signal m a -> Signal m a -> Signal m a -> Signal m a -> Signal m a
- arrivalSignal :: MonadComp m => Signal m a -> Signal m (Arrival a)
- newSignalInTimes :: MonadComp m => [Double] -> Event m (Signal m Double)
- newSignalInIntegTimes :: MonadComp m => Event m (Signal m Double)
- newSignalInStartTime :: MonadComp m => Event m (Signal m Double)
- newSignalInStopTime :: MonadComp m => Event m (Signal m Double)
- data SignalHistory m a
- signalHistorySignal :: SignalHistory m a -> Signal m a
- newSignalHistory :: MonadComp m => Signal m a -> Event m (SignalHistory m a)
- newSignalHistoryStartingWith :: MonadComp m => Maybe a -> Signal m a -> Event m (SignalHistory m a)
- readSignalHistory :: MonadComp m => SignalHistory m a -> Event m (Array Int Double, Array Int a)
- data Signalable m a = Signalable {
- readSignalable :: Event m a
- signalableChanged_ :: Signal m ()
- signalableChanged :: MonadComp m => Signalable m a -> Signal m a
- emptySignalable :: (MonadComp m, Monoid a) => Signalable m a
- appendSignalable :: (MonadComp m, Monoid a) => Signalable m a -> Signalable m a -> Signalable m a
Handling and Triggering Signal
The signal that can have disposable handlers.
Signal | |
|
handleSignal_ :: MonadComp 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
.
data SignalSource m a Source
The signal source that can publish its signal.
newSignalSource :: MonadComp m => Simulation m (SignalSource m a) Source
Create a new signal source.
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 :: MonadComp m => (a -> b) -> Signal m a -> Signal m b Source
Map the signal according the specified function.
filterSignal :: MonadComp m => (a -> Bool) -> Signal m a -> Signal m a Source
Filter only those signal values that satisfy to the specified predicate.
filterSignalM :: MonadComp m => (a -> Event m Bool) -> Signal m a -> Signal m a Source
Filter only those signal values that satisfy to the specified predicate.
emptySignal :: MonadComp m => Signal m a Source
An empty signal which is never triggered.
merge3Signals :: MonadComp m => Signal m a -> Signal m a -> Signal m a -> Signal m a Source
Merge three signals.
merge4Signals :: MonadComp m => Signal m a -> Signal m a -> Signal m a -> Signal m a -> Signal m a Source
Merge four signals.
merge5Signals :: MonadComp 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 :: MonadComp 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.
Creating Signal in Time Points
newSignalInTimes :: MonadComp m => [Double] -> Event m (Signal m Double) Source
Return a signal that is triggered in the specified time points.
newSignalInIntegTimes :: MonadComp 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 :: MonadComp 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 :: MonadComp m => Event m (Signal m Double) Source
Return a signal that is triggered in the final time.
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 :: MonadComp m => Signal m a -> Event m (SignalHistory m a) Source
Create a history of the signal values.
newSignalHistoryStartingWith :: MonadComp m => Maybe a -> Signal m a -> Event m (SignalHistory m a) Source
Create a history of the signal values starting with the optional initial value.
readSignalHistory :: MonadComp m => SignalHistory m a -> Event m (Array Int Double, Array Int a) Source
Read the history of signal values.
Signalable Computations
data Signalable m a Source
Describes a computation that also signals when changing its value.
Signalable | |
|
MonadComp m => ResultComputing Signalable m | |
Functor m => Functor (Signalable m) | |
(MonadComp m, Monoid a) => Monoid (Signalable m a) |
signalableChanged :: MonadComp m => Signalable m a -> Signal m a Source
Return a signal notifying that the value has changed.
emptySignalable :: (MonadComp m, Monoid a) => Signalable m a Source
Return an identity.
appendSignalable :: (MonadComp m, Monoid a) => Signalable m a -> Signalable m a -> Signalable m a Source
An associative operation.