Hostname: page-component-89b8bd64d-b5k59 Total loading time: 0 Render date: 2026-05-12T09:10:24.040Z Has data issue: false hasContentIssue false

Modal FRP for all: Functional reactive programming without space leaks in Haskell

Published online by Cambridge University Press:  26 December 2022

PATRICK BAHR*
Affiliation:
Computer Science Department, IT University of Copenhagen, Copenhagen, Denmark (e-mail: paba@itu.dk)
Rights & Permissions [Opens in a new window]

Abstract

Functional reactive programming (FRP) provides a high-level interface for implementing reactive systems in a declarative manner. However, this high-level interface has to be carefully reigned in to ensure that programs can in fact be executed in practice. Specifically, one must ensure that FRP programs are causal and can be implemented without introducing space leaks. In recent years, modal types have been demonstrated to be an effective tool to ensure these operational properties. In this paper, we present $\mathsf{Rattus}$, a modal FRP language that extends and simplifies previous modal FRP calculi while still maintaining the operational guarantees for productivity, causality, and space leaks. The simplified type system makes $\mathsf{Rattus}$ a practical programming language that can be integrated with existing functional programming languages. To demonstrate this, we have implemented a shallow embedding of $\mathsf{Rattus}$ in Haskell that allows the programmer to write $\mathsf{Rattus}$ code in familiar Haskell syntax and seamlessly integrate it with regular Haskell code. Thus, $\mathsf{Rattus}$ combines the benefits enjoyed by FRP libraries such as Yampa, namely access to a rich library ecosystem (e.g., for graphics programming), with the strong operational guarantees offered by a bespoke type system. To establish the productivity, causality, and memory properties of the language, we prove type soundness using a logical relations argument fully mechanised in the Coq proof assistant.

Information

Type
Research Article
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (https://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution and reproduction, provided the original article is properly cited.
Copyright
© The Author(s), 2022. Published by Cambridge University Press
Figure 0

Fig. 1. Small library for streams and events.

Figure 1

Fig. 2. Arrow type class.

Figure 2

Fig. 3. Syntax of (stable) types, terms, and values. In typing rules, only closed types are considered (i.e., each occurrence of a type variable $\alpha$ is in the scope of a $\mathsf{Fix}\,\alpha$).

Figure 3

Fig. 4. Well-formed contexts.

Figure 4

Fig. 5. Typing rules.

Figure 5

Fig. 6. Evaluation semantics.

Figure 6

Fig. 7. Step semantics for streams.

Figure 7

Fig. 8. Selected typing rules from Bahr et al. (2019).

Figure 8

Fig. 9. Logical relation.

Figure 9

Fig. 10. Implementation of $\mathsf{Rattus}$ primitives.

Figure 10

Fig. 11. Compiler phases of GHC (simplified) extended with $\mathsf{Rattus}$ plugin (highlighted in bold).

Figure 11

Fig. 12. Complete $\mathsf{Rattus}$ program.

Figure 12

Fig. 13. Well-formed contexts of $\lambda_{\checkmark}$.

Figure 13

Fig. 14. Typing rules of $\lambda_{\checkmark}$.

Supplementary material: File

Bahr supplementary material

Bahr supplementary material 1

Download Bahr supplementary material(File)
File 45.5 KB
Supplementary material: File

Bahr supplementary material

Bahr supplementary material 2

Download Bahr supplementary material(File)
File 430.9 KB
Submit a response

Discussions

No Discussions have been published for this article.