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.
 
 
 

18 lines
1.5 KiB

  1. \ifger{Es gibt auch eine Funktion die von \emph{links} faltet und ebenfalls in \emph{Prelude} ist. Sie heisst \textbf{foldl}.}{There is also a function that folds from the \emph{left} which is also in the \emph{Prelude} and called \textbf{foldl}.}\\
  2. \ifger{Zusammenfassend:}{To summarize:}
  3. \begin{haskellcode}
  4. foldr f z [a,b,c] == a `f` (b `f` (c `f` z))
  5. foldl f z [a,b,c] == ((z `f` a) `f` b) `f` c
  6. \end{haskellcode}
  7. \ifger{Für}{For} \hinline{foldl} \ifger{ist}{the} \hinline{z} \ifger{quasi der Startwert.}{is sort of the starting value.}
  8. \vspace{\baselineskip}
  9. \\
  10. \pause
  11. \ifger{Wir können sogar foldl mittels foldr ausdrücken und umgekehrt. Wer interessiert daran ist, sollte hier\footnote{\url{http://lambda.jstolarek.com/2012/07/expressing-foldl-in-terms-of-foldr}} weiterlesen.}{We can even express foldl in terms of foldr and vice versa. If you are interested, have a look here\footnote{\url{http://lambda.jstolarek.com/2012/07/expressing-foldl-in-terms-of-foldr}}.}
  12. \vspace{\baselineskip}
  13. \\
  14. \ifger{Es macht Sinn diese Funktionen in \emph{Prelude}\footnote{\url{https://hackage.haskell.org/package/base-4.8.0.0/docs/Prelude.html}} anzuschauen und ein bisschen damit herumzuspielen:}{You should definitely look them up in the \emph{Prelude}\footnote{\url{https://hackage.haskell.org/package/base-4.8.0.0/docs/Prelude.html}} and play with them:}
  15. \begin{haskellcode*}{bgcolor=mygrey,frame=single,numbers=none,label=GHCi}
  16. > foldr (-) 0 [1, 2, 3]
  17. > foldl (-) 0 [1, 2, 3]
  18. \end{haskellcode*}