module Fr:Functional Reactive core functionssig..end
type +'a event
An event is a signal which occurs as discrete points in time.
type +'a behavior
A behavior is a signal which occurs continuously throughout time.
val never : 'a eventnever is an event which never occurs.val now : unit eventnow is an event which occurs exactly once, when a it is first
instantiated (i.e. registered or switched to).
TODO: should this accept an argument? (we can currently achieve this
with tag_e)
type -'a event_receiver
val event_receiver : unit -> 'a event_receiver * 'a eventval send_event : 'a event_receiver -> 'a -> unitval tag_e : 'a -> 'b event -> 'a eventtag_e v a replaces the value of the event a with v.val map_e : ('a -> 'b) -> 'a event -> 'b eventmap_e f e transforms the value of the event a with f.
(on e -> f) is syntactic sugar for map_e f e, and
(on e a ... -> ...) is syntactic sugar for map_e (fun a ... -> ...) e.
val filter_e : ('a -> bool) -> 'a event -> 'a eventfilter_e f e passes all occurrences of e for which f returns true.val may_e : 'a option event -> 'a eventmay_e e occurs whenever e is Some v, and has the value v.val zip_e : 'a event -> 'b event -> ('a * 'b) eventzip_e a b occurs whenever both a and b occur, and has the value of
a paired with b.
TODO: should this accept a tuple instead of two arguments?
val unzip_e : ('a * 'b) event -> 'a event * 'b eventunzip_e e produces two events synchronous with e whose values are the
first and second halves of the value of e.val merge_e : 'a event list -> 'a eventmerge_e l occurs when any event in l occurs, with the value of that
event. If more than one event occurs at the same time, the leftmost
event takes precedence.
TODO: should this also accept a function used to resolve collisions?
(we can currently acheive this with par_e and List.fold_left)
val par_e : 'a event list -> 'a list eventpar_e l occurs when at least one event in l occurs, with the value of
all occuring events joined in a list. List order is preserved.val once_e : 'a event -> 'a eventonce_e e passes only the first occurrence of e.val snapshot_e : 'a event -> 'b event -> 'a option eventsnapshot_e e trigger occurs whenever event trigger occurs. If event
e occurs simultaneously, its value is used, otherwise the event occurs
with the value None.val accum_e : 'a -> ('a -> 'a) event -> 'a eventaccum_e i e creates a event with memory which occurs whenever its
internal state changes. e is an event which carries a function which
is used to update the internal state each time it occurs. The initial
value of the state is given by i.val collect_e : ('a -> 'b -> 'a) -> 'a -> 'b event -> 'a eventcollect_e f i e is similar to accum_e but passes the value of the
event e to the function f in order to update the internal state.val changes : 'a behavior -> 'a eventchanges b occurs whenever b changes, and has the new value of b.
Equality is determined with ( =* ).val changesq : 'a behavior -> 'a eventchangesq b is similar to changes b but detects changes using
physical equality.val delta : ('a -> 'a -> 'b) -> 'a behavior -> 'b eventdelta f b is similar to changesq b but the value of the event it
creates is determined by applying f to the old and new values,
respectively, of b. For example, delta first b emits the value b
had just before it changed.val when_e : bool behavior -> unit eventwhen_e b occurs whenever b becomes true.
TODO: should this be renamed when?
val edge_e : 'a option behavior -> 'a eventedge_e b occurs whenever b transitions from None to Some v, and
has the value v.
TODO: should this be renamed edge?
val switch_e : 'a event -> 'a event event -> 'a eventswitch_e i e is an event isomorphic to the last occurrence of e (or
i, if e has not yet occurred).val map_wait_e : ('a -> 'b event) -> 'a event -> 'b eventmap_wait_e f e is a convenience function similar to map in that it
creates an event by applying the function f to the event e whenever
e occurs. However, it does not occur until the event returned by f
first occurs. It is identical to the Fr_mt expression async_map_e (fun
v -> wait (f v)) e but does not require threading to be enabled.val collapse_e : 'a event behavior -> 'a eventcollapse_e b is an event isomorphic to the current value of b.val fix_e : ('a -> 'b event) -> ('b event -> 'a) -> 'afix_e g f allows f to reference an event before it is defined: the
result of applying f to this "phantom" event is passed to g, whose
output is used to "fill in" the phantom event. fix_e returns the
output of f.
TODO: this should have some syntactic sugar associated with it
type -'a cell
val new_cell : 'a -> 'a cell * 'a behaviorval set_cell : 'a cell -> 'a -> unitval snapshot_b : 'a behavior -> 'b event -> 'a eventsnapshot b e is an event which occurs with the value of b when
the event e occurs.val latch : 'a behavior -> 'b event -> 'a eventlatch b e is similar to snapshot b e but carries the value b
had just before e occured.val hold : 'a -> 'a event -> 'a behaviorhold i e is a behavior equal to the last occurrence of e (or i, if
e has not yet occurred).val gate_b : 'a behavior -> 'b event -> 'a behaviorgate b e is a behavior which follows b, but changes only when
the event e occurs.val track : 'a -> 'a option behavior -> 'a behaviortrack i b is a behavior which follows b whenever it is not None.val zip_b : 'a behavior -> 'b behavior -> ('a * 'b) behaviorzip_b a b is a behavior with the value of a paired with b.val unzip_b : ('a * 'b) behavior -> 'a behavior * 'b behaviorunzip_b b produces two behaviors whose values are the first and
second halves of the value of b.val par_b : 'a behavior list -> 'a list behaviorpar_b l is a behavior whose value is a list of the values of all
behaviors in the list l. List order is preserved.val accum_b : 'a -> ('a -> 'a) event -> 'a behavioraccum_b is identical to accum_e but produces a behavior rather than
an event.val collect_b : ('a -> 'b -> 'a) -> 'a -> 'b event -> 'a behaviorcollect_b is identical to collect_e but produces a behavior rather
than an event.val switch_b : 'a behavior -> 'a behavior event -> 'a behaviorswitch_b i e is a behavior isomorphic to the last
occurrence of e (or i, if e has not yet occurred).val sswitch_b : ('a -> 'b) ->
('b -> 'a behavior) ->
'b -> ('b -> 'a behavior) event -> 'a behaviorsswitch_b g f i e is similar to switch_b but allows state to be
maintained across switches. g is a function which extracts the
current state of a behavior from its value. e is an event which
carries a function which produces a behavior when given an initial
state. f applied to i determines the initial behavior.
Note that the state of g must be fully observable from its output
value for sswitch_b to work as expected.
val collapse_b : 'a behavior behavior -> 'a behaviorcollapse_b b is a behavior isomorphic to the current value of b.val scollapse_b : ('a -> 'b) -> 'b -> ('b -> 'a behavior) behavior -> 'a behaviorscollapse_b g i e is similar to collapse_b but allows state to be
maintained across switches. g is a function which extracts the
current state of a behavior from its value. b is an event which
carries a function which produces a behavior when given an initial
state. The initial value of b applied to i determines the initial
behavior.
Note that the state of g must be fully observable from its output
value for scollapse_b to work as expected.
val fix_b : ('a -> 'b behavior) -> ('b behavior -> 'a) -> 'afix_b is identical to fix_e but works with a behavior.val lift0 : 'a -> 'a behaviorlift0 a is a behavior which is always equal to a.val lift1 : ('a -> 'b) -> 'a behavior -> 'b behaviorlift1 f returns a function which, when applied to a behavior,
returns a behavior which is always equal to f applied
to the current value of the behavior.val lift2 : ('a -> 'b -> 'c) -> 'a behavior -> 'b behavior -> 'c behaviorval lift3 : ('a -> 'b -> 'c -> 'd) ->
'a behavior -> 'b behavior -> 'c behavior -> 'd behaviorval lift1q : ('a -> 'b) -> 'a behavior -> 'b behaviorval lift2q : ('a -> 'b -> 'c) -> 'a behavior -> 'b behavior -> 'c behaviorval lift3q : ('a -> 'b -> 'c -> 'd) ->
'a behavior -> 'b behavior -> 'c behavior -> 'd behaviortype endpoint
val register_e : 'a event -> endpointregister_e e marks the event e as an endpoint.
register_b b marks the behavior b as an endpoint.
val register_b : 'a behavior -> endpointunregister h destroys the endpoint h. It is guaranteed not to be
evaluated again.val unregister : endpoint -> unitval event_source : ('a event_receiver -> 'b) -> ('b -> unit) -> 'a eventevent_source start stop creates an event. When the event becomes
referenced in a signal path, the function start is called with the
event's receiver as an argument. start is expected to start a thread
or co-routine which uses the provided receiver to generate events.
When the event is no longer referenced in any signal path, the stop
function is called with the value returned by start as an argument.
stop may then terminate the thread or co-routine started by start.
TODO: should event_source have a "force" function like behavior_source to
determine if an event is occurring *right now*? (i.e. for switchers)
val behavior_source : (unit -> 'a) -> ('a cell -> 'b) -> ('b -> unit) -> 'a behaviorbehavior_source force start stop creates a behavior. Like
event_source, start and stop are called when the behavior
is first referenced and last unreferenced, respectively. Additionally,
the force function is called when the behavior is first referenced.
The value it returns is used as the value of the behavior until
it is explicitly set to some value.val id : 'a -> 'aval dup : 'a -> 'a * 'aval some : 'a -> 'a optionval curry2 : ('a * 'b -> 'c) -> 'a -> 'b -> 'cval uncurry2 : ('a -> 'b -> 'c) -> 'a * 'b -> 'cval curry3 : (('a * 'b) * 'c -> 'd) -> 'a -> 'b -> 'c -> 'dval uncurry3 : ('a -> 'b -> 'c -> 'd) -> ('a * 'b) * 'c -> 'dval ($) : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'bval first : 'a -> 'b -> 'aval second : 'a -> 'b -> 'bval (=*) : 'a -> 'a -> bool(=), falling back to physical
equality with (==) if this is not possible.val (<>*) : 'a -> 'a -> bool=*.module Mixed:sig..end
type'amixed ='a Mixed.t