Causality for free!: parametricity implies causality for functional reactive programs

  • Authors:
  • Alan Jeffrey

  • Affiliations:
  • Alcatel-Lucent, Naperville, IL, USA

  • Venue:
  • PLPV '13 Proceedings of the 7th workshop on Programming languages meets program verification
  • Year:
  • 2013

Quantified Score

Hi-index 0.00

Visualization

Abstract

Functional Reactive Programming (FRP) is a model of reactive systems in which signals are time-dependent values, and signal functions are functions between signals. Signal functions are required to be causal, in that output behaviour at time t is only allowed to depend on input behaviour up to time t. In order to enforce causality, many FRP libraries are arrowized, in that they provide combinators for building signal functions, rather than allowing users to write functions directly. In this paper, we provide a definition of deep causality (which coincides with the usual definition on signals of base type, but differs on nested signals). We show that FRP types can be interpreted in System Fomega extended with a kind of time, and show that in this interpretation, a "theorems for free" argument shows that parametric functions are deep causal. Since all System Fomega functions are parametric, this implies that all implementable functions are deep causal. This model is the formal basis of the agda-frp-js FRP library for the dependently typed programming language Agda, which compiles to JavaScript and executes in the browser. Assuming parametricity of Agda, this allows reactive programs to be written as regular functions over signals, without sacrificing causality. All results in this paper have been mechanically verified in Agda.