-
Notifications
You must be signed in to change notification settings - Fork 2
/
introduction.tex
157 lines (128 loc) · 2.99 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
154
155
156
157
\begin{frame}
\begin{center}
Let us remind ourselves.
\end{center}
\begin{center}
What is Functional Programming? What does it \emph{mean}?
\end{center}
\end{frame}
\begin{frame}[fragile]
\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]
\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]
\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;
}
int r = `wibble(x, y);`
/* arbitrary code */
blobble(`r`, `r`);
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{center}
Did the program just change?
\end{center}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Yes, the program changed \ldots}
\begin{lstlisting}[style=java]
int wibble(int a, int b) {
`counter = counter + 1;`
return (a + b) * 2;
}
int r = wibble(x, y);
/* arbitrary code */
blobble(r, r);
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\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]
\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]
\begin{block}{assign the expression to a value}
\begin{lstlisting}[style=java]
int pibble(int a, int b) {
return (a + b) * 2;
}
int r = `pibble(x, y);`
/* arbitrary code */
globble(`r`, `r`);
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}
\begin{center}
This time, did the program just change?
\end{center}
\end{frame}
\begin{frame}
\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}
\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}
\tiny{This property of expressions is called \emph{referential transparency}.}
\end{center}
\end{frame}
\begin{frame}
\begin{block}{Consequences}
A commitment to Functional Programming has many consequences.
\end{block}
\end{frame}
\begin{frame}
\begin{center}
One of the most important and practical of those is
\end{center}
\begin{center}
\textbf{Parametricity}
\end{center}
\end{frame}