15 lines
788 B
TeX
15 lines
788 B
TeX
\ifger{Und jetzt definieren wir unsere ursprünglichen Funktionen mithilfe von \hinline{map}:}{And now watch this:}
|
|
\begin{haskellcode}
|
|
addTwo :: [Int] -> [Int]
|
|
addTwo xs = map (\x -> x + 2) xs
|
|
|
|
square :: [Int] -> [Int]
|
|
square xs = map (\x -> x * x) xs
|
|
|
|
absList :: [Int] -> [Int]
|
|
absList xs = map (\x -> abs x) xs
|
|
-- a haskeller would write, GHCi...
|
|
absList = map abs
|
|
\end{haskellcode}
|
|
\pause
|
|
\ifger{Cool, oder? Wir haben jetzt die \textbf{Rekursionsstruktur} herausabstrahiert, weil sie für alle 3 Funktionen dieselbe ist. \hinline{map} ist schon Teil des Standardmoduls \emph{Prelude}.}{Cool, right? So now we have abstracted out the \textbf{recursion pattern} that is all the same for those 3 functions. \hinline{map} is actually part of the standard library (called \emph{Prelude}).} |