< Back to previous page

Publication

Multi-tier Functional Reactive Programming for the Web

Book - Dissertation

Web applications are inherently distributed, and not just because their client and server counterparts run on networked systems. Web applications are written in multiple programming languages and as multiple programs: the server and client programs. In an effort to lower the complexity of the web, multi-tier programming was proposed. In multi-tier programming languages the language and its tooling give support to create web applications as a whole, one program is written in one language. Web applications are also inherently asynchronous. On the server, they constantly process several client requests and in the browser they constantly have to react to input, be it from the user or a server. A technique that can be applied to make such programs easier to understand is functional reactive programming. A functional programming model that models an interactive program as compositions between two primitives, behaviors and events. In this research, we apply and combine both techniques to web applications, making advances in both applying multi-tier programming to existing languages and to functional reactive programming. We show that the whole of multi-tier and functional reactive programming is greater than the sum of its parts with new properties as a result. Multi-tier Functional Reactive Programming Multi-tier FRP is our unification of multi-tier programming and functional reactive programming. It tackles two problems in development, (1) the inherent distributed and (2) the asynchronous nature of the web. With our design and implementation it becomes possible to write an entire web application (both client and server) in a single language as a composition between events and behaviors. Communication between client and server tier is done through tier-crossing primitives, a low-cost abstraction with atomic propagation. They are checked at the language level and make sure client and server are compatible. We present Gavial, a usable and realistic implementation of multi-tier FRP in Scala as a library that builds on several other techniques to become viable, several of which we describe throughout this dissertation: FRP DOM APIs are key to making a usable FRP web framework. However, subtle design decisions have a big impact and certain issues do not necessarily have an ideal solution. What should be the entry point of the program? How do we deal with recursive definitions in HTML? The user interface is expressed in terms of itself, for example, a todo-list adds rows depending on the interaction with itself. How do we interface with the DOM? The DOM is both a producer of events and a storage of state. We look at these questions and implement a pragmatic FRP DOM API that is used in Gavial. Scalagna is our multi-tier-as-a-library project for Scala. There are several potential problems with multi-tier language development. Certain languages start from scratch and have a hard time covering all library use cases of mature language ecosystems, others start from an existing language but have a high implementation cost on client compilation, etc. We present Scalagna, a first step towards multi-tier programming for Scala. It takes advantage of Scala.JS, a mature Scala to JavaScript compiler with its own ecosystem of libraries. Incremental behaviors are an additional FRP primitive. State that is incrementally modified is common in web applications, a user that interacts with a program constantly changes its state with each form of input. In an FRP setting these states are modeled using behaviors, but traditional FRP exposes no information on why or when these behaviors change. This information becomes crucial in a multi-tier FRP setting, where incremental data structures can become large (e.g., through multiple user interaction). Such large data structures are required to be processed efficiently, possibly in terms of computation but definitely in terms of bandwidth. To make this information available in multi-tier FRP, we present incremental behaviors. A behavior that describes why and when it changes its value so that they can be sent across the network efficiently.
Publication year:2019
Accessibility:Open