Why are there no functions for creating events from non-events in a reactive banana?

I am involved in teaching FRP and Reactive-banana, writing what I hope will become a more useful tutorial for those who follow me. You can check my progress in the tutorial here .

I am stuck trying to implement simple sound examples using events. I know that I need to do something like this:

reactimate $ fmap (uncurry playNote) myEvent 

in my NetworkDescription , but I can’t understand how simple the network is to repeat the same thing, or to do something once. Ideally, I am looking for things like this:

 once :: a -> Event ta repeatWithDelay :: Event ta -> Time -> Event ta concatWithDelay :: Event ta -> Event ta -> Time -> Event ta 

The Time type above is just a means of waiting for any measurement of time that we ultimately use. Do I need to connect the system time as a behavior in order to control the "delay" functions? This seems more complicated than necessary.

Thanks in advance,

Echo nolan

EDIT: Well, the types for repeatWithDelay and concatWithDelay do not make sense. This is what I really had in mind.

 repeatWithDelay :: a -> Time -> Event ta concatWithDelay :: a -> a -> Time -> Event ta 
+7
source share
1 answer

I decided not to include such functions in the base model at the moment, because time creates various problems for consistency. For example, if two events are scheduled in 5 seconds, should they be simultaneous? If not, which one should be the first? I think the basic model should lend itself to formal proof, but this does not work with actual physical measurements of time.

However, I plan to include such features in the “they work, but do not guarantee” mods. The main reason I have not done this yet is that there is no canonical choice for measuring time. Different applications have different needs, sometimes you need nanosecond resolution, sometimes you want to use timers from your GUI infrastructure, and sometimes you want to synchronize with an external MIDI clock. In other words, you want the time-based function to work in general with many timer implementations, and only with reactive banana-0.7.0 I found a good API design for this.

Of course, you can already implement your own temporary function using timers. The Wave.hs example demonstrates how to do this. Another example is the Henning Thielemann reactive balsa library , which implements various time combinators for real-time processing of MIDI data.

+4
source

All Articles