Reputation: 588
I am still trying to wrap my head around Haskell and FRP. Specifically, I have worked through some examples using reactive-banana package and starting to get FRP.
However, I still don't understand how the event network knows when an input event has occurred. My understanding is that, unlike NodeJS which has an event loop constantly checking for user inputs, FRP utilizes a different framework for "waiting" or "checking" user inputs or external signals.
From my reading, FRP makes time explicit. By coupling time with either an event or behavior, somehow the network always knows when an external stimulus has fired.
I have read many papers by Conal, Hudak, et al. and the explanations are too technical. Please provide less technical explanation.
Thanks for your help.
Upvotes: 2
Views: 440
Reputation: 11064
It is useful to keep in mind the distinction between FRP, which is concerned with building interesting Event
s and Behavior
s from basic ones, and platform specific "glue code", which provides a collection of basic Event
s, like the current mouse position or keyboard presses.
In the Reactive-Banana library, this distinction is reflected in the module structure, Reactive.Banana.Combinators
is concerned with the first part, while Reactive.Banana.Frameworks
is concerned with the second part.
Now, understanding how the second part (basic Events
) works is not important for understanding how the first part (FRP) works; in fact, different libraries may make very different implementation choices.
That said, in the Reactive-Banana library, an event network is essentially a huge callback function that registers itself to external event sources (called AddHandler
in the library). Whenever one of these external sources call the callback function, the latter will traverse the graph of Event
and Behavior
in dependency order, perform the necessary updates to internal state, and finally run the actions previously registered with reactimate
.
The magic of FRP is that the library user doesn't see any of these implementation details, though it is sometimes useful to know that "event network = a huge callback function".
Upvotes: 3