-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.tex
72 lines (66 loc) · 1.42 KB
/
example.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
\begin{frame}
\begin{block}{Let's start at a concrete example}
How do I sum the integer values in a list?
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Using a for loop}
\begin{lstlisting}[style=java]
sum(list) {
var r = 0;
for(int i = 0; i < list.length; i++) {
r = r + list[i];
}
return r;
}
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Using a for loop}
\begin{lstlisting}[style=java]
sum(list) {
var r = 0;
for(int i = 0; i < list.length; `i++`) {
`r = r + list[i]`;
}
return r;
}
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}
\begin{center}
Here is another way of looking at the problem
\end{center}
\end{frame}
\begin{frame}
\begin{block}{The sum of a list is \ldots}
\begin{itemize}
\item if the list is empty, return \lstinline{0}
\item otherwise add the first element to the sum of the remainder of the list
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{The sum of a list is \ldots}
\begin{lstlisting}
sum([6, 5, 9, 71, 3]) =
6 + sum (5, 9, 71, 3]) =
6 + 5 + sum([9, 71, 3]) =
6 + 5 + 9 + sum([71, 3]) =
6 + 5 + 9 + 71 + sum([3]) =
6 + 5 + 9 + 71 + 3 + sum([]) =
6 + 5 + 9 + 71 + 3 + 0 =
94
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{Here is the Haskell source code}
\begin{lstlisting}[style=haskell]
sum [] = 0
sum (first:rest) = first + sum rest
\end{lstlisting}
\end{block}
\end{frame}