
FRP.Reactive.PrimReactive  Stability  experimental  Maintainer  conal@conal.net 





Description 
Functional events and reactive values. Semantically, an Event is
stream of future values in time order. A Reactive value is a
discretly timevarying value.
Many of the operations on events and reactive values are packaged as
instances of the standard type classes Monoid, Functor,
Applicative, and Monad.
This module focuses on representation and primitives defined in terms
of the representation. See also FRP.Reactive.Reactive, which
reexports this module, plus extras that do not exploit the
representation. My intention for this separation is to ease
experimentation with alternative representations.
Although the basic Reactive type describes discretelychanging
values, continuouslychanging values can be modeled simply as
reactive functions. See FRP.Reactive.Behavior for a convenient type
composition of Reactive and a constantoptimized representation of
functions of time. The exact packaging of discrete vs continuous will
probably change with more experience.


Synopsis 




Events and reactive values



Events. Semantically: timeordered list of future values.
Instances:
 Monoid: mempty is the event that never occurs, and e mappend
e' is the event that combines occurrences from e and e'.
 Functor: fmap f e is the event that occurs whenever e occurs,
and whose occurrence values come from applying f to the values from
e.
 Applicative: pure a is an event with a single occurrence at time
Infinity. ef <*> ex is an event whose occurrences are made from
the product of the occurrences of ef and ex. For every occurrence
f at time tf of ef and occurrence x at time tx of ex, ef
<*> ex has an occurrence f x at time tf max tx. N.B.: I
don't expect this instance to be very useful. If ef has nf
instances and ex has nx instances, then ef <*> ex has nf*nx
instances. However, there are only nf+nx possibilities for tf
max tx, so many of the occurrences are simultaneous. If you think
you want to use this instance, consider using Reactive instead.
 Monad: return a is the same as pure a (as usual). In e >>= f,
each occurrence of e leads, through f, to a new event. Similarly
for join ee, which is somehow simpler for me to think about. The
occurrences of e >>= f (or join ee) correspond to the union of the
occurrences (temporal interleaving) of all such events. For example,
suppose we're playing Asteroids and tracking collisions. Each collision
can break an asteroid into more of them, each of which has to be tracked
for more collisions. Another example: A chat room has an enter event,
whose occurrences contain new events like speak. An especially useful
monadbased function is joinMaybes, which filters a Maybevalued
event.
 Instances  



Reactive value: a discretely changing value. Reactive values can be
understood in terms of (a) a simple denotational semantics of reactive
values as functions of time, and (b) the corresponding instances for
functions. The semantics is given by the function at :: ReactiveG t a >
(t > a). A reactive value may also be thought of (and in this module
is implemented as) a current value and an event (stream of future values).
The semantics of ReactiveG instances are given by corresponding
instances for the semantic model (functions):
 Functor: at (fmap f r) == fmap f (at r), i.e., fmap f r at
t == f (r at t).
 Applicative: at (pure a) == pure a, and at (s <*> r) == at s
<*> at t. That is, pure a at t == a, and (s <*> r) at t
== (s at t) (r at t).
 Monad: at (return a) == return a, and at (join rr) == join (at
. at rr). That is, return a at t == a, and join rr at t ==
(rr at t) at t. As always, (r >>= f) == join (fmap f r).
at (r >>= f) == at r >>= at . f.
 Monoid: a typical lifted monoid. If o is a monoid, then
Reactive o is a monoid, with mempty == pure mempty, and mappend
== liftA2 mappend. That is, mempty at t == mempty, and (r
mappend s) at t == (r at t) mappend (s at t).
 Instances  


Operations on events and reactive values



Reactive value from an initial value and a newvalue event.



Switch between reactive values.



Access occurrence times in an event. See also withTimeGR.



Access occurrence times in a reactive value. See also withTimeGE.



Convert a temporally monotonic list of futures to an event



Convert a temporally monotonic list of futures to an event. See also
the specialization listE



Event at given times. See also atTimeG.



Singleoccurrence event at given time.



Snapshot a reactive value whenever an event occurs and apply a
combining function to the event and reactive's values.



Accumulating event, starting from an initial value and a
updatefunction event. See also accumR.



Reactive value from an initial value and an updater event. See also
accumE.



Just the first occurrence of an event.



Access the remainder with each event occurrence.



Truncate first event at first occurrence of second event.



Pass through the Just occurrences, stripped. Experimental
specialization of joinMaybes.



Pass through values satisfying a given predicate. Experimental
specialization of filterMP.



Extract a future representing the first occurrence of the event together
with the event of all occurrences after that one.


To be moved elsewhere



Pass through Just occurrences.



Pass through values satisfying p.


result :: (b > b') > (a > b) > a > b'  Source 

Apply a given function inside the results of other functions.
Equivalent to '(.)', but has a nicer reading when composed


To be removed when it gets used somewhere




Testing






Produced by Haddock version 2.4.2 