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

Miguel Negrao miguel.negrao-lists at friendlyvirus.org
Tue Jun 5 11:58:34 CEST 2012

A 04/06/2012, às 16:11, Heinrich Apfelmus escreveu:

> 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.
> http://stackoverflow.com/questions/ask?tags=reactive-programming+haskell+frp

I’ve reposted the question here: http://stackoverflow.com/questions/10888826/reactive-banana-throttling-events

> 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.

Ok, looking at Wave.hs I can see what I need to do to be able to delay an event by a certain amount of seconds. The scheduleQueue function there doesn’t exactly do what I need it to do, because it schedules relative to the last scheduled event. Essentially I would need to alter it such that the scheduling is done in absolute terms, so If I ask something to happen 5 seconds from now it should really happen 5 seconds from now instead of 5 seconds from the last event in queue. One way to do it would be to keep the scheduled times in UTC or some other time format and every time an event comes into the queue stop the timer, sort the event queue by the absolute times, check how long is it till the next event and set the timer delay to be that amount of time, then keep repeating the procedure. It would indeed be nice to have something like this already available in reactive-banana-wx, or in some timer type independent way in the library itself.

Two practical question:
1) How do I filter the slider events (from event0 mySlider command) to get only one event instead of 3 every time I move the slider ?
2) What is the best way to set some wx property based on the current value of some behavior but only when some event happens ? I’m doing like this now:
reactimate $ apply ((\x->(\y->set slider2 [selection := x])) <$> slider1SelectionBehavior) slider1Event


More information about the Beginners mailing list