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.
 
 
 

14 lines
521 B

  1. \ifger{Jetzt wollen wir uns unsere Funktionen}{So how do our} \hinline{sum}, \hinline{prod} \ifger{und}{and} \hinline{length} \ifger{anschauen, wenn wir sie mittels \hinline{fold} implementieren:}{functions look like if we use our \hinline{fold} abstraction?}
  2. \pause
  3. \begin{haskellcode}
  4. sum :: [Int] -> Int
  5. sum xs = fold (\x y -> x + y) 0 xs
  6. -- a Haskeller would write
  7. sum = fold (+) 0
  8. prod :: [Int] -> Int
  9. prod xs = fold (\x y -> x * y) 1 xs
  10. length :: [a] -> Int
  11. length xs = fold (\x y -> 1 + y) 0 xs
  12. \end{haskellcode}