Improve configuration modularity, use minted for inline code

This commit is contained in:
Julian Ospald
2015-04-20 20:55:41 +02:00
parent 9d9ddfaf2d
commit 22f0fd9447
29 changed files with 86 additions and 98 deletions

View File

@@ -8,7 +8,7 @@ data WeekDay = Monday
| Saturday
| Sunday
\end{haskellcode}
This declares the new data type \code{WeekDay} with 7 \emph{constructors}. That means \code{Monday}, \code{Tuesday} etc. are all values of the type \code{WeekDay}.
This declares the new data type \hinline{WeekDay} with 7 \emph{constructors}. That means \hinline{Monday}, \hinline{Tuesday} etc. are all values of the type \hinline{WeekDay}.
\pause
\\
We could now define a whole week, by creating a list:

View File

@@ -1,4 +1,4 @@
And we can again \emph{pattern match} on our \code{WeekDay} type. Let's find out if a given day is a Monday:
And we can again \emph{pattern match} on our \hinline{WeekDay} type. Let's find out if a given day is a Monday:
\pause
\begin{haskellcode}
isMonday :: WeekDay -> Bool

View File

@@ -1,4 +1,4 @@
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:
But we can do more than enumerations. How about we do some error handling? Let's say we want a function to return an \hinline{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}
data MaybeInt = NoError Int

View File

@@ -12,4 +12,4 @@ addIntToList :: MaybeInt -> [Int]
addIntToList (NoError x) = [x]
addIntToList (Error str) = []
\end{haskellcode}
So if we got an error, we just return an empty list, otherwise we return a list with the \code{Int} as its only element.
So if we got an error, we just return an empty list, otherwise we return a list with the \hinline{Int} as its only element.

View File

@@ -8,16 +8,16 @@ Uh... that looks mean. Let's examine this.\\
\pause
We have:
\begin{itemizep}
\item defined a data type \code{Tree}
\item a constructor \code{Leaf} of type \code{Tree} with one arguments of type \code{Char}
\item a constructor \code{Node} of type \code{Tree} with 3 arguments
\item defined a data type \hinline{Tree}
\item a constructor \hinline{Leaf} of type \hinline{Tree} with one arguments of type \hinline{Char}
\item a constructor \hinline{Node} of type \hinline{Tree} with 3 arguments
\begin{itemizep}
\item \code{Tree}
\item \code{Int}
\item \code{Tree}
\item \hinline{Tree}
\item \hinline{Int}
\item \hinline{Tree}
\end{itemizep}
\end{itemizep}
\slidep
That means: a \code{Tree} can either be a \code{Leaf} or an internal \code{Node} with two sub-trees. If we want to create a \code{Leaf}, we have to pass the constructor a \code{Char}. If we want to create a \code{Node}, we have to pass 3 arguments, in order: another \code{Tree}, an \code{Int} and yet another \code{Tree}.\\
So we can save information in the leafs (\code{Char}) and in the internal nodes (\code{Int}).\\
That means: a \hinline{Tree} can either be a \hinline{Leaf} or an internal \hinline{Node} with two sub-trees. If we want to create a \hinline{Leaf}, we have to pass the constructor a \hinline{Char}. If we want to create a \hinline{Node}, we have to pass 3 arguments, in order: another \hinline{Tree}, an \hinline{Int} and yet another \hinline{Tree}.\\
So we can save information in the leafs (\hinline{Char}) and in the internal nodes (\hinline{Int}).\\
This is just an example. There are endless more ways of trees.

View File

@@ -7,4 +7,4 @@ mod2 x
| x - 2 < 0 = x
| otherwise = mod2 (x - 2)
\end{haskellcode}
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.
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.\\ \hinline{otherwise} on the last line is just defined as \hinline{True}, to make these constructs easier to read and catch all other cases of input.

View File

@@ -1,12 +1,12 @@
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:
We build lists by using either the \hinline{[]} notation:
\begin{haskellcode}
list1 :: [Integer]
list1 = [1, 2]
\end{haskellcode}
\pause
or by using the \emph{cons} operator \code{(:)} which takes an element and a list and produces a new list with the element prepended to the front.
or by using the \emph{cons} operator \hinline{(:)} which takes an element and a list and produces a new list with the element prepended to the front.
\begin{haskellcode}
emptyList = []

View File

@@ -12,4 +12,4 @@ sumEveryTwo [] = 0
sumEveryTwo (x:[]) = [x]
sumEveryTwo (x:(y:zs)) = (x + y) : sumEveryTwo zs
\end{haskellcode}
Note that \code{(x:(y:zs))} may also be written as \code{(x:y:zs)}.
Note that \hinline{(x:(y:zs))} may also be written as \hinline{(x:y:zs)}.

View File

@@ -16,4 +16,4 @@ Now let's say we want all numbers between 50 and 100 that have the remainder 0 w
\begin{haskellcode*}{bgcolor=mygrey,frame=single,numbers=none,label=GHCi}
> [x | x <- [50..100], mod x 12 == 0]
\end{haskellcode*}
\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.
\hinline{x <- [50..100]} is the binding, while \hinline{mod x 12 == 0} is the predicate, separated by a comma. We can have multiple predicates.

View File

@@ -8,4 +8,4 @@ sumPair :: (Int, Int) -> Int
sumPair (x, y) = x + y
\end{haskellcode}
\pause
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.
Note: we use \hinline{(x, y)} notation for both the type and the definition! Those are still two different things. We can also have triples, quadruples etc.

View File

@@ -4,7 +4,7 @@
\item everything (variables, data structures...) is \emph{immutable}
\item expressions never have side-effects (remember: mathematical functions)
\item same input $\mapsto$ same output... \emph{always}!
\item replace a function with it's (return) value? Yes. What happens in C or java if you do that? Remember \code{void pop();}?
\item replace a function with it's (return) value? Yes. What happens in C or java if you do that? Remember \cppinline{void pop();}?
\end{itemizep}
\slidep
\vspace{\baselineskip}