I have scoured the documentation of reactive-banana, and I can't find a way to specify explicit time delays. Say, for example, I would like to take an Event t a
and shift all of its occurrences 1 second into the future; or get an event that fires 1 second from now (within Moment t
); or anything like that. Are explicit delays representable in reactive-banana? If not, how do users implement, e.g., echoing input delayed by a second?
As Ben indicates, this is correct: reactive-banana is no built-in notion of time and delays.
The main reason is that it is hard to guarantee that logical time and real time agree. What happens when a mouse click happens in real time before the logical time of an event which could not yet be calculated, i.e. whose real time dallies behind its logical time?
However, it is still possible to deal with time by using external timer events. Have a look at the Wave.hs example.
I'm not an expert by any means, but I've used an older reactive-banana for a program with exactly this need (I don't have the code on hand at the moment, unfortunately).
I think that explicit delays don't fit super-naturally within the reactive-banana framework because you're always implicitly dealing with some sort of abstract time. Delaying by particular intervals requires dealing with the real world notion of time. I can see that it would be very hard to say what something like union event (delay 1.0 event)
would mean in terms of the authoritative model where type Event a = [Maybe a]
: should it be [a, b, a, b]
or [a, a, b, b]
? As I've been thinking of it, the problem is that which of those two should result is unspecified without considering operational runtime details.
But you can do it "around" the reactive-banana framework by wiring up an IO action to the event you want to delay that sleeps for a while (not in the main thread, obviously) and then fires a different event. I believe I was able to wrap all that logic up in a function I could call from the NetworkDescription
monad (this was before the Moment
monad existed) to get my new delayed event.
© 2022 - 2024 — McMap. All rights reserved.