What are 'Latch' and 'Pulse' in reactive-banana?

179 views Asked by At

Do the Latch and Pulse types exist in FRP literature, or are they an invention of the author of reactive-banana?

Just looking at the types, they roughly correspond to Behavior and Event (respectively), but I'd like to know what the difference is, and whether their implementation is based on any formal research.

Thank you!

1

There are 1 answers

0
Heinrich Apfelmus On BEST ANSWER

Heinrich here. The Pulse and Latch types are probably best seen as "lemmas" that I came up with that are very useful for implementing the Event and Behavior type. I'm sure that they will prove useful when trying to justify the implementation more formally, but this is a formidable research project, and I have not found the time or resources to do so.

The type Pulse is almost the same as Event, except that all functions are required to have a monadic type, e.g.

mapP :: (a → b) → Pulse a → Build (Pulse b)
-- vs
mapE :: (a → b) → Event a → Event b

The Event type is implemented by getting rid of the Build monad via black magic (= observable sharing). The name Build sounds like it's a utility monad, which it is if you look at the code, but this monad is also fundamental, because it has a semantic interpretation as "moment of time", and it's not obvious why you can remove it sometimes, and sometimes not.

The type Latch is also very similar to Behavior, except that the latter also includes an Event for pragmatic reasons. Similar considerations apply concerning the Build monad.

I hope this answers more questions than it raises. Sorry that I couldn't go into more detail as for the inner workings of reactive-banana, that would be beyond the scope of a StackOverflow answer.