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 ...

697KB Sizes 3 Downloads 183 Views

Recommend Documents

Otto Heinrich Warburg.pdf
Sign in. Loading… Whoops! There was a problem loading more pages. Retrying... Whoops! There was a problem previewing this document. Retrying.

Heinrich Heine on Burning Books.pdf
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

CP2K with LIBXSMM - GitHub
make ARCH=Linux-x86-64-intel VERSION=psmp AVX=2. To target for instance “Knights ... //manual.cp2k.org/trunk/CP2K_INPUT/GLOBAL/DBCSR.html).

Java with Generators - GitHub
processes the control flow graph and transforms it into a state machine. This is required because we can then create states function SCOPEMANGLE(node).

OpenBMS connection with CAN - GitHub
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 ...

Better performance with WebWorkers - GitHub
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 ...

with ZeroMQ and gevent - GitHub
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.

Getting Started with CodeXL - GitHub
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.

Getting Started with Go - GitHub
Jul 23, 2015 - The majority of my experience is in PHP. I ventured into Ruby, ... Compiled, Statically Typed, Concurrent, Imperative language. Originally ...

Getting Acquainted with R - GitHub
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

Training ConvNets with Torch - GitHub
Jan 17, 2014 - ... features + SVM. – Neural Nets (and discuss discovering graph structure automařcally). – ConvNets. • Notebook Setup ... Page 9 ...

Examples with importance weights - GitHub
Page 3 ... Learning with importance weights y. wT t x wT t+1x s(h)||x||2 ... ∣p=(wt−s(h)x)Tx s (h) = η. ∂l(p,y). ∂p. ∣. ∣. ∣. ∣p=(wt−s(h)x)Tx. Finally s(0) = 0 ...

Digital Design with Chisel - GitHub
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

Deep Learning with H2O.pdf - GitHub
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

How to make presentations with LATEX - GitHub
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.

Getting Started with Transact-SQL Labs - GitHub
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

visualization with ggplot and R - GitHub Pages
Aug 10, 2014 - Some terminology. ▷ data. ▷ aesthetics. ▷ geometry. ▷ The geometric objects in the plot. ▷ points, lines, polygons, etc. ▷ shortcut functions: geom point(), geom bar(), geom line(). Page 20. Basic structure ggplot(data = iris ...... Pa

Automatic Model Construction with Gaussian Processes - GitHub
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 ...

Processing Big Data with Hive - GitHub
Processing Big Data with Hive ... Defines schema metadata to be projected onto data in a folder when ... STORED AS TEXTFILE LOCATION '/data/table2';.

Cluster-parallel learning with VW - GitHub
´runvw.sh ´ -reducer NONE. Each mapper runs VW. Model stored in /model on HDFS runvw.sh calls VW, used to modify VW ...

Realtime HTML5 Multiplayer Games with Node.js - GitHub
○When writing your game no mental model shift ... Switching between different mental models be it java or python or a C++ .... Senior Applications Developer.

NWP Facing the Future with Cpp.pptx - GitHub
May 13, 2015 - Data sources for the ECMWF Meteorological Opera^onal System. 10 .... 13/05/15. 24. Big Data. Scalable Algorithms. Pla orm Uncertainty ...