haskell-lectures/VL2/content/VL2_rec_patterns7.tex
2015-04-20 00:51:14 +02:00

14 lines
388 B
TeX

Let's abstract out the common pieces! This will be our type signature:
\begin{haskellcode}
filter :: (a -> Bool) -> [a] -> [a]
\end{haskellcode}
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}
Again: this function is part of the \emph{Prelude} as well.