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.Developing web applications requires dealing with their distributed nature and the natural asynchronicity of user input and network communication. For facilitating this, different researchers have explored the combination of a multi-tier programming language and functional reactive programming. However, existing proposals take his approach only part of the way. Some parts of the application remain imperative, do not consider network traffic overhead of incremental data, compatibility with common APIs like XMLHttpRequest etc., or they do not consider glitches across network communication (or do but introduce locking or overhead)In this paper, we present Gavial: a design and practical implementation of multi-tier FRP that allows constructing a web application as a functionally reactive program. We propose a novel integration of existing techniques such as solutions to bootstrapping web applications, recursive behaviors for web interfaces, asynchronous FRP and incremental behaviors. As well as novel support for tiered glitch freedom, a compromise between performance and glitch-free evaluation of the distributed FRP program, and a three-tiered system suitable for request-response-style applications as well as user-to-user applications. Gavial automatically runs in request-response (XMLHttpRequest) mode or in websocket mode.After applying a number of old and new ideas to create a practical multi-tier FRP implementation in Gavial, we demonstrate it by building an example and show that it can in fact deal realistically with important practical aspects of building web applications. At the same time, we retain the declarative nature of FRP, where behaviors and events have an intuitive, compositional semantics and a clear dependency structure.
ACM CCS 2012Listing 2 Delayed DBehavior object DBehavior { def delayed[A](db: ⇒ DBehavior[A]): Behavior[A] }Returning to CircleRoyale, a type Player represents a player's position, and whether he is alive, attacking or dead. The svg method produces the player's circle and optionally the attacking circle as SVG elements. case class Player(position: Vec2D, attacking: ...