Browse Source

Initial commit

Julian Ospald 4 years ago
commit
eaf0f3d92e
No account linked to committer's email address
2 changed files with 138 additions and 0 deletions
  1. 138
    0
      VL1.tex
  2. BIN
      function-machine.png

+ 138
- 0
VL1.tex View File

@@ -0,0 +1,138 @@
1
+\documentclass[10pt,a5paper,mathserif,serif,usenames,dvipsnames]{beamer}
2
+
3
+% packages
4
+\usepackage{xcolor}
5
+\usepackage[utf8]{inputenc}
6
+\usepackage{amsmath}
7
+\usepackage{amsfonts}
8
+\usepackage{amssymb}
9
+\usepackage{graphicx}
10
+\usepackage{listings}
11
+
12
+% package configuration
13
+\DeclareGraphicsExtensions{.pdf,.png,.jpg}
14
+
15
+% title page information
16
+\author{Julian Ospald}
17
+\institute{FH Bielefeld}
18
+\title{Haskell: introduction}
19
+
20
+% color definition
21
+\definecolor{solarized}{HTML}{002B36}
22
+
23
+\begin{document}
24
+
25
+% page 0
26
+\frame{\titlepage}
27
+
28
+% page 1
29
+\begin{frame}
30
+\frametitle{Why haskell?}
31
+A Haskeller might claim: haskell...
32
+\begin{itemize}
33
+\item eliminates certain classes of bugs
34
+\item makes it easy to reason about code
35
+\item decreases the bus-factor
36
+\item makes it possible to apply huge changes to large programs without worrying about the implicit state machine
37
+\item makes it easier to program complex problems
38
+\item allows for clean APIs, even without any OOP
39
+\item a haskell program of 10K LOC isn't that much different to maintain as a 100K LOC
40
+\end{itemize}
41
+\vspace{\baselineskip}
42
+We'll have to see if this holds true.
43
+\end{frame}
44
+
45
+% page 1
46
+\begin{frame}[fragile]
47
+\frametitle{Why haskell? (ctn.)}
48
+From C++ std:
49
+\lstset{
50
+	language=C++,
51
+	backgroundcolor=\color{White},
52
+	frame=single,
53
+	keepspaces=true
54
+}
55
+\begin{lstlisting}
56
+void pop();
57
+\end{lstlisting}
58
+\lstset{
59
+	language=C,
60
+}
61
+From the C FLINT library:
62
+\begin{lstlisting}
63
+void fmpz_mod_poly_add(
64
+    fmpz_mod_poly_t res,
65
+    const fmpz_mod_poly_t poly1,
66
+    const fmpz_mod_poly_t poly2);
67
+\end{lstlisting}
68
+\vspace{\baselineskip}
69
+Regular C functions in real-world (omitting examples on purpose):
70
+\begin{itemize}
71
+\item 100+ LOC
72
+\item at least 7 ifs, 4 whiles, 12 variables, 1 goto
73
+\item access both static and global variables
74
+\item indenting level of 5 or more
75
+\item a lot of memory management and custom-made error handling
76
+\end{itemize}
77
+\end{frame}
78
+
79
+\begin{frame}
80
+\frametitle{Why haskell? (ctn.)}
81
+You need to change only one single line in such a C function. You have to know:
82
+\begin{itemize}
83
+\item does the order of function calls matter?
84
+\item how does the change effect the memory management? Do we have memory leaks? Do we access invalid memory?
85
+\item does it change the state of static or global variables?
86
+\item does it implicitly change the state of out-parameters?
87
+\item if it changes any of those states, is the function still correct?
88
+\item does the program flow break? Do we have unreachable codepaths now?
89
+\item did you just nuke a small former Soviet state?
90
+\end{itemize}
91
+\end{frame}
92
+
93
+\begin{frame}
94
+\frametitle{Why haskell? (ctn.)}
95
+But java helps! Does it?
96
+Sort of, because:
97
+\begin{itemize}
98
+\item it improves APIs compared to C, since you can hide information in the state of an object (but... it's hidden now)
99
+\item it has a garbage collector, so you don't need to worry too much about memory... unless it doesn't work OOTB anymore
100
+\end{itemize}
101
+Unfortunately, we:
102
+\begin{itemize}
103
+\item now got even more states to keep track of (intellectual complexity?)
104
+\item have clouded the program flow... it's now about object-interaction with their implicit states
105
+\item still have \textbf{side effects} everywhere: one object changes the state of another and vice versa, may arbitrarily write to the hard drive, do kernel calls or launch a missle
106
+\end{itemize}
107
+Some parts of the implicit state machine have been made explicit by modelling classes, but it's still there and we have to deal with it, because we are modelling everything around states. Wouldn't it be nice if we could just forget about the global state machine? Maybe there is even a way to remove side effects and have more "predictability"? We are lucky. There is. It's called \textbf{Haskell}.
108
+\end{frame}
109
+
110
+% page 2
111
+\begin{frame}
112
+\frametitle{What is haskell?}
113
+Haskell is a \textbf{functional}, \textbf{pure}, \textbf{lazy} and \textbf{statically typed} high-level programming language.
114
+\end{frame}
115
+
116
+% page3
117
+\begin{frame}
118
+\frametitle{What does \textbf{functional} mean?}
119
+Think of haskell functions as regular \emph{mathematical} functions.
120
+\vspace{\baselineskip}
121
+\includegraphics*[scale=0.4]{function-machine.png}
122
+\begin{itemize}
123
+\item does this function write to the hard drive?
124
+\item does the output depend on anything else except the input (e.g. time, environment, ...)?
125
+\end{itemize}
126
+\end{frame}
127
+
128
+% page4
129
+\begin{frame}
130
+\frametitle{What does \textbf{functional} mean? (ctn.)}
131
+\begin{itemize}
132
+\item \emph{first-class} citizens: functions are values
133
+\item a haskell program is what happens when \emph{expressions are evaluated}
134
+\end{itemize}
135
+\end{frame}
136
+
137
+
138
+\end{document}

BIN
function-machine.png View File