2015-04-23 20:40:13 +00:00
|
|
|
\ifger{Erneut können wir pattern matching anwenden, auch auf Listen.}{Again, we can do pattern matching on lists.}
|
2015-04-19 22:32:01 +00:00
|
|
|
\begin{haskellcode}
|
|
|
|
listLen :: [Integer] -> Integer
|
|
|
|
listLen [] = 0
|
|
|
|
listLen (x:xs) = 1 + listLen xs
|
|
|
|
\end{haskellcode}
|
|
|
|
\pause
|
2015-04-23 20:40:13 +00:00
|
|
|
\ifger{Pattern matching können wir auch schachteln:}{We can also nest pattern matching:}
|
2015-04-19 22:32:01 +00:00
|
|
|
\begin{haskellcode}
|
|
|
|
sumEveryTwo :: [Integer] -> [Integer]
|
|
|
|
sumEveryTwo [] = 0
|
|
|
|
sumEveryTwo (x:[]) = [x]
|
|
|
|
sumEveryTwo (x:(y:zs)) = (x + y) : sumEveryTwo zs
|
|
|
|
\end{haskellcode}
|
2015-04-23 20:40:13 +00:00
|
|
|
\ifger{Hinweis...}{Note that} \hinline{(x:(y:zs))} \ifger{kann man auch als}{may also be written as} \hinline{(x:y:zs)}\ifger{ schreiben.}{.}
|