Difference between revisions of "Functional Reactive Programming"

From HaskellWiki
Jump to navigation Jump to search
(added link to FRP-related posts on Wolfgang Jeltsch’s blog and overhauled the sections on publictations and talks and on blog posts)
(→‎People: Added Ertugrul Söylemez.)
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
Functional Reactive Programming (FRP) integrates time flow and compositional events into functional programming. This provides an elegant way to express computation in domains such as interactive animations, robotics, computer vision, user interfaces, and simulation.
 
Functional Reactive Programming (FRP) integrates time flow and compositional events into functional programming. This provides an elegant way to express computation in domains such as interactive animations, robotics, computer vision, user interfaces, and simulation.
  +
  +
  +
== Introduction ==
  +
  +
The original formulation of Functional Reactive Programming can be found in the ICFP 97 paper [http://conal.net/papers/icfp97/ Functional Reactive Animation] by Conal Elliott and Paul Hudak.
  +
  +
=== Behaviors ===
  +
  +
Traditionally a widget-based user interface is created by a series of imperative actions. First an action is invoked to create an edit widget, then additional actions can be invoked to read its current content, set it to a specific value or to assign an event callback for when the content changes. This is tedious and error-prone.
  +
  +
A better way to represent an edit widget's content is a time-varying value, called a ''behavior''. The basic idea is that a time-varying value can be represented as a function of time:
  +
  +
<haskell>
  +
newtype Behavior a =
  +
Behavior {
  +
at :: Time -> a
  +
}
  +
  +
myName :: Behavior Text
  +
  +
myName `at` yesterday
  +
</haskell>
  +
  +
This is only a theoretical model, because a time-varying value can represent something impure like the content of an edit widget, the current value of a database entry as well as the system clock's current time. Using this model the current content of an edit widget would be a regular first class value:
  +
  +
<haskell>
  +
myEditWidget :: Behavior Text
  +
</haskell>
  +
  +
In most frameworks there is an applicative interface for behaviors, such that you can combine them easily:
  +
  +
<haskell>
  +
liftA2 (<>) myEdit1 myEdit2
  +
</haskell>
  +
  +
The result is a time-varying value that represents the concatenation of <hask>myEdit1</hask> and <hask>myEdit2</hask>. This could be the value of a third widget, a label, to display the concatenation. The following is a hypothetical example:
  +
  +
<haskell>
  +
do edit1 <- editWidget
  +
edit2 <- editWidget
  +
label <- label (liftA2 (<>) edit1 edit2)
  +
{- ... -}
  +
</haskell>
  +
  +
Without behaviors you would have to write event callback ''actions'' for the edit widgets to ''update'' the label's content. With behaviors you can express this relationship declaratively.
  +
  +
=== Events ===
  +
  +
''To do''
   
 
== Libraries ==
 
== Libraries ==
Line 12: Line 61:
 
* [[Netwire]]
 
* [[Netwire]]
 
* [http://conal.net/fran/ Fran] (discontinued)
 
* [http://conal.net/fran/ Fran] (discontinued)
 
 
* [http://hackage.haskell.org/packages/archive/pkg-list.html#cat:frp Hackage packages in the category FRP]
 
* [http://hackage.haskell.org/packages/archive/pkg-list.html#cat:frp Hackage packages in the category FRP]
  +
   
 
== Publications and talks ==
 
== Publications and talks ==
Line 19: Line 68:
 
* [http://conal.net/papers/frp.html Conal Elliott’s FRP-related publications]
 
* [http://conal.net/papers/frp.html Conal Elliott’s FRP-related publications]
 
* [https://grapefruit-project.org/publications-and-talks Grapefruit-related publications and talks]
 
* [https://grapefruit-project.org/publications-and-talks Grapefruit-related publications and talks]
* [http://haskell.cs.yale.edu/?page_id=65#FunctionalReactiveProgramming The Yale Haskell group’s FRP-related publications]
+
* [http://haskell.cs.yale.edu/?page_id=65#FunctionalReactiveProgramming The Yale Haskell Group’s FRP-related publications]
  +
   
 
== Blog posts ==
 
== Blog posts ==
Line 27: Line 77:
 
* [http://lukepalmer.wordpress.com/2008/11/28/relative-time-frp/ Relative time FRP] by Luke Palmer
 
* [http://lukepalmer.wordpress.com/2008/11/28/relative-time-frp/ Relative time FRP] by Luke Palmer
 
* [http://blog.edwardamsden.com/2011/03/demonstrating-time-leak-in-arrowized.html Demonstrating a Time Leak in Arrowized FRP] by Edward Amsden
 
* [http://blog.edwardamsden.com/2011/03/demonstrating-time-leak-in-arrowized.html Demonstrating a Time Leak in Arrowized FRP] by Edward Amsden
  +
   
 
== People ==
 
== People ==
Line 39: Line 90:
 
* [http://www.cs.nott.ac.uk/~nhn/ Henrik Nilsson]
 
* [http://www.cs.nott.ac.uk/~nhn/ Henrik Nilsson]
 
* [http://mcis.western.edu/~jpeterson/ John Peterson]
 
* [http://mcis.western.edu/~jpeterson/ John Peterson]
  +
* Ertugrul Söylemez
   
 
[[Category:FRP|*]]
 
[[Category:FRP|*]]

Revision as of 22:54, 12 November 2013

Functional Reactive Programming (FRP) integrates time flow and compositional events into functional programming. This provides an elegant way to express computation in domains such as interactive animations, robotics, computer vision, user interfaces, and simulation.


Introduction

The original formulation of Functional Reactive Programming can be found in the ICFP 97 paper Functional Reactive Animation by Conal Elliott and Paul Hudak.

Behaviors

Traditionally a widget-based user interface is created by a series of imperative actions. First an action is invoked to create an edit widget, then additional actions can be invoked to read its current content, set it to a specific value or to assign an event callback for when the content changes. This is tedious and error-prone.

A better way to represent an edit widget's content is a time-varying value, called a behavior. The basic idea is that a time-varying value can be represented as a function of time:

newtype Behavior a =
    Behavior {
      at :: Time -> a
    }

myName :: Behavior Text

myName `at` yesterday

This is only a theoretical model, because a time-varying value can represent something impure like the content of an edit widget, the current value of a database entry as well as the system clock's current time. Using this model the current content of an edit widget would be a regular first class value:

myEditWidget :: Behavior Text

In most frameworks there is an applicative interface for behaviors, such that you can combine them easily:

liftA2 (<>) myEdit1 myEdit2

The result is a time-varying value that represents the concatenation of myEdit1 and myEdit2. This could be the value of a third widget, a label, to display the concatenation. The following is a hypothetical example:

do edit1 <- editWidget
   edit2 <- editWidget
   label <- label (liftA2 (<>) edit1 edit2)
   {- ... -}

Without behaviors you would have to write event callback actions for the edit widgets to update the label's content. With behaviors you can express this relationship declaratively.

Events

To do

Libraries


Publications and talks


Blog posts


People