haskell-lectures/VL2/content/VL2_filter2.tex

14 lines
571 B
TeX

\ifger{Wir werden die Rekursionsstruktur erneut herausabstrahieren! Die Typsignatur sieht so aus:}{Let's abstract out the common pieces! This will be our type signature:}
\begin{haskellcode}
filter :: (a -> Bool) -> [a] -> [a]
\end{haskellcode}
\ifger{Lösung?}{Solution?}
\pause
\begin{haskellcode}
filter :: (a -> Bool) -> [a] -> [a]
filter f [] = []
filter f (x:xs)
| f x = x : filter f xs
| otherwise = filter f xs
\end{haskellcode}
\ifger{Diese Funktion ist ebenfalls Teil von \emph{Prelude}.}{Again: this function is part of the \emph{Prelude} as well.}