*** Welcome to piglix ***

Functional reactive programming


Functional reactive programming (FRP) is a programming paradigm for reactive programming (asynchronous dataflow programming) using the building blocks of functional programming (e.g. map, reduce, filter). FRP has been used for programming graphical user interfaces (GUIs), robotics, and music, aiming to simplify these problems by explicitly modeling time.

FRP has taken many forms since its introduction in 1997. One axis of diversity is discrete vs. continuous semantics. Another axis is how FRP systems can be changed dynamically.

Formulations such as Event-Driven FRP and Elm before version 0.17 require that updates are discrete and event-driven. These formulations have pushed for practical FRP, focusing on semantics that have a simple API that can be implemented efficiently in a setting such as robotics or in a web-browser.

In these formulations, it is common that the ideas of behaviors and events are combined into signals that always have a current value, but change discretely.

The earliest formulation of FRP used continuous semantics, aiming to abstract over many operational details that are not important to the meaning of a program. The key properties of this formulation are:

This semantic model of FRP in side-effect free languages is typically in terms of continuous functions, and typically over time.

It has been pointed out that the ordinary FRP model, from inputs to outputs, is poorly suited to interactive programs. Lacking the ability to "run" programs within a mapping from inputs to outputs may mean one of the following solutions has to be used:

There are two types of FRP systems, push-based and pull-based. Push-based systems take events and push them through a signal network to achieve a result. Pull-based systems wait until the result is demanded, and work backwards through the network to retrieve the value demanded.

Some FRP systems such as Yampa use sampling. On a regular interval, samples are pushed through a signal network. This approach has two drawbacks: it is very computation intensive to process samples on a regular interval, and the network has to wait up to the duration of the sampling interval to find out about changes to the input. Sampling is an example of push-based FRP.


...
Wikipedia

...