haskell-lectures/VL2/content/VL2_composition3.tex

25 lines
709 B
TeX
Raw Normal View History

And now you can chain functions together. Not just two! Look:
\begin{haskellcode}
f :: String -> Bool
f xs = (even . length . (\x -> x ++ "Hello world")) xs
-- or less ugly
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 are 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.