Reactive Banana Time Delays

I looked through the reactive-banana documentation and I cannot find a way to indicate explicit time delays. Say, for example, I would like to take Event ta and transfer all its appearances for 1 second to the future; or get an event that fires after 1 second (within Moment t ); or something like that. Are apparent delays representable in reactive bananas? If not, how do users implement, for example, an echo delayed by the second?

+8
haskell frp reactive-banana
source share
2 answers

As Ben points out, this is correct: reactive banana is not a built-in concept of time and delays.

The main reason is that it is difficult to guarantee the consistency of logical time and real time. What happens when a mouse click occurs in real time until the logical time of an event that cannot yet be calculated, i.e. Whose real time is past its logical time?

However, you can still deal with time using external timer events. Check out the Wave.hs example.

+4
source share

I am not an expert in any way, but I used an older reactive banana for a program with such a need (unfortunately, at the moment I have no code on hand).

I think that explicit delays do not correspond super-naturally within a reactive banana structure, because you are always implicitly engaged in some kind of abstract time. Delaying with the help of certain intervals requires an appeal to the real world concept of time. I see that it would be very difficult to say something like union event (delay 1.0 event) would mean, from the point of view of the authoritative model, where type Event a = [Maybe a] : should it be [a, b, a, b] or [a, a, b, b] ? As I thought about this, the problem is that of these two results are not indicated, not taking into account the details of operational work.

But you can do this โ€œaroundโ€ the banana-reactive framework by attaching an IO action to an event that you want to snooze that sleeps for a while (not in the main thread, obviously), and then fire another event. I believe that I was able to complete all this logic in a function that I could call from the NetworkDescription monad (this was before the Moment monad existed) to get my new event with a delay.

+3
source share

All Articles