You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

19 lines
1.2 KiB

  1. \ifger{Um es kurz zu machen, die abstrakte Lösung ist:}{To cut the story short, the abstract solution looks like this:}
  2. \begin{haskellcode}
  3. fold :: (a -> b -> b) -> b -> [a] -> b
  4. fold f z [] = z
  5. fold f z (x:xs) = x `f` (fold f z xs)
  6. \end{haskellcode}
  7. Whoa! What's going on here?\\
  8. \ifger{Schauen wir genauer hin...}{Let's see...}
  9. \begin{itemizep}
  10. \item \hinline{f} \ifger{ist unsere Funktion}{is our function} (\ifger{z.b.}{e.g.} \hinline{(*)} \ifger{oder}{or} \hinline{(+)})
  11. \item \hinline{z} \ifger{ist was die Funktion zurückgibt, wenn die Liste leer ist}{is what we return if the list is empty}
  12. \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}
  13. \end{itemizep}
  14. \slidep
  15. \ifger{Die Funktionsanwendung hat die folgende Form:}{The function application has the following form:}\\
  16. \hinline{fold f z [a,b,c] == a `f` (b `f` (c `f` z))}
  17. \vspace{\baselineskip}
  18. \\
  19. \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}.}