\ifger{Um es kurz zu machen, die abstrakte Lösung ist:}{To cut the story short, the abstract solution looks like this:} \begin{haskellcode} fold :: (a -> b -> b) -> b -> [a] -> b fold f z [] = z fold f z (x:xs) = x `f` (fold f z xs) \end{haskellcode} Whoa! What's going on here?\\ \ifger{Schauen wir genauer hin...}{Let's see...} \begin{itemizep} \item \hinline{f} \ifger{ist unsere Funktion}{is our function} (\ifger{z.b.}{e.g.} \hinline{(*)} \ifger{oder}{or} \hinline{(+)}) \item \hinline{z} \ifger{ist was die Funktion zurückgibt, wenn die Liste leer ist}{is what we return if the list is empty} \item \ifger{das letzte Argument ist die eigentliche Liste, auf der wir arbeiten}{and the last remaining argument is the actual list we are working on} \end{itemizep} \slidep \ifger{Die Funktionsanwendung hat die folgende Form:}{The function application has the following form:}\\ \hinline{fold f z [a,b,c] == a `f` (b `f` (c `f` z))} \vspace{\baselineskip} \\ \ifger{D.h. hier falten wir von rechts. \emph{Prelude} definiert diese Funktion bereits, die fast genauso ist wie unsere. Sie heisst \textbf{foldr}.}{This folds from the right, so the \emph{Prelude} already defines a function which is very similar to ours and called \textbf{foldr}.}