Browse Source

Improve function composition slides

stripped-german
Julian Ospald 9 years ago
parent
commit
b79743db4c
No known key found for this signature in database GPG Key ID: 220CD1C5BDEED020
1 changed files with 21 additions and 1 deletions
  1. +21
    -1
      VL2.tex

+ 21
- 1
VL2.tex View File

@@ -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}


Loading…
Cancel
Save