haskell-lectures/VL1/content/VL1_lists4.tex
Julian Ospald f36590c9f4
Restructure files, make the latex code more modular
Also added a few more section to make beamer and article more
compatible.
2015-04-20 17:38:58 +02:00

19 lines
717 B
TeX

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
$S = \{2 \times x\ |\ x \in \mathbb{N},\ x \leq 10\}$
\vspace{\baselineskip}
\pause
\\
How does this look in haskell?
\pause
\begin{haskellcode}
> [ 2 * x | x <- [1..10]]
\end{haskellcode}
\pause
Now let's say we want all numbers between 50 and 100 that have the remainder 0 when divided by 12:
\pause
\begin{haskellcode}
> [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.