Hands-On Reactive Programming with Clojure
上QQ阅读APP看书,第一时间看更新

First-order FRP

The most well-known reactive language in this category is Elm (see http://elm-lang.org/), an FRP language that compiles to JavaScript. It was created by Evan Czaplicki and presented in his paper Elm: Concurrent FRP for Functional GUIs[3].

Elm makes some significant changes to higher-order FRP.

It abandons the idea of continuous time and is entirely event-driven. As a result, it solves the problem of needless recomputation, which was highlighted earlier. First-order FRP combines both behaviors and events into signals, which, in contrast to higher-order FRP, are discrete.

Additionally, first-order FRP allows the programmer to specify when the synchronous processing of events isn't necessary, preventing unnecessary processing delays.

Finally, Elm is a strict programming language, meaning that arguments to functions are evaluated eagerly. This is a conscious decision, as it prevents space and time leaks, which are possible in a lazy language such as Haskell.

In an FRP library such as Fran, which has been implemented in a lazy language, memory usage can grow unwieldy as computations are deferred to the absolutely last possible moment, therefore causing a space leak. These larger computations, which are accumulated over time due to laziness, can then cause unexpected delays when finally executed, thus causing time leaks.