Hello everyone!
I have been working on a new AFRP (Arrowized Functional Reactive Programming) library for about a month which I wanted to share. It is called reactimate and is heavily inspired by the great Yampa
library.
Quick Intro to AFRP
For everyone not familiar with AFRP. The basic idea is to augment normal functions a -> b
with some internal state. Let’s call this augmented function Signal a b
which transforms a
into b
like a -> b
would. However, not only can Signal a b
transform a
into b
, it can also affect its next execution. If you run Signal a b
multiple times (e.g. in a game loop or some simulation), you have access to its output from previous iterations. For example, you can implement feedback
, which feeds back the previous output as input.
feedback :: b -> Signal (a, b) b -> Signal a b
Why a new library
While working on something else, I have discovered a neat way to represent Signal
s and evaluate them efficiently. I assumed that Yampa
has some overhead and wanted to get better performance.
Key differences to Yampa
While Yampa
is side-effect free, reactimate
embraces IO for better performance and more expressive power. Here are some key differences:
- Allows IO during execution
- Probably has better performance (I have only done microbenchmarks)
- Allows resampling of signals at different frequencies and in different threads
- Experimentally integrates Push-Pull-based FRP (e.g. Events, Dynamics and Behaviors) with AFRP
Utility libraries (reactimate-game, reactimate-physics, reactimate-ldtk)
I have also created some utility libraries which integrate with reactimate
. You can do some very basic 2D rendering, get input from keyboard and mouse, simulate 2D physics and load LDtk files (a 2D level designer).
However, many features are still missing or are only implemented in a rudimentary fashion.
Try it out
You can take a look at the reactimate repository and clone the project. I recommend to check out the snake-example
in reactimate-game.
There is no Hackage release planned right now since there will still be breaking changes regularly.