[Haskell-beginners] reactiva-banana : how to implement a certain type of throttling
apfelmus at quantentunnel.de
Thu Jun 7 15:52:07 CEST 2012
Miguel Negrao wrote:
> A 04/06/2012, às 16:11, Heinrich Apfelmus escreveu:
>> Miguel, could you repost this question on Stackoverflow, so I can answer it there?
> I’ve reposted the question here: [..]
> 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.
The wxTimers use relative time, so you would have to convert between the
two, indeed. It's probably not straightforward, but likely an
> 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.
Henning Thielemann has written some time-related combinators in his
You can probably get some inspiration from there.
> 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 ?
If they are simultaneous, then you can use collect . Otherwise, you
will have to read the wxHaskell and wxWidgets documentation to figure
out how to get rid of the superfluous events.
> 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
Looks good to me. You can use the <@ combinator to make it a little
(\x -> set slider2 [ selection := x ]) <$> slider1SelectionBehavior
More information about the Beginners