`React.S`

Signal combinators.

Consult their semantics.

`type 'a t = 'a signal`

The type for signals of type `'a`

.

`val const : 'a -> 'a signal`

`const v`

is always `v`

, [`const v`

]_{t} `= v`

.

`create i`

is a primitive signal `s`

set to `i`

and a `set`

function. The function `set`

is such that:

`set v`

sets the signal's value to`v`

at the time it is called and triggers an update step.`set ~step v`

sets the signal's value to`v`

at the time it is called and updates it dependencies when`step`

is executed`set ~step v`

raises`Invalid_argument`

if it was previously called with a step and this step has not executed yet or if the given`step`

was already executed.

**Warning.** `set`

must not be executed inside an update step.

`val value : 'a signal -> 'a`

`value s`

is `s`

's current value.

**Warning.** If executed in an update step may return a non up-to-date value or raise `Failure`

if the signal is not yet initialized.

`val retain : 'a signal -> ( unit -> unit ) -> [ `R of unit -> unit ]`

`retain s c`

keeps a reference to the closure `c`

in `s`

and returns the previously retained value. `c`

will *never* be invoked.

**Raises.** `Invalid_argument`

on constant signals.

`val stop : ?strong:bool -> 'a signal -> unit`

`stop s`

, stops updating `s`

. It conceptually becomes `const`

with the signal's last value and cannot be restarted. Allows to disable effectful signals.

The `strong`

argument should only be used on platforms where weak arrays have a strong semantics (i.e. JavaScript). See details.

**Note.** If executed in an update step the signal may still update in the step.

`trace iff tr s`

is `s`

except `tr`

is invoked with `s`

's current value and on `s`

changes when `iff`

is `true`

(defaults to `S.const true`

). For all t where [`s`

]_{t} `= v`

and (t = 0 or ([`s`

]_{t-dt}`= v'`

and `eq v v' = false`

)) and [`iff`

]_{t} = `true`

, `tr`

is invoked with `v`

.

`hold i e`

has the value of `e`

's last occurrence or `i`

if there wasn't any.

- [
`hold i e`

]_{t}`= i`

if [`e`

]_{<=t}`= None`

- [
`hold i e`

]_{t}`= v`

if [`e`

]_{<=t}`= Some v`

`app sf s`

holds the value of `sf`

applied to the value of `s`

, [`app sf s`

]_{t} `=`

[`sf`

]_{t} [`s`

]_{t}.

`map f s`

is `s`

transformed by `f`

, [`map f s`

]_{t} = `f`

[`s`

]_{t}.

`filter f i s`

is `s`

's values that satisfy `p`

. If a value does not satisfy `p`

it holds the last value that was satisfied or `i`

if there is none.

- [
`filter p s`

]_{t}`=`

[`s`

]_{t}if`p`

[`s`

]_{t}`= true`

. - [
`filter p s`

]_{t}`=`

[`s`

]_{t'}if`p`

[`s`

]_{t}`= false`

and t' is the greatest t' < t with`p`

[`s`

]_{t'}`= true`

. - [
`filter p e`

]_{t}`= i`

otherwise.

`fmap fm i s`

is `s`

filtered and mapped by `fm`

.

- [
`fmap fm i s`

]_{t}`=`

v if`fm`

[`s`

]_{t}`= Some v`

. - [
`fmap fm i s`

]_{t}`=`

[`fmap fm i s`

]_{t'}if`fm`

[`s`

]_{t}`= None`

and t' is the greatest t' < t with`fm`

[`s`

]_{t'}`<> None`

. - [
`fmap fm i s`

]_{t}`= i`

otherwise.

`diff f s`

is an event with occurrences whenever `s`

changes from `v'`

to `v`

and `eq v v'`

is `false`

(`eq`

is the signal's equality function). The value of the occurrence is `f v v'`

.

- [
`diff f s`

]_{t}`= Some d`

if [`s`

]_{t}`= v`

and [`s`

]_{t-dt}`= v'`

and`eq v v' = false`

and`f v v' = d`

. - [
`diff f s`

]_{t}`= None`

otherwise.

`sample f e s`

samples `s`

at `e`

's occurrences.

- [
`sample f e s`

]_{t}`= Some (f ev sv)`

if [`e`

]_{t}`= Some ev`

and [`s`

]_{t}`= sv`

. - [
`sample e s`

]_{t}`= None`

otherwise.

`on c i s`

is the signal `s`

whenever `c`

is `true`

. When `c`

is `false`

it holds the last value `s`

had when `c`

was the last time `true`

or `i`

if it never was.

- [
`on c i s`

]_{t}`=`

[`s`

]_{t}if [`c`

]_{t}`= true`

- [
`on c i s`

]_{t}`=`

[`s`

]_{t'}if [`c`

]_{t}`= false`

where t' is the greatest t' < t with [`c`

]_{t'}`= true`

. - [
`on c i s`

]_{t}`=`

`i`

otherwise.

`dismiss c i s`

is the signal `s`

except changes when `c`

occurs are ignored. If `c`

occurs initially `i`

is used.

- [
`dismiss c i s`

]_{t}`=`

[`s`

]_{t'}where t' is the greatest t' <= t with [`c`

]_{t'}`= None`

and [`s`

]_{t'-dt}`<>`

[`s`

]_{t'} - [
`dismiss_ c i s`

]_{0}`=`

`v`

where`v = i`

if [`c`

]_{0}`= Some _`

and`v =`

[`s`

]_{0}otherwise.

`accum e i`

is `S.hold i (`

`E.accum`

` e i)`

.

`fold f i e`

is `S.hold i (`

`E.fold`

` f i e)`

.

`merge f a sl`

merges the value of every signal in `sl`

using `f`

and the accumulator `a`

.

[`merge f a sl`

]_{t} `= List.fold_left f a (List.map`

[]_{t}` sl)`

.

`switch ss`

is the inner signal of `ss`

.

- [
`switch ss`

]_{t}`=`

[[`ss`

]_{t}]_{t}.

`bind s sf`

is `switch (map ~eq:( == ) sf s)`

.

`fix i sf`

allow to refer to the value a signal had an infinitesimal amount of time before.

In `fix sf`

, `sf`

is called with a signal `s`

that represents the signal returned by `sf`

delayed by an infinitesimal amount time. If `s', r = sf s`

then `r`

is returned by `fix`

and `s`

is such that :

- [
`s`

]_{t}`=`

`i`

for t = 0. - [
`s`

]_{t}`=`

[`s'`

]_{t-dt}otherwise.

`eq`

is the equality used by `s`

.

**Raises.** `Invalid_argument`

if `s'`

is directly a delayed signal (i.e. a signal given to a fixing function).

**Note.** Regarding values depending on the result `r`

of `s', r = sf s`

the following two cases need to be distinguished :

After

`sf s`

is applied,`s'`

does not depend on a value that is in a step and`s`

has no dependents in a step (e.g in the simple case where`fix`

is applied outside a step).In that case if the initial value of

`s'`

differs from`i`

,`s`

and its dependents need to be updated and a special update step will be triggered for this. Values depending on the result`r`

will be created only after this special update step has finished (e.g. they won't see the`i`

of`s`

if`r = s`

).- Otherwise, values depending on
`r`

will be created in the same step as`s`

and`s'`

(e.g. they will see the`i`

of`s`

if`r = s`

).

Lifting combinators. For a given `n`

the semantics is :

[`ln f a1`

... `an`

]_{t} = f [`a1`

]_{t} ... [`an`

]_{t}

The following modules lift some of `Stdlib`

functions and operators.

`module Bool : sig ... end`

`module Int : sig ... end`

`module Float : sig ... end`

`module Pair : sig ... end`

`module Option : sig ... end`

`module Compare : sig ... end`

Given an equality function `equal`

and a type `t`

, the functor `Make`

automatically applies the `eq`

parameter of the combinators. The outcome is combinators whose *results* are signals with values in `t`

.

Basic types are already specialized in the module `Special`

, open this module to use them.

Functor specializing the combinators for the given signal value type

`module Special : sig ... end`

Specialization for booleans, integers and floats.