package note
Module Note.ESource
Events.
An event is a value with discrete occurrences over time. Consult the semantics and notations of events.
Events
The type for functions sending event occurrences of type 'a. See create.
log ?now e f is Some (Logr.(create ?now (const f $ obs e))) if e is not never and None otherwise.
create () is a primitive event e and a send function. The function send is such that:
send vgenerates an occurrencevofeat the time it is called .send ~step vgenerates an occurrencevofeat the timestep. The function should not be called again beforestepis executed.
Warning. send must not be used in the definition of signals or events.
value e is the value of event e at call time. If this is None the event has no occurrence, if this is Some v, the event occurs with v.
bind e f is the event that results from applying f to the last event of e:
- [
bind e f]t=[f v]t if [e]≤t= Some v. - [
bind e f]t=nevert if [e]≤t= None.
swap es is the current event of es, [swap es]t = [[es]t]t.
map f e applies f to e's occurrences.
- [
map f e]t= Some (f v)if [e]t= Some v. - [
map f e]t= Noneotherwise.
filter p e are the occurrences of e that satisfy p.
- [
filter p e]t= Some vif [e]t= Some vandp v = true - [
filter p e]t= Noneotherwise.
filter_map fm e are e's occurrences filtered and mapped by fm.
- [
filter_map fm e]t= Some viffm[e]t= Some v - [
filter_map fm e]t= Noneotherwise.
select el is the occurrences of every event in el. If more than one event occurs simlutanously, the leftmost is taken and the other are lost:
- [
select el]t=[List.find (fun e ->[e]t<> None) el]t. - [
select el]t= Noneotherwise.
accum i e accumulates a value, starting with i, using e's functional occurrences.
- [
accum i e]t= Some (f i)if [e]t= Some fand [e]<t= None. - [
accum i e]t= Some (f acc)if [e]t= Some fand [accum i e]<t= Some acc. - [
accum i e]= Noneotherwise.
until ~limit ~next e is e's occurrences until next occurs. At that point if e occurs simultaneously the occurrence is discarded (limit is false, default) or kept (limit is true) and after this the event never occurs again.
- [
until ~limit ~next e]t=[e]t if [next]≤t= None - [
until ~limit:false ~next e]t= Noneif [next]t= Some _and [next]<t= None. - [
until ~limit:true ~next e]t=[e]t if [next]t= Some _and [next]<t= None. - [
until ~limit ~next e]t= Noneotherwise.
follow e ~on is e's occurrences whenever on is true.
- [
follow e ~on]t=[e]t if [on]t= true - [
follow e ~on]t= Noneif [on]t= false
defer s is s delayed by an infinitesimal amount of time. At creation time init is used (defaults to S.value s).
- [
defer e]t=Nonefor t = 0. - [
defer e]t=[e]t-dt otherwise.
fix ef allows to refer to the value an event had an infinitesimal amount of time before.
In fix ef, ef is called with an event e that represents the event returned by ef delayed by an infinitesimal amount of time. If e', r = ef e then r is returned by fix and e is such that :
- [
e]t=Noneif t = 0 - [
e]t=[e']t-dt otherwise
Raises. Invalid_argument if e' is directly a delayed event (i.e. an event given to a fixing function).