Procházet zdrojové kódy

Add TOC and sections

stripped-german
Julian Ospald před 9 roky
rodič
revize
b76d88090b
V databázi nebyl nalezen žádný známý klíč pro tento podpis ID GPG klíče: 220CD1C5BDEED020
1 změnil soubory, kde provedl 87 přidání a 38 odebrání
  1. +87
    -38
      VL1.tex

+ 87
- 38
VL1.tex Zobrazit soubor

@@ -64,8 +64,15 @@

\frame{\titlepage}

\begin{frame}[allowframebreaks=0.8]
\frametitle{Table of Contents}
\tableofcontents
\end{frame}

\section{1. Why haskell?}

\begin{frame}
\frametitle{Why haskell?}
\frametitle{1. Why haskell?}
A Haskeller might claim: haskell...
\begin{itemize}[<+->]
\item eliminates certain classes of bugs
@@ -84,7 +91,7 @@ We'll have to see if this holds true.
\end{frame}

\begin{frame}[fragile]
\frametitle{Why haskell? (ctn.)}
\frametitle{1. Why haskell? (ctn.)}
From C++ std:
\setCppCodeStyle
\begin{lstlisting}
@@ -113,7 +120,7 @@ Regular C functions in real-world (omitting examples on purpose):
\end{frame}

\begin{frame}
\frametitle{Why haskell? (ctn.)}
\frametitle{1. Why haskell? (ctn.)}
You need to change only one single line in such a C function. You have to know:
\begin{itemize}[<+->]
\item does the order of function calls matter?
@@ -130,7 +137,7 @@ Conclusion: you really need to understand the complete environment of that line/
\end{frame}

\begin{frame}
\frametitle{Why haskell? (ctn.)}
\frametitle{1. Why haskell? (ctn.)}
But java helps! Does it?
Sort of, because:
\begin{itemize}[<+->]
@@ -141,7 +148,7 @@ Sort of, because:
\end{frame}

\begin{frame}
\frametitle{Why haskell? (ctn.)}
\frametitle{1. Why haskell? (ctn.)}
Unfortunately, with java we:
\begin{itemize}[<+->]
\item now got even more states to keep track of (intellectual complexity?)
@@ -156,16 +163,20 @@ Some parts of the implicit state machine have been made explicit by modelling cl
We are lucky. There is. It's called \textbf{Haskell}.
\end{frame}

\section{2. What is haskell?}

\begin{frame}
\frametitle{What is haskell?}
\frametitle{2. What is haskell?}
Haskell is a \textbf{functional}, \textbf{pure}, \textbf{lazy} and \textbf{statically typed} high-level programming language.\\
\onslide<+->
\vspace{\baselineskip}
A few of the following facts will be white lies. But let's not worry about that. It's maybe more about "how to think in terms of haskell?" than "what is haskell?".
\end{frame}

\subsection{2.1. What does functional mean?}

\begin{frame}
\frametitle{What does \textbf{functional} mean?}
\frametitle{2.1. What does \textbf{functional} mean?}
Think of haskell functions as regular \emph{mathematical} functions.
\onslide<+->
\vspace{\baselineskip}
@@ -180,15 +191,17 @@ It's all about \emph{input} and \emph{output} of functions! And that's it. Nothi
\end{frame}

\begin{frame}
\frametitle{What does \textbf{functional} mean? (ctn.)}
\frametitle{2.1. What does \textbf{functional} mean? (ctn.)}
\begin{itemize}[<+->]
\item \emph{first-class} citizens: functions are values and can be used as such
\item a haskell program is what happens when \emph{expressions are evaluated}, it's not about executing instructions
\end{itemize}
\end{frame}

\subsection{2.2. What does pure mean?}

\begin{frame}
\frametitle{What does \textbf{pure} mean?}
\frametitle{2.2. What does \textbf{pure} mean?}
\emph{Referential transparency}, as in:
\onslide<+->
\begin{itemize}[<+->]
@@ -210,8 +223,10 @@ possible benefits?
Question: call-by-value? call-by-reference? call-by-need?
\end{frame}

\subsection{2.3. What does lazy mean?}

\begin{frame}
\frametitle{What does \textbf{lazy} mean?}
\frametitle{2.3. What does \textbf{lazy} mean?}
In haskell expressions are not evaluated until their results are actually needed. That has a lot of consequences, a few of them being:
\onslide<+->
\begin{itemize}[<+->]
@@ -221,15 +236,19 @@ In haskell expressions are not evaluated until their results are actually needed
\end{itemize}
\end{frame}

\subsection{2.4. What does statically typed mean?}

\begin{frame}
\frametitle{What does \textbf{statically typed} mean?}
\frametitle{2.4. What does \textbf{statically typed} mean?}
Every haskell expression has a type and types are always checked at \emph{compile-time}. Programs with errors will not compile and definitely not run.\\
\vspace{\baselineskip}
It is possible to simulate dynamic types however, i.e. types which may be converted to the type you need them in, following rigid rules. In the end, they are still statically type-checked (as in: the compiler always knows what's going on).
\end{frame}

\subsection{2.5. Summary}

\begin{frame}
\frametitle{What is haskell again?}
\frametitle{2.5. What is haskell again?}
Let's reiterate. Haskell is:
\begin{itemize}
\item functional
@@ -241,8 +260,10 @@ Let's reiterate. Haskell is:
\end{itemize}
\end{frame}

\section{3. How to think haskell?}

\begin{frame}
\frametitle{How to think haskell?}
\frametitle{3. How to think haskell?}
\begin{itemize}[<+->]
\item forget about imperative, procedural, OOP; forget about any programming language
\item think in types!
@@ -262,8 +283,10 @@ Let's reiterate. Haskell is:
\end{itemize}
\end{frame}

\section{4. Declarations}

\begin{frame}[fragile]
\frametitle{Declarations}
\frametitle{4. Declarations}
Let's go!
\setHaskellCodeStyle
\begin{lstlisting}
@@ -288,8 +311,10 @@ s = "Hello, world?"
\end{lstlisting}
\end{frame}

\section{5. Arithmetic and co.}

\begin{frame}[fragile]
\frametitle{Arithmetic and co.}
\frametitle{5. Arithmetic and co.}
\setHaskellCodeStyle
GHCi:
\begin{lstlisting}
@@ -302,8 +327,10 @@ GHCi:
\end{lstlisting}
\end{frame}

\section{6. Functions and control structures}

\begin{frame}[fragile]
\frametitle{Functions and control structures}
\frametitle{6. Functions and control structures}
\setHaskellCodeStyle
Let's make our first function. We want something like the following mathematical function\\
$f(x) = x * x$\\
@@ -327,7 +354,7 @@ So the function gets an Int and returns an Int. Don't get confused by "\verb|->|
\end{frame}

\begin{frame}[fragile]
\frametitle{Functions and control structures (ctn.)}
\frametitle{6. Functions and control structures (ctn.)}
In haskell we often use \textbf{pattern matching}. That means we define a function multiple times, but e.g. for different values of its input arguments. Let's see:
\pause
\setHaskellCodeStyle
@@ -344,7 +371,7 @@ What might happen if we remove the second or the third line? What is a \textbf{p
\end{frame}

\begin{frame}[fragile]
\frametitle{Functions and control structures (ctn.)}
\frametitle{6. Functions and control structures (ctn.)}
How about \emph{recursion}? Let's define the modulo of any \emph{Int} to \emph{2}.
\pause
\setHaskellCodeStyle
@@ -359,8 +386,10 @@ mod2 x
These \verb#|# things above are called \textbf{guards} and are similar to \emph{pattern matching}. They are processed in order. If the condition on the left side of the equation is true, then it returns what stands on the right side of the equation. If it's false, then it processes the next line.\\ \code{otherwise} on the last line is just defined as \code{True}, to make these constructs easier to read and catch all other cases of input.
\end{frame}

\section{7. Pairs/Tuples}

\begin{frame}[fragile]
\frametitle{Pairs/Tuples}
\frametitle{7. Pairs/Tuples}
Defining a pair is easy.
\setHaskellCodeStyle
\begin{lstlisting}
@@ -375,8 +404,10 @@ sumPair (x, y) = x + y
Note: we use \code{(x, y)} notation for both the type and the definition! Those are still two different things. We can also have triples, quadruples etc.
\end{frame}

\section{8. Lists}

\begin{frame}[fragile]
\frametitle{Lists}
\frametitle{8. Lists}
\setHaskellCodeStyle
The list is probably the most basic data structure in Haskell. Like the array in C. It is a singly-linked list and is very lazy. The compiler has numerous ways to optimize lists, so don't be afraid to use them, even for huge things.
\pause
@@ -403,7 +434,7 @@ infiniteList = [1..]
\end{frame}

\begin{frame}[fragile]
\frametitle{Lists (ctn.)}
\frametitle{8. Lists (ctn.)}
Let's check on a few very common list operations:
\setHaskellCodeStyle
\begin{lstlisting}
@@ -428,7 +459,7 @@ A String in haskell is just a list of Chars!
\end{frame}

\begin{frame}[fragile]
\frametitle{Lists (ctn.)}
\frametitle{8. Lists (ctn.)}
Again, we can do pattern matching on lists.
\setHaskellCodeStyle
\begin{lstlisting}
@@ -448,7 +479,7 @@ Note that \code{(x:(y:zs))} may also be written as \code{(x:y:zs)}.
\end{frame}

\begin{frame}[fragile]
\frametitle{Lists (ctn.)}
\frametitle{8. Lists (ctn.)}
Haskell also supports \textbf{list comprehension} which is basically syntactic sugar for what we already know from maths.\\
Let's define a set that contains the first ten even natural numbers:\\
\pause
@@ -471,8 +502,10 @@ Now let's say we want all numbers between 50 and 100 that have the remainder 0 w
\code{x <- [50..100]} is the binding, while \code{mod x 12 == 0} is the predicate, separated by a comma. We can have multiple predicates.
\end{frame}

\section{9. Algebraic Data Types}

\begin{frame}[fragile]
\frametitle{Algebraic Data Types}
\frametitle{9. Algebraic Data Types}
Of course we can also define our own data types in haskell. One very common type is the \emph{enumeration}. For example, we could define a data type for the Week:
\setHaskellCodeStyle
\begin{lstlisting}
@@ -498,7 +531,7 @@ week = [Monday, Tuesday, Thursday, Wednesday
\end{frame}

\begin{frame}[fragile]
\frametitle{Algebraic Data Types (ctn.)}
\frametitle{9. Algebraic Data Types (ctn.)}
And we can again \emph{pattern match} on our \code{WeekDay} type. Let's find out if a given day is a Monday:
\pause
\setHaskellCodeStyle
@@ -510,7 +543,7 @@ isMonday x = False
\end{frame}

\begin{frame}[fragile]
\frametitle{Algebraic Data Types (ctn.)}
\frametitle{9. Algebraic Data Types (ctn.)}
But we can do more than enumerations. How about we do some error handling? Let's say we want a function to return an \code{Int}, but in case something went horribly wrong, we don't just want to return a 0 or some magic number, but a proper error message. Here we go:
\pause
\setHaskellCodeStyle
@@ -539,7 +572,7 @@ calcSomething x
\end{frame}

\begin{frame}[fragile]
\frametitle{Algebraic Data Types (ctn.)}
\frametitle{9. Algebraic Data Types (ctn.)}
And pattern match on it as well:
\setHaskellCodeStyle
\begin{lstlisting}
@@ -551,7 +584,7 @@ So if we got an error, we just return an empty list, otherwise we return a list
\end{frame}

\begin{frame}[fragile]
\frametitle{Algebraic Data Types (ctn.)}
\frametitle{9. Algebraic Data Types (ctn.)}
Let's define something more complex. How about a tree?
\pause
\setHaskellCodeStyle
@@ -579,7 +612,7 @@ This is just an example. There are endless more ways of trees.
\end{frame}

\begin{frame}[fragile]
\frametitle{Algebraic Data Types (ctn.)}
\frametitle{9. Algebraic Data Types (ctn.)}
Let's build our tree:
\setHaskellCodeStyle
\begin{lstlisting}
@@ -597,7 +630,7 @@ See board...
\end{frame}

\begin{frame}[fragile]
\frametitle{Algebraic Data Types (ctn.)}
\frametitle{9. Algebraic Data Types (ctn.)}
So if we want to generalize it, an algebraic data type has one or more \textbf{constructors}, and each of them can have zero or more arguments. E.g.:
\setHaskellCodeStyle
\begin{lstlisting}
@@ -608,16 +641,20 @@ data AlgDataType = Constr1 Type11 Type12
\end{lstlisting}
\end{frame}

\section{10. Questions so far?}

\begin{frame}
\frametitle{Questions?}
\frametitle{10. Questions so far?}
\begin{itemize}
\item How do functions with multiple parameters look like?
\item ...
\end{itemize}
\end{frame}

\section{11. Common misconceptions}

\begin{frame}
\frametitle{Common misconceptions}
\frametitle{11. Common misconceptions}
Now that we know the basics, let's clear up some common misconceptions about haskell.
\begin{itemize}[<+->]
\item haskell is only a language for university professors
@@ -640,8 +677,10 @@ Now that we know the basics, let's clear up some common misconceptions about has
You can!
\end{frame}

\section{12. Difficulties}

\begin{frame}
\frametitle{Difficulties}
\frametitle{12. Difficulties}
Haskell is very powerful and can be used for pretty much anything. However, there are difficulties in any language. Let's name a few for haskell:
\begin{itemize}[<+->]
\item intellectual complexity? New way of thinking?
@@ -655,8 +694,10 @@ Haskell is very powerful and can be used for pretty much anything. However, ther
\end{itemize}
\end{frame}

\section{13. Toolchain}

\begin{frame}
\frametitle{Toolchain}
\frametitle{13. Toolchain}
How to get started? You need:
\begin{itemize}
\item \textbf{GHC}: this is the Haskell compiler
@@ -667,8 +708,10 @@ Go to \url{https://www.haskell.org/platform}\\
For haskell IDEs, see \url{https://wiki.haskell.org/IDEs}
\end{frame}

\section{14. Links}

\begin{frame}
\frametitle{Further reading and useful links}
\frametitle{14. Further reading and useful links}
\begin{itemize}
\item the most popular haskell course from Brent Yorgey:\\ \url{https://www.seas.upenn.edu/~cis194/fall14/spring13/lectures.html}
\item very verbose and enthusiastic haskell book, good for reading once:\\ \url{http://learnyouahaskell.com}
@@ -679,8 +722,10 @@ For haskell IDEs, see \url{https://wiki.haskell.org/IDEs}
\end{itemize}
\end{frame}

\section{15. What you should know}

\begin{frame}
\frametitle{What you should know now}
\frametitle{15. What you should know now}
\begin{itemize}
\item what haskell is
\item how you write haskell functions
@@ -690,8 +735,10 @@ For haskell IDEs, see \url{https://wiki.haskell.org/IDEs}
\end{itemize}
\end{frame}

\section{16. Questions for you}

\begin{frame}[fragile]
\frametitle{You should be able to answer these questions}
\frametitle{16. Questions for you}
\begin{itemize}
\item What are side effects?
\item What is referential transparency?
@@ -712,8 +759,10 @@ f 0 = 0.5
\end{lstlisting}
\end{frame}

\section{17. Sources}

\begin{frame}
\frametitle{Sources}
\frametitle{17. Sources}
\begin{itemize}
\item much content was borrowed or is based on the haskell course from Brent Yorgey:\\ \url{https://www.seas.upenn.edu/~cis194/fall14/spring13/lectures.html}
\item a few small pieces from the LYAH book \url{http://learnyouahaskell.com}


Načítá se…
Zrušit
Uložit