From b79743db4ce38dd67e8f7308933f9f6db96248b2 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 19 Apr 2015 18:43:16 +0200 Subject: [PATCH] Improve function composition slides --- VL2.tex | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/VL2.tex b/VL2.tex index cd31f07..7fe2636 100644 --- a/VL2.tex +++ b/VL2.tex @@ -376,7 +376,10 @@ Solution: (.) :: (b -> c) -> (a -> b) -> a -> c (.) f g x = f (g x) \end{haskellcode} -\pause +\end{frame} + +\begin{frame}[fragile] +\frametitle{5. Function composition} And now you can chain functions together. Not just two! Look: \begin{haskellcode} f :: String -> Bool @@ -385,6 +388,23 @@ f xs = (even . length . (\x -> x ++ "Hello world")) xs f xs = even . length . (\x -> x ++ "Hello world") $ xs \end{haskellcode} % $ +\pause +Another example where currying is actually important: +\begin{haskellcode} +f :: Int -> Bool +f x = even . (+) 3 . (-) 4 $ x + +-- why not this? +f x = even . (+) 3 . (-) $ 4 x +\end{haskellcode} +%$ +\pause +So there a few things that we have to be aware of: +\begin{itemize} +\item the types have to fit! +\item the arity has to fit! +\end{itemize} +That sounds complicated at first, because it counts for the whole composition chain. But you'll get used to it. \end{frame} \section{6. Recursion patterns}