Personal tools

Functional Reactive Programming

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(Material: Conal's blog)
(Introduction: Netwire 4 is now on HackageDB.)
(13 intermediate revisions by 7 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 ==
  +
  +
FRP is about domain-specific languages that capture the notion of
  +
time-varying values. Let's take Netwire 4 as an example. You can install it either from HackageDB,
  +
  +
cabal install netwire
  +
  +
or by grabbing the latest source code via darcs:
  +
  +
darcs get http://darcs.ertes.de/netwire/
  +
cd netwire
  +
cabal install
  +
  +
Imagine you have a simple GUI label that displays the number of seconds
  +
passed since program start. In an event-based model this is actually
  +
quite a complicated task. You would have to create a label and update
  +
it all the time using some form of timer/idle event. In Netwire you
  +
write:
  +
  +
myLabel = time
  +
  +
Now let's say you want to have the same GUI, but the time should start
  +
at 10 and pass twice as fast, so you actually want to display twice the
  +
number of seconds passed plus 10:
  +
  +
myLabel = 10 + 2*time
  +
  +
Imagine you want to display the string "yes" in a label:
  +
  +
myLabel = "yes"
  +
  +
Now let's say you want to display "yes", when the space key is held down
  +
and "no" otherwise:
  +
  +
myLabel = "yes" . keyDown Space <|> "no"
  +
  +
You want to display time while pressed and "Press space" while not:
  +
  +
myLabel = fmap show time . keyDown Space <|> "Press space"
  +
  +
You want to display "yes" every other second and "no" otherwise:
  +
  +
myLabel = "yes" . holdFor 1 (periodically 2) <|> "no"
  +
  +
Imagine doing that with event-based code.
  +
  +
Summary: FRP is about handling time-varying values like they were
  +
regular values.
   
 
== Libraries ==
 
== Libraries ==
* [http://conal.net/fran/ Fran]
+
* [http://hackage.haskell.org/package/sodium Sodium]
 
* [[Grapefruit]]
 
* [[Grapefruit]]
 
* [[Reactive]]
 
* [[Reactive]]
Line 10: Line 60:
 
* [http://hackage.haskell.org/package/elerea Elerea]
 
* [http://hackage.haskell.org/package/elerea Elerea]
 
* [[Reactive-banana|reactive-banana]]
 
* [[Reactive-banana|reactive-banana]]
+
* [[Netwire]]
  +
* [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]
   
== Material ==
+
* [http://conal.net/papers/frp.html Conal Elliott’s FRP papers]
+
== Publications and talks ==
* [http://conal.net/blog/tag/functional-reactive-programming/ FRP-related posts on Conal's blog]
+
* [http://www.cs.rit.edu/~eca7215/frp-independent-study/Survey.pdf A Survey of Functional Reactive Programming]
* [[Grapefruit#Publications and talks|Grapefruit-related publications and talks]]
+
* [http://conal.net/papers/frp.html Conal Elliott’s FRP-related publications]
* [http://www.haskell.org/yale/publications.html The Yale Haskell group’s latest publications] (mostly related to FRP)
+
* [https://grapefruit-project.org/publications-and-talks Grapefruit-related publications and talks]
* [http://apfelmus.nfshost.com/blog.html#functional-reactive-programming-frp FRP section] of Heinrich Apfelmus' blog
+
* [http://haskell.cs.yale.edu/?page_id=65#FunctionalReactiveProgramming The Yale Haskell Group’s FRP-related publications]
  +
  +
  +
== Blog posts ==
  +
* [http://apfelmus.nfshost.com/blog.html#functional-reactive-programming-frp FRP-related posts on Heinrich Apfelmus’ blog]
  +
* [http://conal.net/blog/tag/frp FRP-related posts on Conal Elliott’s blog]
  +
* [http://jeltsch.wordpress.com/tag/frp/ FRP-related posts on Wolfgang Jeltsch’s blog]
  +
* [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
  +
   
 
== People ==
 
== People ==
 
* [http://apfelmus.nfshost.com/ Heinrich Apfelmus]
 
* [http://apfelmus.nfshost.com/ Heinrich Apfelmus]
* [http://www.apocalypse.org/pub/u/antony/work/index.html Antony Courtney]
+
* [http://www.facebook.com/antony.courtney Antony Courtney]
 
* [http://conal.net/ Conal Elliott]
 
* [http://conal.net/ Conal Elliott]
 
* [http://sgate.emt.bme.hu/patai/ Patai Gergely]
 
* [http://sgate.emt.bme.hu/patai/ Patai Gergely]
* [http://www.ittc.ku.edu/~andygill Andy Gill]
+
* [http://www.ittc.ku.edu/csdl/fpg/Users/AndyGill Andy Gill]
 
* Liwen Huang
 
* Liwen Huang
 
* Paul Hudak
 
* Paul Hudak
* [http://www.tu-cottbus.de/fakultaet1/de/programmiersprachen-compilerbau/lehrstuhl/mitarbeiter/wolfgang-jeltsch.html Wolfgang Jeltsch]
+
* [https://wolfgang.jeltsch.info/ Wolfgang Jeltsch]
 
* [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]
   
== Blog articles ==
+
[[Category:FRP|*]]
* [http://lukepalmer.wordpress.com/2008/11/28/relative-time-frp/ Relative time FRP]
 
* Several on [http://conal.net/blog Conal's blog]
 
* [http://blog.edwardamsden.com/2011/03/demonstrating-time-leak-in-arrowized.html Demonstrating a Time Leak in Arrowized FRP]
 

Revision as of 16:24, 16 November 2012

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.


Contents

1 Introduction

FRP is about domain-specific languages that capture the notion of time-varying values. Let's take Netwire 4 as an example. You can install it either from HackageDB,

   cabal install netwire

or by grabbing the latest source code via darcs:

   darcs get http://darcs.ertes.de/netwire/
   cd netwire
   cabal install

Imagine you have a simple GUI label that displays the number of seconds passed since program start. In an event-based model this is actually quite a complicated task. You would have to create a label and update it all the time using some form of timer/idle event. In Netwire you write:

   myLabel = time

Now let's say you want to have the same GUI, but the time should start at 10 and pass twice as fast, so you actually want to display twice the number of seconds passed plus 10:

   myLabel = 10 + 2*time

Imagine you want to display the string "yes" in a label:

   myLabel = "yes"

Now let's say you want to display "yes", when the space key is held down and "no" otherwise:

   myLabel = "yes" . keyDown Space <|> "no"

You want to display time while pressed and "Press space" while not:

   myLabel = fmap show time . keyDown Space <|> "Press space"

You want to display "yes" every other second and "no" otherwise:

   myLabel = "yes" . holdFor 1 (periodically 2) <|> "no"

Imagine doing that with event-based code.

Summary: FRP is about handling time-varying values like they were regular values.

2 Libraries


3 Publications and talks


4 Blog posts


5 People