Functional Reactive Programming (FRP) with reactive-banana-0.6.0.0
Heinrich Apfelmus
Functional Reactive Programming (FRP) with reactive-banana-0.6.0.0
Heinrich Apfelmus
Why? Functional reactive programming is an elegant method for implementing interactive programs
• graphical user interfaces (GUI) • animations • digital music • robotics
How? variation in time as first-class value
type Behavior a = Time → a type Event a = [(Time, a)]
The key data types are Behavior and Event. Behavior corresponds to a „value that varies in time“. Event corresponds to „events that occurr at certains points in time“. I‘m going to explain how to understand them. Of course, the real implementation is abstract.
Behavior type Behavior a = Time → a
Value
• position – animation • text value – GUI • volume – music • physical quantity t2 y(t) = y0 + v0 t − g 2
Time A Behavior associates a value to each point in time.
Behavior API instance Functor Behavior
Functor
instance Applicative Behavior
Applicative
How to program with Behaviors? The API for Behaviors is actually very simple: they are just applicative functors.
Behavior API (<$>) :: (a -> b) -> Behavior a -> Behavior b
Functor
pure :: a -> Behavior a (<*>) :: Behavior (a -> b) -> Behavior a -> Behavior b
Applicative
bf <*> bx = \time -> bf time $ bx time
at each point in time
Reminder on the functions associated with Functor and Applicative classes. The most important function is the <*> operator, which is called „apply“ and applies a time-varying function to a time-varying value, simply by applying them at each point in time. The `pure` function constructs a value that stays constant in time.
Double
Behavior API a
b
1 0
Time
Time
(*) <$> a <*> b
Time Example task: attenuate an oscillation.
Event type Event a = [(Time,a)]
Value
• mous clicks – GUI • notes – music • collision – physics Time An Event is a collection of values that „occur“ at particular points in time. You can also see that event occurrences may happen simultaneously, at least in reactive-banana-0.6.
Event API instance Functor Event never :: Event a unionWith :: (a -> a -> a) -> Event a -> Event a -> Event a
Functor List [] zipWith
filterE
:: (a -> Bool) -> Event a -> Event a
filter
accumE
:: a -> Event (a -> a) -> Event a
scanl
How to program with Events? The API for Events is a bit more elaborate, but is closely related to operations on lists.
Event API x
filterE (> 5) x
Int 10 0
Example: filterE
Time
Time
Event & Behavior API stepper :: a -> Event a -> Behavior a
x
stepper 2 x
Time
2
Time
Of course, the most interesting part about the API concerns the interaction between Behavior and Event. The `stepper` function turns an Event into a Behavior by remembering the value. The result is a step function, hence the name.
Event & Behavior API (<@>) :: Behavior (a -> b) -> Event a -> Event b (<@)
„apply“
:: Behavior b -> Event a -> Event b
The <@> operator is called „apply“ and applies a time-varying function to event occurrences. Its little brother <@ tags an Event with values from the Behavior. It is analogous to the <$ operator from Data.Functor.
Event & Behavior API ()
b
e
Time
Time b <@ e
Time Visualization of the <@ operator.
Frameworks (GUI, ...) data NetworkDescription t a
fromAddHandler
import Event
fromPoll
import Behavior
reactimate
export Event
changes
get Event from Behavior
The API discussed so far allows you to combine existing Events and Behaviors into new ones, but it doesn‘t tell you how to get them in the first place. For this, you have to bind to external frameworks like wxHaskell. The NetworkDescription monad from the module Reactive.Banana.Frameworks allows you to do this. It‘s not a very interesting monad, it‘s just a device for bookkeeping and I recommend that you think of it as some sort of syntactic sugar.
with reactive-banana-0.6.0.0 Heinrich Apfelmus - GitHub
variation in time as first-class value type Behavior a = Time â a type Event a = [(Time, a)]. The key data types are Behavior and Event. Behavior corresponds to a ...
Page 1 of 2. Heinrich Heine on Burning Books. Connecting the Holocaust to Book Burning. By Austin Cline, About.com Guide. Two of the actions which Nazi Germany is most infamous for are probably the burning of books and the. burning of people. Are the
processes the control flow graph and transforms it into a state machine. This is required because we can then create states function SCOPEMANGLE(node).
Arduino with BMS- and CAN-bus shield as BMS a master. - LTC6802-2 or LTC6803-2 based boards as cell-level boards. - CAN controlled Eltek Valere as a ...
Chrome52 on this Laptop. » ~14kbyte. String => 133ms ... 3-4 Seks processing time on samsung galaxy S5 with crosswalk to finish the transition with ... Page 17 ...
Normally, the networking of distributed systems is ... Service Oriented .... while True: msg = socket.recv() print "Received", msg socket.send(msg). 1. 2. 3. 4. 5. 6. 7.
10. Source Code View . ..... APU, a recent version of Radeon Software, and the OpenCL APP SDK. This document describes ...... lel_Processing_OpenCL_Programming_Guide-rev-2.7.pdf. For GPU ... trademarks of their respective companies.
Jul 23, 2015 - The majority of my experience is in PHP. I ventured into Ruby, ... Compiled, Statically Typed, Concurrent, Imperative language. Originally ...
In this case help.search(log) returns all the functions with the string 'log' in them. ... R environment your 'working directory' (i.e. the directory on your computer's file ... Later in the course we'll discuss some ways of implementing sanity check
Dec 27, 2017 - This lecture notes (to become a book) are an introduction into hardware design with the focus on using the hardware construction language Chisel. The approach of this book is to present small to medium sized typical hardware components
best-in-class algorithms such as Random Forest, Gradient Boosting and Deep Learning at scale. .... elegant web interface or fully scriptable R API from H2O CRAN package. · grid search for .... takes to cut the learning rate in half (e.g., 10â6 mea
Aug 29, 2011 - well with PGF/TikZ packages which might make it the best solution out there. ... done from scratch, the user will end up having a unique theme for his/her ... .tex files, which get compiled when needed and then the resultant .pdf.
The SQL Server Database Engine is a complex software product. For your systems to achieve optimum performance, you need to have a knowledge of Database Engine architecture, understand how query design affects performance, and be able to implement eff
This chapter also presents a system that generates reports combining automatically generated ... in different circumstances, our system converts each kernel expression into a standard, simplified ..... (2013) developed an analytic method for ...
âWhen writing your game no mental model shift ... Switching between different mental models be it java or python or a C++ .... Senior Applications Developer.
May 13, 2015 - Data sources for the ECMWF Meteorological Opera^onal System. 10 .... 13/05/15. 24. Big Data. Scalable Algorithms. Pla orm Uncertainty ...