Implements Functional Reactive Programming.
Allows for dynamic programs whose structure changes over time.
Isolates of effect-free signal functions from effectful actions.
Runs fast and is memory efficient.
Has been industry tested.
Provides a robust, elegant, stable interface.
Has well-defined semantics.
Supports applicative, functional and arrowized styles.
Supports all platforms and enjoys multiple backends.
Programs can be tested with QuickCheck and debugged using Haskell Titan.
To use Yampa, you must have a Haskell compiler installed (GHC). We currently support all versions of GHC from 7.6.3 to modern versions (9.X series as of this writing).
On Debian/Ubuntu, the Haskell toolchain can be installed with:
$ apt-get install ghc cabal-install
On Mac, they can be installed with:
$ brew install ghc cabal-install
Once you have a working set of Haskell tools installed, install Yampa from hackage by executing:
$ cabal update
$ cabal install --lib Yampa
Running the following will print the word Success
if installation has gone
well, or show an error message otherwise:
$ runhaskell <<< 'import FRP.Yampa; main = putStrLn "Success"'
Getting Yampa to run is trivial. FRP is about values that change over time. In Yampa, a system is defined by a signal function (SF), which determines how the varying input and the varying output relate.
Code can be written in multiple styles: applicative style, arrowized style, and just plain arrow combinators. All three are compatible and interchangeable.
For example, the following signal function takes a value, integrates it, and then divides that value by the current time:
{-# LANGUAGE Arrows #-}
import FRP.Yampa
signalFunction :: SF Double Double
signalFunction = proc x -> do
y <- integral -< x
t <- time -< ()
returnA -< y / t
This signal function says that the output signal is the integral y
of the
input signal x
, divided by the time t
. The elements between <-
and -<
are always signal functions (in this case, integral
and time
are signal
functions used to define another signal function).
The example above is written in arrow syntax and uses a Haskell extension called Arrows. If you are unhappy using arrow syntax, you can implement the same behavior using applicative style and/or arrow combinators:
-- Applicative style
signalFunction1 :: SF Double Double
signalFunction1 = (/) <$> integral <*> time
-- Functional style with arrow combinators
signalFunction2 :: SF Double Double
signalFunction2 = (integral &&& time) >>^ (/)
All three are equivalent, and it's a matter of which one you like best.
To run this example, we need to provide the inputs, the times, and consume the output:
firstSample :: IO Double -- sample at time zero
firstSample =
return 1.0 -- time == 0, input == 1.0
nextSamples :: Bool -> IO (Double, Maybe Double)
nextSamples _ =
return (0.1, Just 1.0) -- time delta == 0.1s, input == 1.0
output :: Bool -> Double -> IO Bool
output _ x = do
print x -- print the output
return False -- just continue forever
This is a trivial example, since the integral of the constant function 1.0 over time, divided by the time, is always 1.0! Nevertheless, we are now ready to run!
ghci> reactimate firstSample nextSamples output signalFunction
1.0
1.0
1.0
1.0
1.0
1.0
...
There is a directory with examples, which includes two basic SDL examples and one with using a Nintendo Wii Remote. You can install them with:
$ cabal update
$ cabal install Yampa -fexamples
A more comprehensive list can be obtained using the reverse dependency finder (http://packdeps.haskellers.com/reverse/Yampa), but only programs uploaded to hackage are listed.
Haskanoid, SDL cross-platform arkanoid. | Peoplemon, a role playing game | Yampa2048, a gloss board game |
Keera Studios uses Yampa to create Haskell games available on Google Play for Android and iTunes for iOS:
Yampa is backend agnostic, you can ultimately connect it to any backend you want. Existing backends include:
Yampa comes with a sophisticated testing library that allows you to use QuickCheck to test your games, and use a time-travel debugger. These features are described in the paper Testing and Debugging Functional Reactive Programming.
You can find the additional projects at:
The API of Yampa is thoroughly documented on hackage. Documentation is also available in the Haskell wiki page for Yampa.
Using Functional Reactive Programming for Robotic Art: An Experience Report (Eliane I. Schmidli and Farhad Mehta; 2024)
Demo: The Fun of Robotic Artwork (Eliane I. Schmidli and Farhad Mehta; 2024)
Reactamole: functional reactive molecular programming (Titus Klinge, James Lathrop, Peter-Michael Osera, Allison Rogers; 2024)
The Beauty and Elegance of Functional Reactive Animation (Ivan Perez; 2023)
Extensible and Robust Functional Reactive Programming (Ivan Perez; 2017)
Testing and Debugging Functional Reactive Programming (Ivan Perez and Henrik Nilsson; 2017)
Functional Reactive Programming, Refactored (Ivan Perez, Manuel Bärenz, and Henrik Nilsson; 2016)
Safe Functional Reactive Programming through Dependent Types (Neil Sculthorpe and Henrik Nilsson; 2009)
Push-Pull Functional Reactive Programming (Conal Elliott; 2009)
Switched-on Yampa: Declarative Programming of Modular Synthesizers (George Giorgidze and Henrik Nilsson; 2008)
Demo-outline: Switched-on Yampa: Programming Modular Synthesizers in Haskell (George Giorgidze and Henrik Nilsson; 2007)
Dynamic Optimization for Functional Reactive Programming using Generalized Algebraic Data Types (Henrik Nilsson; 2005)
The Yampa Arcade (Antony Courtney, Henrik Nilsson, and John Peterson; 2003)
Arrows, Robots, and Functional Reactive Programming (Paul Hudak, Antony Courtney, Henrik Nilsson, and John Peterson; 2002)
Functional Reactive Programming, Continued (Henrik Nilsson, Antony Courtney, and John Peterson; 2002)
Genuinely Functional User Interfaces (Antony Courtney and Conal Elliott; 2001)
See also:
If this library helps you, you may want to consider buying the maintainer a cup of coffee.
Discussions
If you have any comments, questions, ideas, or other topics that you think will be of interest to the Yampa community, start a new discussion here. Examples include:
Issues
If a specific change is being proposed (either a new feature or a bug fix), you can open an issue documenting the proposed change here.
If you are unsure about whether your submission should be filed as an issue or as a discussion, file it as a discussion. We can always move it later.
Pull requests
Once we determine that an issue will be addressed, we'll decide who does it and when the change will be added to Yampa. Even if you implement the solution, someone will walk you through the steps to ensure that your submission conforms with our version control process, style guide, etc. More information on our process is included below.
Please, do not just send a PR unless there is an issue for it and someone from the Yampa team has confirmed that you should address it. The PR is very likely to be rejected, and we really want to accept your contributions, so it will make us very sad. Open a discussion / issue first and let us guide you through the process.
This project is split in two:
Yampa's unit tests are mostly implemented as tests inside the yampa-test
library. The module hierarchy of yampa-test/tests/Test
mirrors that of Yampa.
Yampa also includes some benchmarks as part of the main library. You are encouraged to use them to evaluate your pull requests, and to improve the benchmarks themselves.
A directory yampa/examples
contains a number of examples of Yampa programs,
some of which can be installed with the flag -fexamples
.
We follow this style guide for the Haskell code and this style guide for Cabal files.
We follow git flow. In addition:
Refs #<issue_number>
at the end.<package_name>: <...rest_of_summary...>
.See the recent repo history for examples of this process. Using a visual repo
inspection tool like gitk
may help.
The versioning model we use is the standard in Haskell packages. Versions have
the format <PUB>.<MAJOR>.<MINOR>(.<PATCH>)?
where:
<PUB>
is just a way to signal important milestones or used for promotional
reasons (to indicate a major advancement). A zero on this position has no
special meaning.
<MAJOR>
increases on incompatible API changes.
<MINOR>
increases on backwards-compatible changes.
<PATCH>
(optional) increases on small changes that do not affect behavior
(e.g., documentation).
This library was created by Henrik Nilsson and Antony Courtney in 2002, while working at Yale's Haskell group, led by Paul Hudak. The design and implementation benefited from frequent discussions with other members of the group, including also John Peterson. From 2008 to 2012, it was maintained by George Giorgidze. In 2014, maintenance was passed to Ivan Perez.
Yampa is the longest standing FRP implementation in Haskell still in use. It has seen and continues to see abundant use in industry, research, and academia. We invite you to be part of this incredible community project as a user, a contributor, and overall supporter.
Yampa is named after the Yampa river in Colorado, USA.