Improve TOC

Also add TOC for beginning of a new section to show the subsections.
This commit is contained in:
Julian Ospald 2015-04-17 19:28:14 +02:00
parent fab913d5b9
commit c47f62ca93
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
1 changed files with 70 additions and 38 deletions

108
VL1.tex
View File

@ -144,6 +144,11 @@ We are lucky. There is. It's called \textbf{Haskell}.
\begin{frame}
\frametitle{2. What is haskell?}
\tableofcontents[currentsection,hideothersubsections]
\end{frame}
\begin{frame}
\frametitle{2. What is haskell? (ctn.)}
Haskell is a \textbf{functional}, \textbf{pure}, \textbf{lazy} and \textbf{statically typed} high-level programming language.\\
\onslide<+->
\vspace{\baselineskip}
@ -260,10 +265,17 @@ Let's reiterate. Haskell is:
\end{itemize}
\end{frame}
\section{4. Declarations}
\section{4. How to write haskell?}
\begin{frame}
\frametitle{4. How to write haskell?}
\tableofcontents[currentsection,hideothersubsections]
\end{frame}
\subsection{4.1. Declarations}
\begin{frame}[fragile]
\frametitle{4. Declarations}
\frametitle{4.1. Declarations}
Let's go!
\begin{haskellcode}
x :: Int
@ -287,10 +299,10 @@ s = "Hello, world?"
\end{haskellcode}
\end{frame}
\section{5. Arithmetic and co.}
\subsection{4.2. Arithmetic and co.}
\begin{frame}[fragile]
\frametitle{5. Arithmetic and co.}
\frametitle{4.2. Arithmetic and co.}
GHCi:
\begin{haskellcode}
> 3 + 5
@ -302,10 +314,10 @@ GHCi:
\end{haskellcode}
\end{frame}
\section{6. Functions and control structures}
\subsection{4.3. Functions and control structures}
\begin{frame}[fragile]
\frametitle{6. Functions and control structures}
\frametitle{4.3. Functions and control structures}
Let's make our first function. We want something like the following mathematical function\\
$f(x) = x * x$\\
\vspace{\baselineskip}
@ -328,7 +340,7 @@ So the function gets an Int and returns an Int. Don't get confused by "\verb|->|
\end{frame}
\begin{frame}[fragile]
\frametitle{6. Functions and control structures (ctn.)}
\frametitle{4.3. 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
\vspace{\baselineskip}
@ -344,7 +356,7 @@ What might happen if we remove the second or the third line? What is a \textbf{p
\end{frame}
\begin{frame}[fragile]
\frametitle{6. Functions and control structures (ctn.)}
\frametitle{4.3. Functions and control structures (ctn.)}
How about \emph{recursion}? Let's define the modulo of any \emph{Int} to \emph{2}.
\pause
\vspace{\baselineskip}
@ -358,10 +370,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. Lists}
\subsection{4.4. Lists}
\begin{frame}[fragile]
\frametitle{7. Lists}
\frametitle{4.4. Lists}
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
We build lists by using either the \code{[]} notation:
@ -387,7 +399,7 @@ infiniteList = [1..]
\end{frame}
\begin{frame}[fragile]
\frametitle{7. Lists (ctn.)}
\frametitle{4.4. Lists (ctn.)}
Let's check on a few very common list operations:
\begin{haskellcode}
> [1, 2] ++ [4, 5] -- append two lists
@ -410,7 +422,7 @@ A String in haskell is just a list of Chars!
\end{frame}
\begin{frame}[fragile]
\frametitle{7. Lists (ctn.)}
\frametitle{4.4. Lists (ctn.)}
Again, we can do pattern matching on lists.
\begin{haskellcode}
listLen :: [Integer] -> Integer
@ -429,7 +441,7 @@ Note that \code{(x:(y:zs))} may also be written as \code{(x:y:zs)}.
\end{frame}
\begin{frame}[fragile]
\frametitle{7. Lists (ctn.)}
\frametitle{4.4. 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
@ -450,10 +462,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{8. Pairs}
\subsection{4.5. Pairs}
\begin{frame}[fragile]
\frametitle{8. Pairs}
\frametitle{4.5. Pairs}
Defining a pair is easy.
\begin{haskellcode}
p :: (Int, Char) -- this is the type
@ -467,10 +479,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{9. Algebraic Data Types}
\subsection{4.6. Algebraic Data Types}
\begin{frame}[fragile]
\frametitle{9. Algebraic Data Types}
\frametitle{4.6. 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:
\begin{haskellcode}
data WeekDay = Monday
@ -494,7 +506,7 @@ week = [Monday, Tuesday, Thursday, Wednesday
\end{frame}
\begin{frame}[fragile]
\frametitle{9. Algebraic Data Types (ctn.)}
\frametitle{4.6. 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
\begin{haskellcode}
@ -505,7 +517,7 @@ isMonday x = False
\end{frame}
\begin{frame}[fragile]
\frametitle{9. Algebraic Data Types (ctn.)}
\frametitle{4.6. 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
\begin{haskellcode}
@ -531,7 +543,7 @@ calcSomething x
\end{frame}
\begin{frame}[fragile]
\frametitle{9. Algebraic Data Types (ctn.)}
\frametitle{4.6. Algebraic Data Types (ctn.)}
And pattern match on it as well:
\begin{haskellcode}
addIntToList :: MaybeInt -> [Int]
@ -542,7 +554,7 @@ So if we got an error, we just return an empty list, otherwise we return a list
\end{frame}
\begin{frame}[fragile]
\frametitle{9. Algebraic Data Types (ctn.)}
\frametitle{4.6. Algebraic Data Types (ctn.)}
Let's define something more complex. How about a tree?
\pause
\begin{haskellcode}
@ -569,7 +581,7 @@ This is just an example. There are endless more ways of trees.
\end{frame}
\begin{frame}[fragile]
\frametitle{9. Algebraic Data Types (ctn.)}
\frametitle{4.6. Algebraic Data Types (ctn.)}
Let's build our tree:
\begin{haskellcode}
tree :: Tree
@ -586,7 +598,7 @@ See board...
\end{frame}
\begin{frame}[fragile]
\frametitle{9. Algebraic Data Types (ctn.)}
\frametitle{4.6. 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.:
\begin{haskellcode}
data AlgDataType = Constr1 Type11 Type12
@ -596,20 +608,28 @@ data AlgDataType = Constr1 Type11 Type12
\end{haskellcode}
\end{frame}
\section{10. Questions so far?}
\section{5. Résumé}
\begin{frame}
\frametitle{10. Questions so far?}
\frametitle{5. Résumé}
\tableofcontents[currentsection,hideothersubsections]
\end{frame}
\subsection{5.1. Questions so far?}
\begin{frame}
\frametitle{5.1. Questions so far?}
\begin{itemize}
\item How do functions with multiple parameters look like?
\item ...
\end{itemize}
\end{frame}
\section{11. Common misconceptions}
\subsection{5.2. Common misconceptions}
\begin{frame}
\frametitle{11. Common misconceptions}
\frametitle{5.2. 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
@ -632,10 +652,10 @@ Now that we know the basics, let's clear up some common misconceptions about has
You can!
\end{frame}
\section{12. Difficulties}
\subsection{5.3. Difficulties}
\begin{frame}
\frametitle{12. Difficulties}
\frametitle{5.3. 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?
@ -649,7 +669,7 @@ Haskell is very powerful and can be used for pretty much anything. However, ther
\end{itemize}
\end{frame}
\section{13. Toolchain}
\section{6. Toolchain}
\begin{frame}
\frametitle{13. Toolchain}
@ -663,11 +683,16 @@ Go to \url{https://www.haskell.org/platform}\\
For haskell IDEs, see \url{https://wiki.haskell.org/IDEs}
\end{frame}
\section{7. Reflection}
\begin{frame}
\frametitle{7. Reflection}
\tableofcontents[currentsection,hideothersubsections]
\end{frame}
\section{14. What you should know}
\subsection{7.1. What you should know}
\begin{frame}
\frametitle{14. What you should know now}
\frametitle{7.1. What you should know now}
\begin{itemize}
\item what haskell is
\item how you write haskell functions
@ -677,10 +702,10 @@ For haskell IDEs, see \url{https://wiki.haskell.org/IDEs}
\end{itemize}
\end{frame}
\section{15. Questions for you}
\subsection{7.2. Questions for you}
\begin{frame}[fragile]
\frametitle{15. Questions for you}
\frametitle{7.2. Questions for you}
\begin{itemize}
\item What are side effects?
\item What is referential transparency?
@ -701,10 +726,17 @@ f 0 = 0.5
\end{haskellcode}
\end{frame}
\section{16. Links}
\section{8. References}
\begin{frame}
\frametitle{16. Further reading and useful links}
\frametitle{8. References}
\tableofcontents[currentsection,hideothersubsections]
\end{frame}
\subsection{8.1. Links}
\begin{frame}
\frametitle{8.1. 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}
@ -715,10 +747,10 @@ f 0 = 0.5
\end{itemize}
\end{frame}
\section{17. Sources}
\subsection{8.2. Sources}
\begin{frame}
\frametitle{17. Sources}
\frametitle{8.2. 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}