This module is about segmented signals.
For a general introduction to signals, see the documentation of FRP.Grapefruit.Signal.
- data SSignal era val
- construct :: val -> DSignal era val -> SSignal era val
- fromInitAndUpdate :: val -> DSignal era val -> SSignal era val
- withInit :: Signal signal => SSignal era val -> (val -> signal era val') -> signal era val'
- updates :: SSignal era val -> DSignal era val
- scan :: accu -> (accu -> val -> accu) -> DSignal era val -> SSignal era accu
- consumer :: (val -> IO ()) -> Consumer SSignal val
- producer :: IO val -> (IO () -> Setup) -> Producer SSignal val
Segmented signal type
The type of segmented signals.
A segmented signal maps times to values like a continuous signal. However, it also comprises a set of discrete times, called update points. The signal can only change its value at its update points. As a special case, the starting time of the era is always considered an update point. So a segmented signal is composed of constant segments which are either bounded by adjacent update points or left-bounded by a last update point and right-unbounded. Note that value updates already take effect at the update point so that the segments are left-closed.
It follows that a segmented signal is completely determined by the update points and the values assigned to them. Therefore, a segmented signal can also be seen as a kind of discrete signal with occurences at the update points. The only difference to a discrete signal is that a segmented signal always has an occurence at the starting time of the era whereas a discrete signal never has one.
The dual nature of segmented signals is reflected by the class instances of
SSignal is an instance of
Samplee as well as of
Sampler. The first means that it can
be sampled and therefore has a continuous aspect. The second means that it can be used to
sample a signal and therefore has a discrete aspect.
Constructs a segmented signal from an initial value and a series of updates.
construct init upd has initially the value
init. At each occurence in
upd, it has an update point and changes its value to the value occuring in
the segmented signal is interpreted as a kind of discrete signal,
adds an initial occurence of
init to the signal
Deprecated: fromInitAndUpdate is replaced by construct.
Applies the second argument to the initial value of the first argument.
withInit, it is possible to create a signal which is dependent on the initial value
of a segmented signal but it is not possible to extract the initial value itself. The reason
for this restriction is that the initial value may depend on values of continuous signals
and therefore its calculation might involve doing I/O to read external continuous sources.
Yields the sequence of updates of a segmented signal.
If the segmented signal is interpreted as a discrete signal with an additional occurence at
the start then
update just drops this occurence.
Accumulates the values of a discrete signal.
scan init fun to a discrete signal replaces its occurence values
val_2 and so on by the values
init `fun` val_1,
`fun` val_1) `fun` val_2 and so on and adds an occurence of
init at the beginning.
Converts an event handler into a segmented signal consumer.
If a segmented signal is consumed with such a consumer, the handler is called at the
starting time of the era and at each update with the current value of the signal as its
argument. If the segmented signal is seen as a discrete signal with an additional occurence
at the start then
consumer behaves analogous to the
consumer function of
|:: IO val|
an action reading the current value of the signal
|-> (IO () -> Setup)|
an action which registers a given event handler so that it is called everytime the value of the signal has changed
|-> Producer SSignal val|
Converts a value read action and a change event handler registration into a segmented signal producer.