[Haskell-beginners] reactiva-banana : how to implement a certain type of throttling

Heinrich Apfelmus apfelmus at quantentunnel.de
Mon Jun 4 17:11:56 CEST 2012

Miguel Negrao wrote:
> Hi list,
> I would like to implement a certain type of throttling of events in
> reactive-banana. It should work such that an event is not let through
> if arrives at less then delta seconds from the last event that passed
> through. If it is not let through then it is stored and is fired after
> delta seconds from the last fired event.
> Below is a program that implements this for lists of time stamped
> numbers. Would it be possible to translate this to reactive-banana ?
> Also, in reactive-banana how do I fire an event x seconds after some
> other event comes in. The way I would do it in scala’s reactive-web is
> to start a timer that fires x seconds after it is started when an
> event comes in using dynamic event switching . It seems to me this
> would not be possible in reactive-banana because starting a timer
> is an IO operation, so I assume it can’t be done inside the
> event/behavior logic, right ?

Miguel, could you repost this question on Stackoverflow, so I can answer 
it there? This way, questions about reactive-banana are easier to find 
later on.


As for the answer, it is possible to implement the functionality you 
desire in reactive-banana, though it is a little involved.

Basically, you have use an external framework like wxHaskell to create a 
timer, which you can then use to schedule events. The Wave.hs example 
from the examples pages demonstrates how to do that.

Put differently, I have opted to not include time in the reactive-banana 
library itself. The reason is simply that different external framework 
have timers of different resolution or quality, there is no one-size 
that fits it all. I do intend to add common helper functions that deal 
with time and timers to the library itself, but I still need to find a 
good way to make it generic over different timers and figure out which 
guarantees I can provide.

Best regards,
Heinrich Apfelmus


More information about the Beginners mailing list