Date of Original Version

7-25-2015

Type

Working Paper

Abstract or Description

Interactive applications must operate correctly and efficiently while reacting to events in an unpredictable external world. Currently, most such programs are written in an event-driven style that can often be difficult to understand and maintain because callbacks defeat modularity and often share global state. Elliott and Hudak proposed Functional Reactive Programmng (FRP), which tames this complexity by representing interactive values as functions of time. Although FRP has an elegant denotational semantics, its realizations limit the sampling of external events and signals to avoid time and space leaks.

In this paper, we propose an approach to reactive programming that avoids memoization, the cause of many space leaks, but provides a flexible programming interface. We propose a single language abstraction, called a factor, for sampling interactive values. The absence of state ensures that space leaks are impossible, but raises the question of what it would mean to query the same factor twice. Such queries are ruled out using an affine type system that ensures that each factor may be queried at most once, providing both an output and another factor admitting further interaction.

The dynamics of the language is specified in terms of Brouwer’s concept of free choice sequences, which model the unpredictability of the external world with which a program interacts. An affine notion of logical relations, derived from Ahmed, Fluet, and Morrisett’s account of state, supports the derivation of equations characterizing the behavior of interactive programs under the assumption of an unpredictable world. The practicality of factors as a programming device is illustrated through the use of a factor library written in OCaml to build a number of applications, including a multiplayer game and a Unix-like shell.

Share

COinS