Stability  experimental 

Maintainer  conal@conal.net 
Reactive behaviors (continuous time)
 data BehaviorG tr tf a
 type Behavior = BehaviorI TimeT
 type Behaviour = Behavior
 time :: Ord t => BehaviorI t t
 stepper :: a > EventI t a > BehaviorI t a
 switcher :: (Ord tr, Bounded tr) => BehaviorG tr tf a > EventG tr (BehaviorG tr tf a) > BehaviorG tr tf a
 snapshotWith :: Ord t => (a > b > c) > BehaviorI t b > EventI t a > EventI t c
 snapshot :: Ord t => BehaviorI t b > EventI t a > EventI t (a, b)
 snapshot_ :: Ord t => BehaviorI t b > EventI t a > EventI t b
 whenE :: Ord t => BehaviorI t Bool > EventI t a > EventI t a
 accumB :: a > EventI t (a > a) > BehaviorI t a
 scanlB :: forall a b tr tf. (Ord tr, Bounded tr) => (b > BehaviorG tr tf a > BehaviorG tr tf a) > BehaviorG tr tf a > EventG tr b > BehaviorG tr tf a
 monoidB :: (Ord tr, Bounded tr, Monoid a) => EventG tr (BehaviorG tr tf a) > BehaviorG tr tf a
 maybeB :: Ord t => EventI t a > EventI t b > BehaviorI t (Maybe a)
 flipFlop :: Ord t => EventI t a > EventI t b > BehaviorI t Bool
 countB :: (Ord t, Num n) => EventI t a > BehaviorI t n
 sumB :: (Ord t, AdditiveGroup a) => EventI t a > BehaviorI t a
 integral :: (VectorSpace v, AffineSpace t, Scalar v ~ Diff t, Ord t) => EventI t a > BehaviorI t v > BehaviorI t v
Documentation
Reactive behaviors. They can be understood in terms of a simple
model (denotational semantics) as functions of time, namely at ::
BehaviorG t a > (t > a)
.
The semantics of BehaviorG
instances are given by corresponding
instances for the semantic model (functions). See
http://conal.net/blog/posts/simplifyingsemanticswithtypeclassmorphisms/.

Functor
:at (fmap f r) == fmap f (at r)
, i.e.,fmap f r
.at
t == f (rat
t) 
Applicative
:at (pure a) == pure a
, andat (s <*> r) == at s <*> at t
. That is,pure a
, andat
t == a(s <*> r)
.at
t == (sat
t) (rat
t) 
Monad
:at (return a) == return a
, andat (join rr) == join (at . at rr)
. That is,return a
, andat
t == ajoin rr
. As always,at
t == (rrat
t)at
t(r >>= f) == join (fmap f r)
.at (r >>= f) == at r >>= at . f
. 
Monoid
: a typical lifted monoid. Ifo
is a monoid, thenReactive o
is a monoid, withmempty == pure mempty
, andmappend == liftA2 mappend
. That is,mempty
, andat
t == mempty(r
mappend
s)at
t == (rat
t)mappend
(sat
t).
type Behavior = BehaviorI TimeTSource
Timespecialized behaviors. Note: The signatures of all of the behavior functions can be generalized. Is the interface generality worth the complexity?
time :: Ord t => BehaviorI t tSource
The identity generalized behavior. Has value t
at time t
.
time :: Behavior TimeT
stepper :: a > EventI t a > BehaviorI t aSource
Discretely changing behavior, based on an initial value and a newvalue event.
stepper :: a > Event a > Behavior a
switcher :: (Ord tr, Bounded tr) => BehaviorG tr tf a > EventG tr (BehaviorG tr tf a) > BehaviorG tr tf aSource
Switch between behaviors.
switcher :: Behavior a > Event (Behavior a) > Behavior a
snapshotWith :: Ord t => (a > b > c) > BehaviorI t b > EventI t a > EventI t cSource
Snapshots a behavior whenever an event occurs and combines the values using the combining function passed. Take careful note of the order of arguments and results.
snapshotWith :: (a > b > c) > Behavior b > Event a > Event c
snapshot :: Ord t => BehaviorI t b > EventI t a > EventI t (a, b)Source
Snapshot a behavior whenever an event occurs. See also
snapshotWith
. Take careful note of the order of arguments and
results.
snapshot :: Behavior b > Event a > Event (a,b)
snapshot_ :: Ord t => BehaviorI t b > EventI t a > EventI t bSource
Like snapshot
but discarding event data (often a
is '()').
snapshot_ :: Behavior b > Event a > Event b
whenE :: Ord t => BehaviorI t Bool > EventI t a > EventI t aSource
Filter an event according to whether a reactive boolean is true.
whenE :: Behavior Bool > Event a > Event a
accumB :: a > EventI t (a > a) > BehaviorI t aSource
Behavior from an initial value and an updater event. See also
accumE
.
accumB :: a > Event (a > a) > Behavior a
scanlB :: forall a b tr tf. (Ord tr, Bounded tr) => (b > BehaviorG tr tf a > BehaviorG tr tf a) > BehaviorG tr tf a > EventG tr b > BehaviorG tr tf aSource
Like scanl
for behaviors. See also scanlE
.
scanlB :: forall a. (Behavior a > Behavior a > Behavior a) > Behavior a > Event (Behavior a) > Behavior a
monoidB :: (Ord tr, Bounded tr, Monoid a) => EventG tr (BehaviorG tr tf a) > BehaviorG tr tf aSource
flipFlop :: Ord t => EventI t a > EventI t b > BehaviorI t BoolSource
Flipflopping behavior. Turns true whenever first event occurs and false whenever the second event occurs.
flipFlop :: Event a > Event b > Behavior Bool
countB :: (Ord t, Num n) => EventI t a > BehaviorI t nSource
Count occurrences of an event. See also countE
.
countB :: Num n => Event a > Behavior n
sumB :: (Ord t, AdditiveGroup a) => EventI t a > BehaviorI t aSource
Like sum
for behaviors.
sumB :: AdditiveGroup a => Event a > Behavior a
integral :: (VectorSpace v, AffineSpace t, Scalar v ~ Diff t, Ord t) => EventI t a > BehaviorI t v > BehaviorI t vSource
Euler integral.
integral :: (VectorSpace v, Scalar v ~ TimeT) => Event () > Behavior v > Behavior v