21 lines
904 B
TeX
21 lines
904 B
TeX
|
What does that mean for us? It's not just fun stuff or aesthetic. It allows us to do \textbf{partial application}. That means we do not have to give a function all arguments. If we pass an "insufficient" number of arguments it will just give us a new function! Here:
|
||
|
\pause
|
||
|
\begin{haskellcode}
|
||
|
addInt :: Int -> Int -> Int
|
||
|
addInt x y = x + y
|
||
|
|
||
|
addTwo :: Int -> Int
|
||
|
addTwo = addInt 2
|
||
|
\end{haskellcode}
|
||
|
You probably noticed that we did not write \code{addTwo x = ...}, but why would we? We gave \code{addInt} one argument, so the arity (we called it dimension in the gemoetrical example) is one less, but there is still one parameter left we can pass in.
|
||
|
\vspace{\baselineskip}
|
||
|
\\
|
||
|
\pause
|
||
|
The reason we can omit the \code{x} here is that
|
||
|
\begin{haskellcode}
|
||
|
f x y z = ...
|
||
|
\end{haskellcode}
|
||
|
is just syntax sugar for
|
||
|
\begin{haskellcode}
|
||
|
f = \x -> (\y -> (\z -> ... )) -- right-associative, ofc
|
||
|
\end{haskellcode}
|