Functional reactive programming (FRP) is a declarative programming paradigm
where the basic notions are continuous, time-varying behaviors and discret
e, event-based reactivity. FRP has been used successfully in many reactive
programming domains such as animation, robotics, and graphical user interfa
ces. The success of FRP in these domains encourages us to consider its use
in real-time applications, where it is crucial that the cost of running a p
rogram be bounded and known before run-time. But previous work on the seman
tics and implementation of FRP was not explicitly concerned about the issue
s of cost. In fact, the resource consumption of FRP programs in the current
implementation is often hard to predict.
As a first step towards addressing these concerns, this paper presents Real
-Time FRP (RT-FRP), a statically-typed language where the time and space co
st of each execution step for a given program is statically bounded. To tak
e advantage of existing work on languages with bounded resources, we split
RT-FRP into two parts: a reactive part that captures the essential ingredie
nts of FRP programs, and a base language part that can be instantiated to a
ny generic programming language that has been shown to be terminating and r
esource-bounded. This allows us to focus on the issues specific to RT-FRP,
namely, two forms of recursion. After presenting the operational explanatio
n of what can go wrong due to the presence of recursion, we show how the ty
ped version of the language is terminating and resource-bounded.
Most of our FRP programs are expressible directly in RT-FRP. The rest are e
xpressible via a simple mechanism that integrates RT-FRP with the base lang
uage.