Functional reactive programming

Last updated

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, games, and music, aiming to simplify these problems by explicitly modeling time.[ citation needed ]

Contents

Formulations of FRP

The original formulation of functional reactive programming can be found in the ICFP 97 paper Functional Reactive Animation by Conal Elliott and Paul Hudak. [1]

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. [2]

Continuous

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. [3] 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. [4] This formulation is also referred to as denotative continuous time programming (DCTP). [5]

Discrete

Formulations such as Event-Driven FRP and versions of Elm prior to 0.17 require that updates are discrete and event-driven. [6] 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. [7]

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. [8]

Interactive FRP

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

planNow::Event(IOa)->IO(Eventa)

Implementation issues

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, where samples are pulled by the signal network. This approach has a drawback: the network must wait up to the duration of one computation step to learn of changes to the input. Sampling is an example of pull-based FRP.

The Reactive and Etage libraries on Hackage introduced an approach called push-pull FRP. In it, only when the next event on a purely defined stream (such as a list of fixed events with times) is demanded, that event is constructed. These purely defined streams act like lazy lists in Haskell. That is the pull-based half. The push-based half is used when events external to the system are brought in. The external events are pushed to consumers, so that they can find out about an event the instant it is issued.

Implementations

Implementations exist for many programming languages, including:

ReactiveX, popularized by its JavaScript implementation rxjs, is functional and reactive but differs from functional reactive programming. [18]

See also

Related Research Articles

In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map values to other values, rather than a sequence of imperative statements which update the running state of the program.

<span class="mw-page-title-main">Foreign relations of Nicaragua</span>

Nicaragua pursues an independent foreign policy. A participant of the Central American Security Commission, Nicaragua also has taken a leading role in pressing for regional demilitarization and peaceful settlement of disputes within states in the region.

<span class="mw-page-title-main">Purdue University</span> Public university in West Lafayette, Indiana, US

Purdue University is a public land-grant research university in West Lafayette, Indiana, and the flagship campus of the Purdue University system. The university was founded in 1869 after Lafayette businessman John Purdue donated land and money to establish a college of science, technology, and agriculture; the first classes were held on September 16, 1874.

Pascal is an imperative and procedural programming language, designed by Niklaus Wirth as a small, efficient language intended to encourage good programming practices using structured programming and data structuring. It is named after French mathematician, philosopher and physicist Blaise Pascal.

<span class="mw-page-title-main">Perl</span> Interpreted programming language first released in 1987

Perl is a high-level, general-purpose, interpreted, dynamic programming language. Though Perl is not officially an acronym, there are various backronyms in use, including "Practical Extraction and Reporting Language".

<span class="mw-page-title-main">Porsche</span> German automobile manufacturer

Dr. Ing. h.c. F. Porsche AG, usually shortened to Porsche, is a German automobile manufacturer specializing in luxury, high-performance sports cars, SUVs and sedans, headquartered in Stuttgart, Baden-Württemberg, Germany. The company is owned by Volkswagen AG, a controlling stake of which is owned by Porsche Automobil Holding SE. Porsche's current lineup includes the 718, 911, Panamera, Macan, Cayenne and Taycan.

<span class="mw-page-title-main">R2-D2</span> Fictional character from Star Wars

R2-D2 or Artoo-Detoo is a fictional robot character in the Star Wars franchise created by George Lucas. He has appeared in ten of the eleven theatrical Star Wars films to date, including every movie in the original trilogy, prequel trilogy, and sequel trilogy. At various points throughout the course of the films, R2, an astromech droid, is a friend to C-3PO, Padmé Amidala, Anakin Skywalker, Leia Organa, Luke Skywalker, and Obi-Wan Kenobi. R2-D2 and his companion C-3PO are the only characters to appear in every theatrical Star Wars film, with the exception of Solo: A Star Wars Story (2018).

Programming languages can be grouped by the number and types of paradigms supported.

In computer programming, especially functional programming and type theory, an algebraic data type (ADT) is a kind of composite type, i.e., a type formed by combining other types.

The Glasgow Haskell Compiler (GHC) is a native or machine code compiler for the functional programming language Haskell. It provides a cross-platform software environment for writing and testing Haskell code and supports many extensions, libraries, and optimisations that streamline the process of generating and executing code. GHC is the most commonly used Haskell compiler. It is free and open-source software released under a BSD license. The lead developers are Simon Peyton Jones and Simon Marlow.

SIGPLAN is the Association for Computing Machinery's Special Interest Group on programming languages.

In computer science, arrows or bolts are a type class used in programming to describe computations in a pure and declarative fashion. First proposed by computer scientist John Hughes as a generalization of monads, arrows provide a referentially transparent way of expressing relationships between logical steps in a computation. Unlike monads, arrows don't limit steps to having one and only one input. As a result, they have found use in functional reactive programming, point-free programming, and parsers among other applications.

wxHaskell is a portable and native graphical user interface (GUI) library for the programming language Haskell, built on wxWidgets. It is often used by those wanting to develop a GUI with a functional programming language.

QuickCheck is a software library, specifically a combinator library, originally written in the programming language Haskell, designed to assist in software testing by generating test cases for test suites – an approach known as property testing.

In computing, reactive programming is a declarative programming paradigm concerned with data streams and the propagation of change. With this paradigm, it is possible to express static or dynamic data streams with ease, and also communicate that an inferred dependency within the associated execution model exists, which facilitates the automatic propagation of the changed data flow.

<span class="mw-page-title-main">Incremental computing</span> Software feature

Incremental computing, also known as incremental computation, is a software feature which, whenever a piece of data changes, attempts to save time by only recomputing those outputs which depend on the changed data. When incremental computing is successful, it can be significantly faster than computing new outputs naively. For example, a spreadsheet software package might use incremental computation in its recalculation features, to update only those cells containing formulas which depend on the changed cells.

Haskell is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research, and industrial applications, Haskell has pioneered a number of programming language features such as type classes, which enable type-safe operator overloading, and monadic input/output (IO). It is named after logician Haskell Curry. Haskell's main implementation is the Glasgow Haskell Compiler (GHC).

Conor McBride is a Reader in the department of Computer and Information Sciences at the University of Strathclyde. In 1999, he completed a Doctor of Philosophy (Ph.D.) in Dependently Typed Functional Programs and their Proofs at the University of Edinburgh for his work in type theory. He formerly worked at Durham University and briefly at Royal Holloway, University of London before joining the academic staff at the University of Strathclyde.

<span class="mw-page-title-main">Elm (programming language)</span> Functional programming language

Elm is a domain-specific programming language for declaratively creating web browser-based graphical user interfaces. Elm is purely functional, and is developed with emphasis on usability, performance, and robustness. It advertises "no runtime exceptions in practice", made possible by the Elm compiler's static type checking.

<span class="mw-page-title-main">ReactiveX</span> Program library

ReactiveX is a software library originally created by Microsoft that allows imperative programming languages to operate on sequences of data regardless of whether the data is synchronous or asynchronous. It provides a set of sequence operators that operate on each item in the sequence. It is an implementation of reactive programming and provides a blueprint for the tools to be implemented in multiple programming languages.

References

  1. Elliott, Conal; Hudak, Paul. "Functional Reactive Animation". Functional Reactive Animation. ICFP ’97. Retrieved 14 July 2018.
  2. Nilsson, Henrik; Courtney, Antony; Peterson, John (Feb 2011) [2002], "Functional Reactive Programming, Continued", Haskell Workshop (PDF)
  3. Elliott, Conal; Hudak, Paul (1997), "Functional Reactive Animation", ICFP
  4. Courtney, Antony; Elliott, Conal (Feb 2011) [2001], "Genuinely Functional User Interfaces", Haskell Workshop, Yale
  5. Elliot, Conal (2014), "Denotational Design" (PDF), LambdaJam, retrieved 5 May 2023
  6. Taha, Walid; Wan, Zhanyong; Hudak, Paul (2002), "Event-Driven FRP", PADL (PDF), Yale, archived from the original (PDF) on 2013-09-28, retrieved 2013-09-23{{citation}}: More than one of |archivedate= and |archive-date= specified (help); More than one of |archiveurl= and |archive-url= specified (help)
  7. Czaplicki, Evan; Chong, Stephen (2013), "Asynchronous Functional Reactive Programming for GUIs", PLDI, Harvard
  8. Wan, Zhanyong; Taha, Walid; Hudak, Paul (Feb 2011), "Real-Time FRP", ICFP (PDF), archived from the original (PDF) on 2013-09-28, retrieved 2013-09-23{{citation}}: More than one of |archivedate= and |archive-date= specified (help); More than one of |archiveurl= and |archive-url= specified (help)
  9. Elliott, Conal (December 9, 2008). "Why classic FRP does not fit interactive behavior". Archived from the original on 2022-10-12.
  10. Borning, Alan. "I/O in Purely Functional Languages" (PDF). Archived (PDF) from the original on 2022-04-28.
  11. Carlsson, Magnus; Hallgren, Thomas (1998). "Fudgets – Purely Functional Processes with applications to Graphical User Interfaces" (PDF). Archived (PDF) from the original on 2022-10-15.
  12. Perez, Ivan; Barenz, Manuel; Nilsson, Henrik (July 2016), "Functional Reactive Programming, Refactored", Haskell Symposium (PDF)
  13. Atze van der Ploeg; Claessen, Koen. "Practical Principled FRP" (PDF). Archived from the original (PDF) on 2015-07-01. Retrieved 2015-07-24.{{cite web}}: More than one of |archivedate= and |archive-date= specified (help); More than one of |archiveurl= and |archive-url= specified (help)
  14. Czaplicki, Evan (Apr 2012), Elm: Concurrent FRP for Functional GUIs (PDF) (thesis), Harvard, archived from the original (PDF) on 2016-06-04, retrieved 2015-02-17{{citation}}: More than one of |archivedate= and |archive-date= specified (help); More than one of |archiveurl= and |archive-url= specified (help)CS1 maint: location missing publisher (link)
  15. Czaplicki, Evan. "A Farewell to FRP". elm. Retrieved 14 July 2018.
  16. Van den Vonder, Sam; Renaux, Thierry; Oeyen, Bjarno; De Koster, Joeri; De Meuter, Wolfgang (2020), "Tackling the Awkward Squad for Reactive Programming: The Actor-Reactor Model", Leibniz International Proceedings in Informatics (LIPIcs), vol. 166, pp. 19:1–19:29, doi:10.4230/LIPIcs.ECOOP.2020.19, ISBN   9783959771542, S2CID   260445152
  17. Van den Vonder, Sam; Renaux, Thierry; De Meuter, Wolfgang (2022), "Topology-Level Reactivity in Distributed Reactive Programs: Reactive Acquaintance Management using Flocks", The Art, Science, and Engineering of Programming, vol. 6, pp. 14:1–14:36, arXiv: 2202.09228 , doi: 10.22152/programming-journal.org/2022/6/14 , S2CID   246979565
  18. "ReactiveX". ReactiveX.io. Retrieved July 3, 2022.