Event-Driven FRP
📜 Abstract
Functional Reactive Programming (FRP) is a high-level declarative language for programming reactive systems. Previous work on FRP has demonstrated its utility in applications ranging from animation and graphical user interfaces to robotics. FRP has a continuous-time denotational semantics that is elegant and expressive. But FRP provides no guarantees on resource consumption, and so is unsuitable for more demanding applications. Recently we identified a resource bounded sub-language of FRP called Real-Time FRP (RT-FRP). Experience using RT-FRP in the micro-controller domain has revealed a shortcoming of RT-FRP in the event-driven setting. To deal with this shortcoming, we present a more general language called Event-driven FRP (E-FRP). The new language allows us to express heavily event-oriented computations in a natural manner. The focus of this paper is on compilation, which had not been addressed with RT-FRP. We formally define a compilation strategy for E-FRP into imperative code. By giving a formal operational semantics to a small imperative language, we also show that compilation is correct. We are currently building a compiler from RT-FRP which includes a back-end for generating code for the PIC16C66 micro-controller.
✨ Summary
Contribution
The paper introduces Event-Driven Functional Reactive Programming (E-FRP), a resource-bounded subset of Functional Reactive Programming designed for systems driven by multiple external events. It generalizes Real-Time FRP by replacing its single implicit global clock with multiple mutually exclusive event sources. Behaviors change only when events occur, and event processing is divided into computation and state-update phases. These restrictions provide a simpler operational model and support predictable execution for interrupt-driven embedded systems.
The central technical contribution is a formally specified compilation strategy from E-FRP into a small imperative language. The authors give operational semantics for the target language and establish that the compilation preserves the behavior of the source program. The paper also presents a robot-controller example targeting a PIC16C66 microcontroller. The formally specified generated code is intentionally conservative; the paper notes that practical implementations can apply global optimizations to produce more efficient code. (researchgate.net)
Influence
The work directly led to subsequent research on E-FRP with priorities, which extended the compilation strategy to support prioritized and preemptive event handling while preserving the original high-level semantics and resource guarantees. (websrv.cecs.uci.edu)
E-FRP was also incorporated into later analyses of reactive programming as an example of a discrete, event-driven FRP model with explicit update ordering and glitch-avoidance properties. The model was cited in research on asynchronous FRP and Elm, and in surveys that classified reactive systems according to their treatment of time, events, evaluation, and dependency propagation. (doi.org)
More recently, Reactive Vega used E-FRP semantics as a basis for declarative interactive visualization, retaining event-driven propagation and two-phase updates while combining them with streaming-data and incremental-recomputation techniques. This demonstrates an extension of the paper’s event-driven dataflow ideas beyond embedded controllers into interactive web visualization systems. (citeseerx.ist.psu.edu)