grapefruit-frp-0.1.0.7: Functional Reactive Programming core

Safe HaskellNone
LanguageHaskell98

FRP.Grapefruit.Signal.Segmented

Contents

Description

This module is about segmented signals.

For a general introduction to signals, see the documentation of FRP.Grapefruit.Signal.

Synopsis

Segmented signal type

data SSignal era val Source #

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. 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.

Instances

Samplee SSignal Source # 

Methods

dSample :: DSignal era (val -> val') -> SSignal era val -> DSignal era val'

sSample :: SSignal era (val -> val') -> SSignal era val -> SSignal era val'

Sampler SSignal Source # 

Methods

sample :: Samplee samplee => SSignal era (val -> val') -> samplee era val -> SSignal era val'

samplerMap :: (val -> val') -> SSignal era val -> SSignal era val'

Signal SSignal Source # 

Methods

osfSwitch :: SSignal era (PolyOSF SSignal val) -> SSignal era val

ssfSwitch :: SSignal era (PolySSF SSignal val shape) -> SSignal era val -> SignalFun era shape

Functor (SSignal era) Source # 

Methods

fmap :: (a -> b) -> SSignal era a -> SSignal era b #

(<$) :: a -> SSignal era b -> SSignal era a #

Applicative (SSignal era) Source # 

Methods

pure :: a -> SSignal era a #

(<*>) :: SSignal era (a -> b) -> SSignal era a -> SSignal era b #

(*>) :: SSignal era a -> SSignal era b -> SSignal era b #

(<*) :: SSignal era a -> SSignal era b -> SSignal era a #

Construction

construct :: val -> DSignal era val -> SSignal era val Source #

Constructs a segmented signal from an initial value and a series of updates.

A signal 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 upd. If the segmented signal is interpreted as a kind of discrete signal, fromInitAndUpdate just adds an initial occurence of init to the signal upd.

fromInitAndUpdate :: val -> DSignal era val -> SSignal era val Source #

Deprecated: fromInitAndUpdate is replaced by construct.

Same as construct.

Queries

withInit :: Signal signal => SSignal era val -> (val -> signal era val') -> signal era val' Source #

Applies the second argument to the initial value of the first argument.

Using 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.

updates :: SSignal era val -> DSignal era val Source #

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.

Stateful signals

scan :: accu -> (accu -> val -> accu) -> DSignal era val -> SSignal era accu Source #

Accumulates the values of a discrete signal.

Applying scan init fun to a discrete signal replaces its occurence values val_1, val_2 and so on by the values init `fun` val_1, (init `fun` val_1) `fun` val_2 and so on and adds an occurence of the value init at the beginning.

Connectors

consumer :: (val -> IO ()) -> Consumer SSignal val Source #

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 FRP.Grapefruit.Signal.Discrete.

producer Source #

Arguments

:: 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.