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
689 B

  1. 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. 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. 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. So we don't really know what the function \code{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.