Functional Reactive Programming: Difference between revisions
m (→Publications and talks: case correction) |
(Added a brief explanation in the new section "Introduction"; copied froman e-mail from Ertugrul Söylemez, with permission) |
||
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. It's not on | |||
Hackage yet, so you may want to grab it using darcs: | |||
darcs get http://darcs.ertes.de/netwire/ | |||
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://hackage.haskell.org/package/sodium Sodium] | * [http://hackage.haskell.org/package/sodium Sodium] | ||
Line 12: | Line 58: | ||
* [[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] | |||
== Publications and talks == | == Publications and talks == | ||
Line 20: | Line 66: | ||
* [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 74: | ||
* [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 == |
Revision as of 15:05, 16 September 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.
Introduction
FRP is about domain-specific languages that capture the notion of time-varying values. Let's take Netwire 4 as an example. It's not on Hackage yet, so you may want to grab it using darcs:
darcs get http://darcs.ertes.de/netwire/
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
- Sodium
- Grapefruit
- Reactive
- DataDriven
- Yampa
- wxFruit
- Elerea
- reactive-banana
- Netwire
- Fran (discontinued)
- Hackage packages in the category FRP
Publications and talks
- A Survey of Functional Reactive Programming
- Conal Elliott’s FRP-related publications
- Grapefruit-related publications and talks
- The Yale Haskell Group’s FRP-related publications
Blog posts
- FRP-related posts on Heinrich Apfelmus’ blog
- FRP-related posts on Conal Elliott’s blog
- FRP-related posts on Wolfgang Jeltsch’s blog
- Relative time FRP by Luke Palmer
- Demonstrating a Time Leak in Arrowized FRP by Edward Amsden
People
- Heinrich Apfelmus
- Antony Courtney
- Conal Elliott
- Patai Gergely
- Andy Gill
- Liwen Huang
- Paul Hudak
- Wolfgang Jeltsch
- Henrik Nilsson
- John Peterson