-
Notifications
You must be signed in to change notification settings - Fork 2
/
Presentation.tex
473 lines (413 loc) · 12.3 KB
/
Presentation.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
\documentclass{enigtex-beamer-base}
\useoutertheme{miniframes}
\usepackage{comment}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{minted}
\title{Rhine - FRP with type level clocks}
\subtitle{A tea tutorial}
\author{Manuel Bärenz}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\section{Setup}
\begin{frame}[fragile]
\note<.>{Open a console and run these commands to set up the tutorial environment.
While you do so, I'm going to introduce you to Rhine and explain the plan for the tutorial.}
\begin{verbatim}
cabal update
git clone https://github.com/turion/rhine-tutorial/
cd rhine-tutorial
cabal sandbox init
cabal install --only-dependencies
cabal configure
cabal build
cabal run rhine-tutorial
\end{verbatim}
Read documentation on \href{http://hackage.haskell.org/package/rhine}{http://hackage.haskell.org/package/rhine} (version 0.1.0.0)!
\end{frame}
\section{Quick introduction to Rhine}
\subsection{Synchronous arrowized FRP}
\begin{frame}[fragile]
\begin{block}<+->{\texttt{Dunai} (Iván Pérez, Henrik Nilsson, MB)}
\begin{minted}{haskell}
data MSF m a b = MSF (a -> m (b, MSF m a b))
\end{minted}
\end{block}
\begin{block}<+->{}
\begin{minted}{haskell}
-- Control.Arrow
(>>>) :: MSF m a b -> MSF m b c -> MSF m a c
(***) :: MSF m a b -> MSF m c d -> MSF m (a,c) (b,d)
arr :: (a -> b) -> MSF m a b
\end{minted}
\end{block}
\begin{block}<+->{}
\begin{minted}{haskell}
-- only dunai
arrM :: (a -> m b) -> MSF m a b
\end{minted}
\end{block}
\begin{itemize}[<+->]
\item \mintinline{haskell}{MSF (Reader Double)} is a replacement for \mintinline{haskell}{FRP.Yampa.SF}.
\item Other monads allow for concise FRP paradigms:
\begin{itemize}[<+->]
\item \mintinline{haskell}{State}, \mintinline{haskell}{Reader} and \mintinline{haskell}{Writer} give global state variables.
\item \mintinline{haskell}{List} gives branching computations.
\item \mintinline{haskell}{Either} gives control flow!
\end{itemize}
\item Support for (entering and leaving) monad transformers.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\begin{block}<+->{Arrow syntax}
\begin{minted}{haskell}
{-# LANGUAGE Arrows #-}
verboseSum :: MSF IO Int Int
verboseSum = proc n -> do
s <- sumS -< n
_ <- arrM print -< "The sum is now " ++ show s
returnA -< s
\end{minted}
\end{block}
\end{frame}
\subsection{Clocks}
\begin{frame}[fragile]
\begin{description}[<+->]
\item[Clock type] All relevant properties of the clock, such as ...
\begin{itemize}[<+->]
\item When, and how often, the clock should tick
\item Which monad the clock takes side effects in
\item What additional data (besides a time stamp) the clock outputs
\end{itemize}
\item[Clock value] All information needed to run the clock
\begin{itemize}[<+->]
\item E.g. physical device address, event socket
\item Implementation choice
\end{itemize}
\item[Running clock] Side-effectful stream of \emph{time stamps}, tagged with additional info about the \emph{tick}.
\end{description}
\end{frame}
\begin{frame}[fragile]
\begin{block}<+->{\texttt{Rhine}}
\begin{minted}{haskell}
-- simplified here
class Clock m cl where
type Time cl -- time stamp
type Tag cl -- additional information about tick
initClock :: cl -> MSF m () (TimeInfo cl, Tag cl)
\end{minted}
\end{block}
\begin{block}<+->{}
\begin{minted}{haskell}
data TimeInfo cl = {...}
-- absolute and relative time, tag
\end{minted}
\end{block}
\note<.>{While a clock only needs to output a time stamp,
\texttt{Rhine} calculates absolute and relative (to the start of the program and to the last tick) time.}
\end{frame}
\begin{frame}[fragile]
\visible<+->{A clock produces side effects to...}
\begin{itemize}
\item[...] wait between ticks,
\item[...] measure the current time,
\item[...] produce additional data (e.g. events).
\end{itemize}
\begin{block}<+->{Examples of clocks}
\begin{itemize}
\item Fixed sample rate (e.g. \mintinline{haskell}{Millisecond n})
\item Events (e.g. \mintinline{haskell}{Stdin})
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}<+->{}
\begin{minted}{haskell}
type ClSF m cl a b = MSF (ReaderT (TimeInfo cl) m) a b
\end{minted}
\end{block}
\begin{block}<+->{Lifting \texttt{dunai} concepts}
\begin{minted}{haskell}
arrMCl :: (a -> m b) -> ClSF m cl a b
...
\end{minted}
\end{block}
\begin{block}<+->{Time information}
\begin{minted}{haskell}
timeInfo :: ClSF m cl () (TimeInfo cl)
\end{minted}
\end{block}
\begin{block}<+->{Basic signal processing}
\begin{minted}{haskell}
integral :: VectorSpace v => ClSF m cl v v
...
\end{minted}
\end{block}
\end{frame}
\subsection{Exceptions and control flow}
\begin{frame}[fragile]
\begin{block}<+->{\mintinline{haskell}{ExceptT}...}
\begin{minted}{haskell}
data Either e a = Left e | Right a
newtype ExceptT e m a = ExceptT (m (Either e a))
\end{minted}
\end{block}
\begin{block}<+->{...control flow! (Thanks to Paolo Capriotti)}
\begin{minted}{haskell}
-- dunai, rhine (simplified)
newtype ClSFExcept m cl a b e
= ClSFExcept (ClSF (ExceptT e m) cl a b)
\end{minted}
\end{block}
\begin{block}<+->{}
\begin{minted}{haskell}
instance Monad m => Monad (ClSFExcept m cl a b)
throwOn' :: ClSF (ExceptT e m) cl (Bool, e) ()
try :: ClSF (ExceptT e m) cl a b
-> ClSFExcept m cl a b e
safely :: ClSFExcept m cl a b Empty -> ClSF m cl a b
safe :: ClSF m cl a b -> SyncExcept m cl a b e
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}<+->{Hello World!}
\begin{minted}{haskell}
type SumClock = Millisecond 100
fillUp :: ClSF (ExceptT Double m) SumClock Double ()
fillUp = proc x -> do
s <- integral -< x
_ <- throwOn' -< (s > 5, s)
returnA -< ()
helloWorld :: ClSFExcept IO SumClock () () Empty
helloWorld = do
try $ arr (const 1) >>> fillUp
once_ $ putStrLn "Hello World!"
helloWorld
main = flow $ safely helloWorld @@ waitClock
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Clock safety}
\begin{minted}{haskell}
fastSignal :: ClSF m FastClock () a
slowProcessor :: ClSF m SlowClock a b
clockTypeError = fastSignal >>> slowProcessor
\end{minted}
\end{block}
\begin{verbatim}
PresentationExamples.hs:67:33: error:
• Couldn't match type ‘SlowClock’ with ‘FastClock’
\end{verbatim}
\end{frame}
\subsection{Asynchronous FRP}
\begin{frame}[fragile]
\begin{block}<+->{}
\begin{minted}{haskell}
data Schedule m cl1 cl2
\end{minted}
\end{block}
\begin{block}<+->{Binary schedules}
Execute two different clocks simultaneously.
\end{block}
\begin{itemize}[<+->]
\item Can be clock-polymorphic or specific to certain clocks.
\item (No implementation details here.)
\item Some examples:
\begin{itemize}[<+->]
\item \mintinline{haskell}{concurrently :: Schedule IO cl1 cl2}
\item \mintinline{haskell}{schedule :: Schedule (ScheduleT m) cl1 cl2}
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\begin{block}<+->{}
\begin{minted}{haskell}
data ResamplingBuffer m cla clb a b = ResamplingBuffer
{ put :: TimeInfo cla -> a
-> m ( ResamplingBuffer m cla clb a b)
, get :: TimeInfo clb
-> m (b, ResamplingBuffer m cla clb a b)
}
\end{minted}
\end{block}
\begin{block}<+->{Resampling buffers}
Buffer data at the boundary between two asynchronous systems.
\end{block}
\begin{itemize}[<+->]
\item Can be clock-polymorphic or specific to certain clocks.
\item Some examples
\begin{itemize}[<+->]
\item \mintinline{haskell}{collect :: ResamplingBuffer m cl1 cl2 a [a]}
\item \mintinline{haskell}{fifo :: ResamplingBuffer m cl1 cl2 a (Maybe a)}
\item \mintinline{haskell}{keepLast :: a -> ResamplingBuffer m cl1 cl2 a a}
\item Linear interpolation, combinators to build your own\dots
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\begin{block}<+->{Asynchronous signal functions}
\begin{minted}{haskell}
data SN m cl a b -- Signal network
type family In cl
type family Out cl
\end{minted}
\end{block}
\begin{block}<+->{A clocked reactive program}
\begin{minted}{haskell}
data Rhine m cl a b
\end{minted}
(...basically an \mintinline{haskell}{SF} and a matching clock!)
\end{block}
\begin{block}<+->{Execution (reactimation)}
\begin{minted}{haskell}
flow :: Rhine m cl () () -> m ()
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}<+->{Synchronous subsystems}
\begin{minted}{haskell}
cl :: MyClock
sf :: ClSF m MyClock A B
rhineCl :: Rhine m MyClock A B
rhineCl = sf @@ cl
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}<+->{Parallel composition}
\begin{minted}{haskell}
clL :: MyClockL
clR :: MyClockR
sfL :: ClSF m MyClockL C D
sfR :: ClSF m MyClockR C D
schedPar :: Schedule m MyClockL MyClockR
rhinePar = sfL @@ clL **@ schedPar @** sfR @@ clR
\end{minted}
\end{block}
\begin{block}<+->{Sequential composition}
\begin{minted}{haskell}
buf :: ResamplingBuffer m MyClock (In (..)) B C
schedSeq :: Schedule m ...
rhineSeq = rhineCl >-- buf -@- schedSeq --> rhineP
\end{minted}
\end{block}
\end{frame}
\begin{comment}
Introduction what Rhine can do
Basic vocab
Arrowized FRP
Synchronous subsystems
Clocks
Schedules
Resampling buffers
Events and behaviours
Comparison (differences, +, -) to
Yampa
dunai, auto, varying
classical FRP
Pipes, conduit
Further plan
Mission statement what we want to implement
Ideas
FRP zoo
Extra features?
Tea time
First without, then with GUI
Given enough time, implement audience suggestions
\end{comment}
\section{Let's hack!}
\begin{frame}
\begin{block}<+->{The plan: A tea app}
\begin{itemize}
\item Run several tea timers in parallel
\item Reactively read tea requests from the console
\end{itemize}
\end{block}
\visible<+->{\textbf{Any questions before we start hacking?}}
\end{frame}
\begin{frame}
\textbf{Have fun!}
\end{frame}
\section{After the tutorial}
\subsection{What Rhine can do}
\begin{frame}
\begin{block}<+->{What else you could (easily) do with \texttt{Dunai} and \texttt{Rhine}}
\begin{itemize}
\item Simple arcade games (SDL, Gloss)
\item Reactive console apps
\end{itemize}
\end{block}
\begin{block}<+->{What should be doable, but I didn't do yet because of lazyness}
\begin{itemize}
\item Webservers, server-side web apps
\item Interactive File I/O
\item GUI programs
\item External devices (e.g. Kinect, Wiimote)
\end{itemize}
\end{block}
\begin{block}<+->{What might eventually be feasible}
\begin{itemize}
\item Reactive audio synthesis, processing and analysis (performance...)
\item Reactive web apps (GHCJS...)
\item Android, embedded systems (recent GHC...)
\end{itemize}
\end{block}
\end{frame}
\subsection{Comparison to other frameworks}
\begin{frame}[fragile]
\begin{tabular}{p{2.5cm}p{3.5cm}p{3.5cm}}
\toprule
\textbf{Framework}
& \textbf{Pro \texttt{Rhine}}
& \textbf{Contra \texttt{Rhine}}
\\\midrule
Yampa, dunai
& Asynchronicity, clock types
& Performance
\\\midrule
Pipes, conduit
& FRP, clocks
& Performance?
\\\midrule
Most classical FRP frameworks
& No \mintinline{haskell}{IO} built in, clock types
& ?
\\\midrule
C$\lambda$aSH
& General purpose
& No compilation to circuits
\end{tabular}
\end{frame}
\subsection{More information}
\begin{frame}[fragile]
\begin{block}<+->{\texttt{Dunai}}
\begin{itemize}[<+->]
\item \href{https://github.com/ivanperez-keera/dunai}{github.com/ivanperez-keera/dunai}
\item There's a link to the article!
\end{itemize}
\end{block}
\begin{block}<+->{\texttt{Rhine}}
\begin{itemize}[<+->]
\item Article: \href{https://github.com/turion/rhine#documentation}{github.com/turion/rhine\#documentation}
\item This tutorial: \href{https://github.com/turion/rhine-tutorial/}{github.com/turion/rhine-tutorial/}
\item Checkout branch \texttt{final} for solutions
\item Documentation on hackage
\item Simple examples in \href{https://github.com/turion/rhine/}{github.com/turion/rhine/}
\end{itemize}
\end{block}
\end{frame}
\subsection{What you can do}
\begin{frame}
\begin{itemize}[<+->]
\item Use \texttt{Rhine} at the hackathon and win a nice bar of chocolate!
\item Create issues on \href{https://github.com/turion/rhine/}{github.com/turion/rhine/} and ask for your most needed clocks, schedules, resampling buffers etc.!
\item Look at easy to solve issues on \href{https://github.com/ivanperez-keera/dunai}{github.com/ivanperez-keera/dunai}!
\end{itemize}
\end{frame}
\end{document}