-
Notifications
You must be signed in to change notification settings - Fork 0
/
introduction.tex
153 lines (125 loc) · 3.1 KB
/
introduction.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
\begin{frame}
\begin{center}
What is Functional Programming?
\end{center}
\begin{center}
What does it \emph{mean}?
\end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{What is Functional Programming?}
\begin{block}{Suppose the following program \ldots}
\begin{lstlisting}[style=java]
int wibble(int a, int b) {
counter = counter + 1;
return (a + b) * 2;
}
/* arbitrary code */
blobble(wibble(x, y), wibble(x, y));
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{What is Functional Programming?}
\begin{block}{and we refactor out these common expressions \ldots}
\begin{lstlisting}[style=java]
int wibble(int a, int b) {
counter = counter + 1;
return (a + b) * 2;
}
/* arbitrary code */
blobble(`wibble(x, y)`, `wibble(x, y)`);
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{What is Functional Programming?}
\begin{block}{assign the expression to a value}
\begin{lstlisting}[style=java]
int wibble(int a, int b) {
counter = counter + 1;
return (a + b) * 2;
}
/* arbitrary code */
int r = `wibble(x, y);`
blobble(`r`, `r`);
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{What is Functional Programming?}
\begin{center}
Did the program just change?
\end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{What is Functional Programming?}
\begin{block}{Yes, the program changed \ldots}
\begin{lstlisting}[style=java]
int wibble(int a, int b) {
`counter = counter + 1;`
return (a + b) * 2;
}
/* arbitrary code */
int r = wibble(x, y);
blobble(r, r);
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{What is Functional Programming?}
\begin{block}{Suppose this slightly different program \ldots}
\begin{lstlisting}[style=java]
int pibble(int a, int b) {
return (a + b) * 2;
}
/* arbitrary code */
globble(pibble(x, y), pibble(x, y));
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{What is Functional Programming?}
\begin{block}{and we refactor out these common expressions \ldots}
\begin{lstlisting}[style=java]
int pibble(int a, int b) {
return (a + b) * 2;
}
/* arbitrary code */
globble(`pibble(x, y)`, `pibble(x, y)`);
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{What is Functional Programming?}
\begin{block}{assign the expression to a value}
\begin{lstlisting}[style=java]
int pibble(int a, int b) {
return (a + b) * 2;
}
/* arbitrary code */
int r = `pibble(x, y);`
globble(`r`, `r`);
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}
\frametitle{What is Functional Programming?}
\begin{center}
This time, did the program just change?
\end{center}
\end{frame}
\begin{frame}
\frametitle{What is Functional Programming?}
\begin{block}{It's the same program}
For given inputs, the same outputs are given, with no observable changes to the program
\end{block}
\end{frame}
\begin{frame}
\frametitle{What is Functional Programming?}
\begin{block}{Functional Programming is the idea that}
We can \textbf{always replace expressions with a value, without affecting the program behaviour}
\end{block}
\begin{center}
\end{center}
\end{frame}