308
|
1 |
% !TEX program = xelatex
|
22
|
2 |
\documentclass[dvipsnames,14pt,t,xelatex]{beamer}
|
|
3 |
\usepackage{../slides}
|
32
|
4 |
\usepackage{../graphics}
|
22
|
5 |
\usepackage{../langs}
|
|
6 |
%\usepackage{../data}
|
309
|
7 |
\usetikzlibrary{shapes}
|
22
|
8 |
|
|
9 |
\hfuzz=220pt
|
|
10 |
|
|
11 |
%\setmonofont[Scale=.88]{Consolas}
|
|
12 |
%\newfontfamily{\consolas}{Consolas}
|
|
13 |
|
|
14 |
\lstset{language=Scala,
|
|
15 |
style=mystyle,
|
|
16 |
numbersep=0pt,
|
|
17 |
numbers=none,
|
|
18 |
xleftmargin=0mm}
|
|
19 |
|
309
|
20 |
\newcommand{\bl}[1]{\textcolor{blue}{#1}}
|
|
21 |
|
|
22 |
\newcommand{\RIGHTarrow}[3]{%
|
|
23 |
\begin{textblock}{0}(#2,#3)%
|
|
24 |
\onslide<#1>{%
|
|
25 |
\begin{tikzpicture}%
|
|
26 |
\node at (0,0) [single arrow, shape border rotate=0, fill=red,text=red]{a};%
|
|
27 |
\end{tikzpicture}}%
|
|
28 |
\end{textblock}}
|
|
29 |
\newcommand{\LEFTarrow}[3]{%
|
|
30 |
\begin{textblock}{0}(#2,#3)%
|
|
31 |
\onslide<#1>{%
|
|
32 |
\begin{tikzpicture}%
|
|
33 |
\node at (0,0) [single arrow, shape border rotate=180, fill=red,text=red]{a};%
|
|
34 |
\end{tikzpicture}}%
|
|
35 |
\end{textblock}}
|
|
36 |
\newcommand{\DOWNarrow}[3]{%
|
|
37 |
\begin{textblock}{0}(#2,#3)%
|
|
38 |
\onslide<#1>{%
|
|
39 |
\begin{tikzpicture}%
|
|
40 |
\node at (0,0) [single arrow, shape border rotate=270, fill=red,text=red]{a};%
|
|
41 |
\end{tikzpicture}}%
|
|
42 |
\end{textblock}}
|
22
|
43 |
|
|
44 |
% beamer stuff
|
195
|
45 |
\renewcommand{\slidecaption}{PEP (Scala) \liningnums{01}, King's College London}
|
22
|
46 |
|
334
|
47 |
% https://insights.stackoverflow.com/survey/2019#technology-most-loved-dreaded-and-wanted
|
|
48 |
|
|
49 |
% processors in the future / Ahmdahl law
|
|
50 |
% https://www.youtube.com/watch?v=_9mzmvhwMqw
|
|
51 |
|
22
|
52 |
|
|
53 |
\begin{document}
|
|
54 |
|
|
55 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
56 |
\begin{frame}[t]
|
|
57 |
\frametitle{%
|
|
58 |
\begin{tabular}{@ {}c@ {}}
|
|
59 |
\\[5mm]
|
199
|
60 |
\hspace{7mm}\huge PEP Scala (\liningnums{1})
|
22
|
61 |
\end{tabular}}
|
|
62 |
|
|
63 |
\normalsize
|
|
64 |
\begin{center}
|
|
65 |
\begin{tabular}{ll}
|
137
|
66 |
Email: & christian.urban at kcl.ac.uk\\
|
309
|
67 |
Office: & N\liningnums{7.07} (North Wing, Bush House)\bigskip\\
|
|
68 |
Slides \& Code: & KEATS\bigskip\\
|
308
|
69 |
Office Hours: & Thursdays 12:00 -- 14:00\\
|
|
70 |
Additionally: & (for Scala) Tuesdays 10:45 -- 11:45\\
|
22
|
71 |
\end{tabular}
|
|
72 |
\end{center}
|
|
73 |
|
199
|
74 |
%\tiny
|
|
75 |
%developed since 2004 bv Martin Odersky
|
|
76 |
%picture about assignments
|
|
77 |
|
|
78 |
\begin{textblock}{6}(0.5,0.5)
|
|
79 |
\includegraphics[scale=0.035]{../pics/assign.jpg}\\[-1mm]
|
|
80 |
\end{textblock}
|
22
|
81 |
|
|
82 |
\end{frame}
|
|
83 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
84 |
|
|
85 |
|
|
86 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
87 |
\begin{frame}[c]
|
|
88 |
\frametitle{Why Scala?}
|
|
89 |
|
23
|
90 |
\begin{textblock}{6}(3,4)
|
22
|
91 |
\begin{tabular}{l}
|
|
92 |
\mbox{}\hspace{-1mm}\includegraphics[scale=0.36]{../pics/twitter.png}\\[-1mm]
|
|
93 |
\includegraphics[scale=0.30]{../pics/linked.png}\\
|
141
|
94 |
\includegraphics[scale=0.30]{../pics/guardian.jpg}\\[-3mm]
|
22
|
95 |
\mbox{}\hspace{-2mm}\includegraphics[scale=0.38]{../pics/morgan.png}\\[-3mm]
|
|
96 |
\includegraphics[scale=0.30]{../pics/suisse.png}\\
|
23
|
97 |
{\large\bf ...}
|
|
98 |
\end{tabular}
|
|
99 |
\end{textblock}
|
|
100 |
|
|
101 |
\begin{textblock}{6}(9,4)
|
|
102 |
\begin{tabular}{l}
|
22
|
103 |
\includegraphics[scale=0.20]{../pics/edf.png}\\[-1mm]
|
|
104 |
\includegraphics[scale=0.08]{../pics/novell.png}\\[-1mm]
|
|
105 |
\includegraphics[scale=0.30]{../pics/foursquare.png}\\
|
|
106 |
\includegraphics[scale=0.30]{../pics/hsbc.png}\\
|
|
107 |
{\large\bf ...}
|
|
108 |
\end{tabular}
|
|
109 |
\end{textblock}
|
|
110 |
|
199
|
111 |
|
|
112 |
\begin{textblock}{6}(2,12)
|
308
|
113 |
\begin{bubble}[9.4cm]
|
199
|
114 |
\small
|
308
|
115 |
developed since 2004 by Martin Odersky
|
200
|
116 |
(he was behind Generic Java which was included in Java 5
|
308
|
117 |
\ldots I am using Scala since maybe 2008?)
|
199
|
118 |
\end{bubble}
|
|
119 |
\end{textblock}
|
|
120 |
|
22
|
121 |
\end{frame}
|
|
122 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
123 |
|
174
|
124 |
|
23
|
125 |
|
|
126 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
127 |
\begin{frame}[c]
|
|
128 |
\frametitle{Why Scala?}
|
|
129 |
|
|
130 |
\begin{itemize}
|
34
|
131 |
\item compiles to the JVM\\
|
|
132 |
\textcolor{gray}{(also JavaScript, native X86 in the works)}\medskip
|
32
|
133 |
\item integrates seamlessly with Java\medskip
|
33
|
134 |
\item combines \underline{\bf functional} and {\bf object-oriented} programming\bigskip
|
308
|
135 |
\item it is a bit on the ``theory'' / ``mathematical'' side\\
|
199
|
136 |
\textcolor{gray}{(no pointers, no \texttt{null}, but expressions)}
|
34
|
137 |
|
33
|
138 |
\item often one can write very concise and elegant code
|
|
139 |
\end{itemize}\bigskip\medskip
|
|
140 |
|
308
|
141 |
%\small
|
|
142 |
%alternatives:\\
|
|
143 |
%Elm, Haskell, Ocaml, F$\sharp$, Erlang, ML, Lisp (Racket), \ldots
|
23
|
144 |
|
|
145 |
\end{frame}
|
22
|
146 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
23
|
147 |
|
|
148 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
308
|
149 |
\begin{frame}[t]
|
32
|
150 |
\frametitle{Java vs Scala}
|
|
151 |
|
308
|
152 |
{\lstset{language=java,numbers=right}\fontsize{12}{12}\selectfont
|
32
|
153 |
\texttt{\lstinputlisting{Point.java}}}
|
|
154 |
|
308
|
155 |
\rule{11cm}{0.3mm}\\[-3mm]
|
33
|
156 |
|
32
|
157 |
{\lstset{language=scala}\fontsize{12}{12}\selectfont
|
|
158 |
\texttt{\lstinputlisting{Point.scala}}}
|
|
159 |
|
|
160 |
\begin{textblock}{6}(13,3)
|
|
161 |
\textbf{\large Java}
|
33
|
162 |
\end{textblock}
|
|
163 |
|
308
|
164 |
\begin{textblock}{6}(13,14.3)
|
32
|
165 |
\textbf{\large Scala}
|
|
166 |
\end{textblock}
|
|
167 |
|
|
168 |
\end{frame}
|
|
169 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
170 |
|
174
|
171 |
|
|
172 |
|
|
173 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
174 |
\begin{frame}[c]
|
137
|
175 |
\frametitle{First Steps: Scala Tools}
|
32
|
176 |
|
33
|
177 |
\begin{itemize}
|
308
|
178 |
\item contains a REPL
|
200
|
179 |
\item I use VS Code and a Scala extension (M'place)
|
199
|
180 |
\begin{center}
|
|
181 |
\includegraphics[scale=0.10]{../pics/vscode.png}\\[-10mm]\mbox{}
|
|
182 |
\end{center}\bigskip
|
|
183 |
|
33
|
184 |
\item there is a plugin for Eclipse (called Scala IDE)\medskip
|
137
|
185 |
\item there is also a plugin for IntelliJ\medskip
|
33
|
186 |
\end{itemize}
|
|
187 |
|
|
188 |
\end{frame}
|
137
|
189 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
190 |
|
|
191 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
309
|
192 |
\begin{frame}[t]
|
|
193 |
\frametitle{Why Scala?}
|
|
194 |
|
|
195 |
\onslide<2->{%
|
|
196 |
\begin{center}
|
|
197 |
{\large\bf{}Money?}\bigskip\\
|
|
198 |
\begin{tabular}{@{}c@{}c@{}}
|
|
199 |
\includegraphics[scale=0.2]{../pics/salary1.png} &
|
|
200 |
\includegraphics[scale=0.2]{../pics/salary2.png}\\
|
|
201 |
\multicolumn{2}{r@{}}{\footnotesize$^*$ source: Stackoverflow Developer Survey, 2019}
|
|
202 |
\end{tabular}
|
|
203 |
\end{center}
|
314
|
204 |
\RIGHTarrow{2}{2.4}{6.4}
|
|
205 |
\DOWNarrow{2}{10.1}{4.4}
|
309
|
206 |
}
|
|
207 |
|
|
208 |
|
|
209 |
\small
|
|
210 |
Elm, Rust, Haskell, Ocaml, F$\#$, Erlang, ML, Lisp (Racket)\ldots
|
|
211 |
|
|
212 |
\only<3>{
|
|
213 |
\begin{textblock}{6}(3.3,6.2)
|
|
214 |
\begin{bubble}[6.5cm]
|
|
215 |
\bf\huge\textcolor{RoyalBlue}{Functional Programming!}
|
|
216 |
\end{bubble}
|
|
217 |
\end{textblock}}
|
|
218 |
|
|
219 |
\end{frame}
|
|
220 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
221 |
|
|
222 |
|
|
223 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
137
|
224 |
\begin{frame}[c]
|
309
|
225 |
\frametitle{\begin{tabular}{c}\\[2mm]
|
|
226 |
Why Functional\\[-2mm] Programming?\end{tabular}
|
137
|
227 |
}
|
|
228 |
|
|
229 |
%
|
|
230 |
\mbox{}\\[3.5cm]
|
|
231 |
\small
|
309
|
232 |
Elm, Haskell, Ocaml, F$\#$, Erlang, ML, Lisp (Racket)\ldots
|
137
|
233 |
|
309
|
234 |
\only<2>{
|
|
235 |
\begin{textblock}{6}(1.3,6.2)
|
137
|
236 |
\begin{bubble}[10cm]
|
|
237 |
\normalsize``If you want to see which features will be in mainstream programming
|
|
238 |
languages tomorrow, then take a look at functional programming
|
|
239 |
languages today.''\medskip\small\\
|
|
240 |
\hfill{}---Simon Peyton Jones (works at Microsoft)\\
|
|
241 |
\hfill{}main developer of the Glasgow Haskell Compiler
|
|
242 |
\end{bubble}
|
|
243 |
\end{textblock}}
|
|
244 |
|
309
|
245 |
\only<3>{
|
200
|
246 |
\begin{textblock}{6}(5,5.8)
|
|
247 |
\hspace{2mm}\includegraphics[scale=0.06]{../pics/assign.jpg}\\[-1mm]
|
309
|
248 |
\Large\alert{\hspace{5mm}\textbf{Immutability}}
|
200
|
249 |
\end{textblock}}
|
|
250 |
|
|
251 |
|
137
|
252 |
\end{frame}
|
|
253 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
254 |
|
200
|
255 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
309
|
256 |
\begin{frame}[c]
|
|
257 |
|
|
258 |
\begin{center}
|
|
259 |
\includegraphics[scale=0.4]{../pics/pure.png}
|
|
260 |
\end{center}
|
|
261 |
|
|
262 |
\begin{textblock}{6}(9,14)
|
|
263 |
\tiny$^*$ from ``What pure functional programming is all about?''
|
|
264 |
\end{textblock}
|
|
265 |
\end{frame}
|
|
266 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
267 |
|
|
268 |
|
|
269 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
200
|
270 |
\begin{frame}[c, fragile]
|
|
271 |
|
|
272 |
{\Large Why bother? or\smallskip\\\hfill What is wrong with this?}\bigskip\bigskip
|
|
273 |
|
|
274 |
|
|
275 |
\begin{lstlisting}[language=C,numbers=none]
|
|
276 |
for (int i = 10; i < 20; i++) {
|
|
277 |
|
|
278 |
//...Do something interesting
|
|
279 |
// with i...
|
|
280 |
|
|
281 |
}
|
|
282 |
\end{lstlisting}
|
|
283 |
|
|
284 |
|
|
285 |
\end{frame}
|
|
286 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
287 |
|
|
288 |
|
|
289 |
|
137
|
290 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
291 |
\begin{frame}[c]
|
|
292 |
\mbox{}\\[-21mm]\mbox{}
|
|
293 |
|
|
294 |
\begin{center}
|
|
295 |
\begin{tikzpicture}[scale=1,
|
|
296 |
node/.style={
|
|
297 |
rectangle,rounded corners=3mm,
|
|
298 |
very thick,draw=black!50,
|
|
299 |
minimum height=18mm, minimum width=20mm,
|
|
300 |
top color=white,bottom color=black!20}]
|
|
301 |
|
|
302 |
\onslide<1-10>{
|
|
303 |
\node (A) at (0,0) [node]
|
|
304 |
{\mbox{\includegraphics[scale=0.15]{../pics/cplus2.jpg}}};
|
|
305 |
\node [above right] at (A.north west) {1986};}
|
|
306 |
|
|
307 |
\onslide<2->{
|
|
308 |
\node (B) at (3.5,0) [node]
|
|
309 |
{\mbox{\includegraphics[scale=0.15]{../pics/robotron.jpg}}};
|
|
310 |
\node [above right] at (B.north west) {1988, C};
|
|
311 |
\draw [->,line width=4mm] (A) -- (B);}
|
|
312 |
|
|
313 |
\onslide<3->{
|
|
314 |
\node (C0) at (6.3,0) {};
|
|
315 |
\node (C) at (8,0) [node]
|
|
316 |
{\mbox{\includegraphics[scale=0.15]{../pics/sun.jpg}}};
|
|
317 |
\node [above right] at (C.north west) {1992, {\small Linux}};
|
|
318 |
\draw [->,line width=4mm] (B) -- (C0);
|
|
319 |
\draw [->,line width=4mm] (C0) -- (C);}
|
|
320 |
|
|
321 |
\onslide<4->{
|
|
322 |
\node (D) at (8,-3.3) [node]
|
|
323 |
{\mbox{\includegraphics[scale=0.2]{../pics/gateway.jpg}}};
|
|
324 |
\draw [->,line width=4mm] (C) -- (D);
|
|
325 |
\node [below right] at (D.south west) {1996};}
|
|
326 |
|
|
327 |
\onslide<5->{
|
|
328 |
\node (E) at (4,-3.3) [node]
|
|
329 |
{\mbox{\includegraphics[scale=0.1]{../pics/appleg4.jpg}}};
|
|
330 |
\draw [->,line width=4mm] (D) -- (E);
|
|
331 |
\node [above right] at (E.north west) {2000};}
|
|
332 |
|
|
333 |
\onslide<6->{
|
|
334 |
\node (F0) at (1.5,-3.3) {};
|
|
335 |
\node (F1) at (1,-3.3) {};
|
|
336 |
\node (F) at (-0.9,-3.3) [node]
|
|
337 |
{\mbox{\includegraphics[scale=0.3]{../pics/appleair.png}}};
|
|
338 |
\draw [->,line width=4mm] (E) -- (F0);
|
|
339 |
\draw [->,line width=4mm] (F1) -- (F);
|
|
340 |
\node [above right] at (F.north west) {2012?};}
|
|
341 |
|
|
342 |
\onslide<7->{
|
|
343 |
\node (G) at (-0.9,-6.3) [node]
|
|
344 |
{\mbox{\includegraphics[scale=0.02]{../pics/applepro.jpg}}};
|
|
345 |
\draw [->,line width=4mm] (F) -- (G);
|
|
346 |
\node [right] at (G.west) {\hspace{22mm}2017};}
|
|
347 |
|
|
348 |
\end{tikzpicture}
|
|
349 |
\end{center}
|
|
350 |
|
|
351 |
|
|
352 |
\only<1>{%
|
|
353 |
\begin{textblock}{10}(2.5,5)
|
|
354 |
\includegraphics[scale=0.26]{../pics/cplus1.jpg}\\
|
|
355 |
\footnotesize 64K RAM, no HD, no monitor, lots of cables
|
|
356 |
\end{textblock}
|
|
357 |
\begin{textblock}{6}(10.9,4.5)
|
|
358 |
\includegraphics[scale=0.09]{../pics/mand1.png}
|
|
359 |
\includegraphics[scale=0.09]{../pics/mand2.png}
|
|
360 |
\end{textblock}
|
|
361 |
\begin{textblock}{6}(10.8,2.2)
|
|
362 |
\huge\bf 3 days
|
|
363 |
\end{textblock}
|
|
364 |
}
|
|
365 |
\only<8->{%
|
|
366 |
\begin{textblock}{8}(5.8,11.6)
|
|
367 |
\large\bf
|
|
368 |
\begin{tabular}{l@{}l}
|
|
369 |
1986:\, & no Internet\\
|
|
370 |
& no Amazon\\
|
|
371 |
& no FB, no mobiles,\ldots\\
|
|
372 |
\end{tabular}
|
|
373 |
\end{textblock}
|
|
374 |
}
|
|
375 |
\only<9>{
|
|
376 |
\begin{textblock}{1}(3,3)
|
|
377 |
\begin{bubble}[9cm]
|
|
378 |
\begin{tabular}{@{\hspace{8mm}}llll@{\hspace{8mm}}}
|
|
379 |
\\
|
200
|
380 |
\multicolumn{4}{c}{\alert{\bf Speedup by Moore's Law}}\medskip\\
|
137
|
381 |
\textbf{1986:} & 3 days & \textbf{1996:} & 135 mins\\
|
|
382 |
\textbf{1988:} & 1.5 days & \textbf{1998:} & 67 mins\\
|
|
383 |
\textbf{1990:} & 18 hs & \textbf{2000:} & 33 mins\\
|
|
384 |
\textbf{1992:} & 9 hs & \textbf{2002:} & 16 mins\\
|
|
385 |
\textbf{1994:} & 4.5 hs & \multicolumn{2}{c}{???}\\
|
|
386 |
\\
|
|
387 |
\end{tabular}
|
|
388 |
\small Every two years, computers got twice as powerful.
|
|
389 |
\end{bubble}
|
|
390 |
\end{textblock}}
|
|
391 |
|
|
392 |
\end{frame}
|
|
393 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
394 |
|
|
395 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
396 |
\begin{frame}[c]
|
200
|
397 |
\frametitle{Seq \;vs\; Par}
|
137
|
398 |
|
|
399 |
\begin{center}
|
|
400 |
\begin{tabular}[t]{@{}l@{}l@{}}
|
200
|
401 |
\includegraphics[scale=0.14]{../pics/mand4.png} & \hspace{4mm}
|
|
402 |
\raisebox{0mm}{\includegraphics[scale=0.14]{../pics/mand3.png}}\\
|
|
403 |
\hspace{6mm}\includegraphics[scale=0.5]{../pics/cpu2.png} &
|
|
404 |
\hspace{11mm}\includegraphics[scale=0.5]{../pics/cpu1.png}
|
137
|
405 |
\end{tabular}
|
|
406 |
\end{center}
|
|
407 |
|
|
408 |
\only<2>{
|
|
409 |
\begin{textblock}{5}(12,2)
|
|
410 |
\begin{bubble}[2.1cm]
|
|
411 |
\footnotesize{}in Java or C++\\
|
|
412 |
\includegraphics[scale=0.50]{../pics/skeleton.jpg}\\
|
|
413 |
\end{bubble}
|
|
414 |
\end{textblock}}
|
|
415 |
|
|
416 |
\only<3>{
|
200
|
417 |
\begin{textblock}{14.2}(1,13.5)
|
140
|
418 |
In FP: Once a variable is created, it is assigned a value and then
|
308
|
419 |
never changed again $\Rightarrow$ no synchronisation needed\smallskip\\
|
200
|
420 |
%%\small\textcolor{gray}{(Andrew's second favourite feature of C++)}
|
137
|
421 |
\end{textblock}}
|
|
422 |
|
|
423 |
\end{frame}
|
|
424 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
425 |
|
|
426 |
|
|
427 |
|
32
|
428 |
|
|
429 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
430 |
\begin{frame}[c]
|
23
|
431 |
\frametitle{Types}
|
|
432 |
|
|
433 |
\begin{itemize}
|
33
|
434 |
\item Base types\smallskip
|
23
|
435 |
|
33
|
436 |
\begin{tabular}{@{}l@{}}
|
23
|
437 |
\textcolor{codegreen}{\texttt{Int}},
|
|
438 |
\textcolor{codegreen}{\texttt{Long}},
|
|
439 |
\textcolor{codegreen}{\texttt{BigInt}},
|
|
440 |
\textcolor{codegreen}{\texttt{Float}},
|
|
441 |
\textcolor{codegreen}{\texttt{Double}}\\
|
|
442 |
\textcolor{codegreen}{\texttt{String}},
|
25
|
443 |
\textcolor{codegreen}{\texttt{Char}}\\
|
|
444 |
\textcolor{codegreen}{\texttt{Boolean}}
|
23
|
445 |
\end{tabular}
|
|
446 |
|
33
|
447 |
\item Compound types \smallskip
|
23
|
448 |
|
33
|
449 |
\begin{tabular}{@{}ll@{}}
|
23
|
450 |
\textcolor{codegreen}{\texttt{List[Int]}} & lists of Int's \\
|
|
451 |
\textcolor{codegreen}{\texttt{Set[Double]}} & sets of Double's \\
|
|
452 |
\textcolor{codegreen}{\texttt{(Int, String)}} & Int-String pair\\
|
|
453 |
\textcolor{codegreen}{\texttt{List[(BigInt, String)]}} &
|
|
454 |
lists of BigInt-String\\
|
|
455 |
& pairs\\
|
200
|
456 |
\textcolor{codegreen}{\texttt{List[List[Int]]}} & list of lists of Int's\\ \textcolor{codegreen}{\texttt{Option[Int]}} & options of Int's \\
|
23
|
457 |
\end{tabular}
|
|
458 |
|
|
459 |
\end{itemize}
|
|
460 |
|
|
461 |
\end{frame}
|
|
462 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
463 |
|
32
|
464 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
200
|
465 |
%\begin{frame}[c]
|
|
466 |
%\frametitle{An Http Request}
|
32
|
467 |
|
200
|
468 |
%\begin{textblock}{1}(2,5)
|
|
469 |
%\begin{tabular}{c}
|
|
470 |
%\includegraphics[scale=0.15]{../pics/servers.png}\\[-2mm]
|
|
471 |
%\small Server
|
|
472 |
%\end{tabular}
|
|
473 |
%\end{textblock}
|
32
|
474 |
|
200
|
475 |
%\begin{textblock}{1}(5.6,4)
|
|
476 |
% \begin{tikzpicture}[scale=1.1]
|
|
477 |
% \draw[white] (0,1) node (X) {};
|
|
478 |
% \draw[white] (2,1) node (Y) {};
|
|
479 |
% \draw[white] (0,0) node (X1) {};
|
|
480 |
% \draw[white] (2,0) node (Y1) {};
|
|
481 |
% \draw[white] (0,-1) node (X2) {};
|
|
482 |
% \draw[white] (2,-1) node (Y2) {};
|
|
483 |
% \draw[red, <-, line width = 2mm] (X) -- (Y);
|
|
484 |
% \node [inner sep=5pt,label=above:\textcolor{black}{GET request}] at ($ (X)!.5!(Y) $) {};
|
|
485 |
% \draw[red, ->, line width = 2mm] (X1) -- (Y1);
|
|
486 |
% \node [inner sep=5pt,label=above:\textcolor{black}{webpage}] at ($ (X1)!.5!(Y1) $) {};
|
|
487 |
% \draw[red, <-, line width = 2mm] (X2) -- (Y2);
|
|
488 |
% \node [inner sep=7pt,label=above:\textcolor{black}{POST data}] at ($ (X2)!.5!(Y2) $) {};
|
|
489 |
% \end{tikzpicture}
|
|
490 |
%\end{textblock}
|
32
|
491 |
|
|
492 |
|
200
|
493 |
%\begin{textblock}{1}(9,5.5)
|
|
494 |
%\begin{tabular}{c}
|
|
495 |
%\includegraphics[scale=0.15]{../pics/laptop.png}\\[-2mm]
|
|
496 |
%\small Browser
|
|
497 |
%\end{tabular}
|
|
498 |
%\end{textblock}
|
|
499 |
%\end{frame}
|
32
|
500 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
501 |
|
|
502 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
200
|
503 |
%\begin{frame}[c]
|
|
504 |
%
|
|
505 |
%{\lstset{language=Java}\fontsize{7}{8}\selectfont
|
|
506 |
%\texttt{\lstinputlisting{URLReader.java}}}
|
|
507 |
%
|
|
508 |
%\end{frame}
|
32
|
509 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
510 |
|
33
|
511 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
512 |
\begin{frame}[c]
|
309
|
513 |
\frametitle{Coursework Dates}
|
|
514 |
|
|
515 |
Similar to C++:\bigskip
|
|
516 |
|
|
517 |
\begin{itemize}
|
|
518 |
\item Preliminary Parts: Wednesdays 4pm
|
|
519 |
\begin{itemize}
|
|
520 |
\item Preliminary Part 6: 3\% (13 November)
|
|
521 |
\item Preliminary Part 7: 4\% (20 November)
|
|
522 |
\item Preliminary Part 8: 4\% (27 November)
|
|
523 |
\item Preliminary Part 9: 4\% (5 December)
|
|
524 |
\end{itemize}\medskip
|
314
|
525 |
\item Core Part: 35\% (15 January 2020)\bigskip
|
309
|
526 |
\end{itemize}
|
|
527 |
\end{frame}
|
|
528 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
529 |
|
|
530 |
|
|
531 |
|
|
532 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
533 |
\begin{frame}[c]
|
140
|
534 |
\frametitle{Coursework}
|
|
535 |
|
|
536 |
\begin{itemize}
|
200
|
537 |
\item Sorry, I might have been a bit wordy:\\
|
308
|
538 |
Part 6 of CW description is 7 pages, but
|
|
539 |
I only needed \mbox{< 100} loc for \emph{all} Part 6.\bigskip
|
140
|
540 |
|
308
|
541 |
\item there is feedback when pushing code to github\medskip
|
140
|
542 |
|
309
|
543 |
\item there are \texttt{jar}-files you can use to test
|
|
544 |
my reference implementation\bigskip
|
200
|
545 |
|
309
|
546 |
\item we want you to learn FP!\smallskip\\ \alert{\bf no vars}, no mutable
|
|
547 |
data-structures\\ \quad{}e.g.~no \texttt{Arrays}, no \texttt{ListBuffer}
|
140
|
548 |
\end{itemize}
|
309
|
549 |
|
|
550 |
\LEFTarrow{1}{11}{11.8}
|
140
|
551 |
\end{frame}
|
|
552 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
553 |
|
|
554 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
555 |
|
|
556 |
\begin{frame}[c, fragile]
|
|
557 |
\frametitle{The Joy of Immutability}
|
|
558 |
|
|
559 |
\begin{itemize}
|
|
560 |
\item If you need to manipulate some data in a list say, then you make
|
|
561 |
a new list with the updated values, rather than revise the original
|
|
562 |
list. Easy!\medskip
|
|
563 |
|
|
564 |
{\small
|
|
565 |
\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
|
|
566 |
val old_list = List(1, 2, 3, 5)
|
|
567 |
val new_list = 0 :: old_list
|
308
|
568 |
// -> List(0, 1, 2, 3, 4, 5)
|
140
|
569 |
\end{lstlisting}}
|
|
570 |
|
200
|
571 |
\item You do not have to be defensive about who can access the data.
|
|
572 |
|
|
573 |
\item You can look at your code in isolation.
|
140
|
574 |
\end{itemize}
|
|
575 |
\end{frame}
|
|
576 |
|
|
577 |
|
|
578 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
579 |
|
|
580 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
581 |
\begin{frame}[t]
|
|
582 |
\frametitle{Email: Hate 'val'}
|
|
583 |
|
308
|
584 |
\mbox{}\\[-23mm]\mbox{}
|
140
|
585 |
|
|
586 |
\begin{center}
|
|
587 |
\begin{bubble}[10.5cm]
|
|
588 |
Subject: \textbf{Hate '\textbf{\texttt{val}}'}\hfill 01:00 AM\medskip\\
|
|
589 |
|
|
590 |
Hello Mr Urban,\medskip\\
|
|
591 |
|
|
592 |
I just wanted to ask, how are we suppose to work
|
|
593 |
with the completely useless \textbf{\texttt{val}}, that can’t be changed ever? Why is
|
|
594 |
this rule active at all? I’ve spent 4 hours not thinking on the
|
|
595 |
coursework, but how to bypass this annoying rule. What’s the whole
|
|
596 |
point of all these coursework, when we can’t use everything Scala
|
|
597 |
gives us?!?\medskip\\
|
|
598 |
|
|
599 |
Regards.\\
|
|
600 |
\mbox{}\hspace{5mm}\textcolor{black!50}{<<deleted>>}\\
|
|
601 |
\end{bubble}
|
|
602 |
\end{center}
|
|
603 |
|
|
604 |
\end{frame}
|
|
605 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
606 |
|
|
607 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
608 |
\begin{frame}[c]
|
|
609 |
|
|
610 |
\mbox{}\\[-25mm]\mbox{}
|
|
611 |
|
|
612 |
\begin{center}
|
|
613 |
\begin{bubble}[10.5cm]
|
|
614 |
Subject: \textbf{Re: Hate '\textbf{\texttt{val}}'}\hfill 01:02 AM\bigskip\bigskip\\
|
|
615 |
|
|
616 |
\textcolor{black!70}{
|
|
617 |
\textit{\large<<my usual rant about fp\ldots\\ concurrency bla bla\ldots{} better programs
|
|
618 |
yada>>}}\bigskip\bigskip\bigskip
|
|
619 |
|
|
620 |
PS: What are you trying to do where you desperately want to use \texttt{var}?
|
|
621 |
\end{bubble}
|
|
622 |
\end{center}
|
|
623 |
|
|
624 |
\end{frame}
|
|
625 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
626 |
|
|
627 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
628 |
\begin{frame}[c,fragile]
|
|
629 |
|
|
630 |
\begin{textblock}{6}(0.5,0.5)
|
|
631 |
\begin{bubble}[11.5cm]
|
|
632 |
\small
|
|
633 |
Subject: \textbf{Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:04 AM\medskip\\
|
|
634 |
|
|
635 |
\textbf{Right now my is\_legal function works fine:}
|
|
636 |
|
|
637 |
\footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
|
|
638 |
def is_legal(dim: Int, path: Path)(x: Pos): Boolean = {
|
|
639 |
var boolReturn = false
|
|
640 |
if(x._1 > dim || x._2 > dim || x._1 < 0 || x._2 < 0) {
|
|
641 |
else { var breakLoop = false
|
|
642 |
if(path == Nil) { boolReturn = true }
|
|
643 |
else { for(i <- 0 until path.length) {
|
|
644 |
if(breakLoop == false) {
|
|
645 |
if(path(i) == x) {
|
|
646 |
boolReturn = true
|
|
647 |
breakLoop = true
|
|
648 |
}
|
|
649 |
else { boolReturn = false }
|
|
650 |
} else breakLoop
|
|
651 |
}
|
|
652 |
}
|
|
653 |
boolReturn
|
|
654 |
}
|
|
655 |
\end{lstlisting}
|
|
656 |
\end{bubble}
|
|
657 |
\end{textblock}
|
|
658 |
|
|
659 |
\begin{textblock}{6}(8.2,11.8)
|
|
660 |
\begin{bubble}[5.5cm]\footnotesize\bf
|
|
661 |
\ldots{}but I can’t make it work with boolReturn being val. What approach would
|
|
662 |
you recommend in this case, and is using var in this case justified?
|
|
663 |
\end{bubble}
|
|
664 |
\end{textblock}
|
|
665 |
|
|
666 |
\only<2>{
|
|
667 |
\begin{textblock}{6}(0.3,11.8)
|
|
668 |
\begin{bubble}[3.1cm]
|
|
669 |
\textbf{Me:}
|
|
670 |
\raisebox{-12mm}{\includegraphics[scale=0.08]{../pics/throwup.jpg}}
|
|
671 |
\end{bubble}
|
|
672 |
\end{textblock}}
|
|
673 |
|
|
674 |
\end{frame}
|
|
675 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
676 |
|
|
677 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
678 |
\begin{frame}[t,fragile]
|
|
679 |
|
|
680 |
\mbox{}\\[-25mm]\mbox{}
|
|
681 |
|
|
682 |
\begin{textblock}{6}(0.5,2)
|
|
683 |
\begin{bubble}[11.5cm]
|
|
684 |
Subject: \textbf{Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:06 AM\bigskip\\
|
|
685 |
\small
|
|
686 |
|
|
687 |
OK. So you want to make sure that the \texttt{x}-position is not outside the
|
|
688 |
board....and furthermore you want to make sure that the \texttt{x}-position
|
|
689 |
is not yet in the path list. How about something like\bigskip
|
|
690 |
|
|
691 |
\footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
|
|
692 |
def is_legal(dim: Int, path: Path)(x: Pos): Boolean =
|
|
693 |
...<<some board conditions>>... && !path.contains(x)
|
|
694 |
\end{lstlisting}\bigskip
|
|
695 |
|
|
696 |
\small Does not even contain a \texttt{val}.
|
|
697 |
\end{bubble}
|
|
698 |
\end{textblock}
|
|
699 |
|
|
700 |
\begin{textblock}{6}(7,12)
|
|
701 |
\footnotesize\textcolor{black!50}{(This is all on one line)}
|
|
702 |
\end{textblock}
|
|
703 |
|
|
704 |
\end{frame}
|
|
705 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
706 |
|
|
707 |
|
|
708 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
709 |
\begin{frame}[t,fragile]
|
|
710 |
|
|
711 |
\mbox{}\\[-15mm]\mbox{}
|
|
712 |
|
|
713 |
\begin{textblock}{6}(1,3)
|
|
714 |
\begin{bubble}[10.5cm]
|
|
715 |
Subject: \textbf{Re: Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 11:02 AM\bigskip\bigskip\\
|
|
716 |
|
|
717 |
THANK YOU! You made me change my coding perspective. Because of you,
|
|
718 |
I figured out the next one\ldots
|
|
719 |
\end{bubble}
|
|
720 |
\end{textblock}
|
|
721 |
|
|
722 |
\only<2>{
|
|
723 |
\begin{textblock}{6}(0.3,11.8)
|
|
724 |
\begin{bubble}[3.1cm]
|
|
725 |
\textbf{Me:}
|
|
726 |
\raisebox{-12mm}{\includegraphics[scale=0.15]{../pics/happy.jpg}}
|
|
727 |
\end{bubble}
|
|
728 |
\end{textblock}}
|
|
729 |
|
|
730 |
\end{frame}
|
|
731 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
732 |
|
|
733 |
|
|
734 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
735 |
\begin{frame}[c]
|
309
|
736 |
\frametitle{Conclusion for Today}
|
33
|
737 |
|
|
738 |
\begin{itemize}
|
309
|
739 |
\item Scala is still under development, 2.13.1 came out in Sept.\\
|
|
740 |
(the compiler is terribly slow)\medskip
|
33
|
741 |
\item {\bf\url{http://www.scala-lang.org/}}\bigskip
|
140
|
742 |
|
|
743 |
\item it is a rather \textbf{\alert{deep}} language\ldots i.e.~gives
|
|
744 |
you a lot of rope to shoot yourself\bigskip
|
33
|
745 |
|
140
|
746 |
\item learning functional programming is not easy\ldots{}when you have
|
200
|
747 |
spent all of your career thinking in an imperative way, it is hard to
|
140
|
748 |
change\bigskip\medskip
|
|
749 |
|
200
|
750 |
\item hope you have fun with Scala and the assignments
|
33
|
751 |
\end{itemize}
|
|
752 |
\end{frame}
|
|
753 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
754 |
|
|
755 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
756 |
\begin{frame}[c]
|
140
|
757 |
\frametitle{\begin{tabular}{c}\\[0cm]\alert{Questions?}\end{tabular}}
|
33
|
758 |
|
140
|
759 |
\begin{center}
|
|
760 |
\begin{tabular}[t]{@{}l@{}l@{}}
|
200
|
761 |
\includegraphics[scale=0.1]{../pics/mand4.png} & \hspace{4mm}
|
|
762 |
\raisebox{0mm}{\includegraphics[scale=0.1]{../pics/mand3.png}}
|
140
|
763 |
\end{tabular}
|
|
764 |
\end{center}
|
|
765 |
|
|
766 |
\begin{center}
|
308
|
767 |
My Office Hours: Thursdays 12 -- 14\\
|
309
|
768 |
And specifically for Scala: Tuesdays 10:45 -- 11:45
|
140
|
769 |
\end{center}
|
33
|
770 |
\end{frame}
|
|
771 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
314
|
772 |
|
|
773 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
774 |
\begin{frame}[t]
|
|
775 |
|
|
776 |
\begin{center}
|
|
777 |
\includegraphics[scale=0.4]{../pics/blow.png}
|
|
778 |
\end{center}
|
|
779 |
|
|
780 |
\begin{textblock}{14}(2,12.4)
|
|
781 |
\Large\bf{}Mind-Blowing\\ Programming Languages: C/C++
|
|
782 |
\end{textblock}
|
|
783 |
\end{frame}
|
|
784 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
785 |
|
|
786 |
|
32
|
787 |
|
|
788 |
|
22
|
789 |
\end{document}
|
|
790 |
|
|
791 |
%%% Local Variables:
|
|
792 |
%%% mode: latex
|
|
793 |
%%% TeX-master: t
|
|
794 |
%%% End:
|
|
795 |
|
140
|
796 |
|
|
797 |
“Functional programming is often regarded as the best-kept secret of
|
|
798 |
scientific modelers, mathematicians, artificial intelligence
|
|
799 |
researchers, financial institutions, graphic designers, CPU designers,
|
|
800 |
compiler programmers, and telecommunications engineers.”
|
|
801 |
|
|
802 |
The Wikipedia F# page |