Learning Yampa and Functional Reactive Programming
This blog post was originally written back in 2010-06-13
If you are just starting to learn Yampa, please share your experiences! This post just covers my personal opinion on how to tackle Yampa, maybe you have additional or different recommendations.
Recommendations for learning
I recommend reading the following papers/presentations to learn Yampa and FRP in general:
A Brief Introduction to Functional Reactive Programming and Yampa (slides)
Arrows, Robots and Functional Programming: covers Yampa basics in detail (Section 3 is very domain specific and may be omitted)
Functional Reactive Programming, Continued: more Yampa basics
The Yampa Arcade: standard paper for games
Dynamic, Interactive Virtual Environments: read chapter 3 – Time and appendix A – Functional Reactive Programming
Functional Programming and 3D Games: Yampa basics in games, not very detailed though
Functional Reactive Programming from First Principles: Yampa implementation details
Dynamic Optimization for Functional Reactive Programming: Yampa optimization details
Understanding FRP
I think to learn FRP (for games) you have to especially understand the following aspects:
Signals make time omnipresent
Systems are built with Signal Functions (
SF a b
)FRP is implemented in standard Haskell
Arrow notation makes using FRP convenient and more readable
Signal functions diagrams look just mirrored to the actual arrow notation code :)
The signal function systems need to be updated somehow – usually via
reactimate
reactimate
divides the programm into input IO (sense), the signal function (SF
) and output IO (actuate)Switches allow dynamic changes of the reactive system. Note that in Yampa signal functions are continuation-based so they “switch into” a new signal function.
To handle dynamic game object collections use the delayed parallel switch (
dpSwitch
) signal functionInput events are propagated to the objects via
route
route
also reasons about the whole object collection to produce logical events (f.e. hit detection)killOrSpawn
collects all kill and spawn events into one big function composition (insertion/deletion) which is applied to the object collectionIn the Space Invaders example
gameCore :: IL Object -> SF (GameInput, IL ObjOutput) (IL ObjOutput)
is actually embedded in the functioncore :: ... -> SF GameInput (IL ObjOutput)
which acts as the intermediate between sense and actuate (this is not mentioned in the Yampa Arcade paper)
Complete list of recommended papers
Covering FRP in general and FRP in games:
A Brief Introduction to Functional Reactive Programming and Yampa (slides)
Directions in Functional Programming for RealTime Applications
Plugging A Space Leak With An Arrow
Push-Pull Functional Reactive Programming
List of discarded papers
The reason for discarding was mostly because they are too old, too theoretical or off-topic from games:
A Functional Reactive Animation Of A Lift Using Fran
A Language for Declarative Robotic Programming
Crafting Game-Models Using Reactive System Design
Event-Driven FRP
FrTime – A Language for Reactive Programs
Functional Reactive Animation
Functional Reactive Programming for Real-Time Reactive Systems
Genuinely Functional User Interfaces
Interactive Functional Objects in Clean
Modelling Reactive Multimedia – Events and Behaviours
Modular Domain Specific Languages and Tools
Prototyping Real-Time Vision Systems
Reactive Multimedia Documents in a Functional Framework
Real-Time FRP