Conal Elliott's paper defines Event as
type Event a = [(T , a)] -- for non-decreasing times
This would allow more than one occurrence at a time. In my FRP library I would like to implement the function:
sample :: Reactive a -> Future () -> Future a
This would sample the reactive when the future fires. Since the reactive can have more than one value at the time the future fires how should I implement it? Always use the last, the first, or a nonempty list?
This is how the sample function should behave:
sample
(MkReactive "a"
(MkEvent
(MkFuture 2
(MkReactive "b" ...)
)
)
(MkFuture 1 ())
= MkFuture 1 "a"
In the paper Push-pull functional reactive programming (if duplode is correct), the fundamental sampling combinator switcher
is described as:
The semantics of b₀ `switcher` e chooses and samples either b₀ or the last behavior from e before a given sample time t
sample
should behave the same way to be compatible with the combinators in that paper. Since a Reactive
is an Event
with an initial value, and a Future
is a time-value pair, sample r (MkFuture t ())
should return a MkFuture t v
where v
is the last value in r
from strictly before t
, or the initial value of r
if there is no such value. There's no issue with multiple values at the same time: any values at time t
are ignored since they're not strictly before t
, and of the values before t
, "take the last one" is unambiguous.