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.
 
 
 

16 lines
1.2 KiB

  1. \ifger{Alle 3 Funktionen sind sehr ähnlich. In Haskell wollen wir vor allem abstrahieren und würden niemals die Funktionen derart schreiben. Stattdessen werden wir eine Funktion schreiben, die die Rekursionsstruktur aller 3 abstrakt zusammenfässt.}{All those 3 functions look almost the same. Since haskell is about abstraction, we would never really write any of those like that. Instead, we will write a function that generalizes all 3.}
  2. \vspace{\baselineskip}
  3. \\
  4. \pause
  5. \ifger{Ich gebe als Tipp die Typsignatur. Wie könnte die Implementierung aussehen?}{I'll give you the type signature, can you guess how the implementation looks like?}
  6. \begin{haskellcode}
  7. map :: (a -> b) -> [a] -> [b]
  8. \end{haskellcode}
  9. \ifger{Lösung?}{Solution?}
  10. \pause
  11. \begin{haskellcode}
  12. map :: (a -> b) -> [a] -> [b]
  13. map f [] = []
  14. map f (x:xs) = f x : map f xs
  15. \end{haskellcode}
  16. \ifger{Wir wissen nicht was die Funktion \hinline{f} genau macht, aber wir wissen, dass sie ein Element der Liste zu etwas anderem konvertiert. Wir \emph{mappen} eine Funktion über eine Liste! Daher der Name.}{So we don't really know what the function \hinline{f} does, but we know that it converts one element of the list to something else. We \emph{map} a function over a list! Hence the name.}