@@ -57,6 +57,7 @@ | |||||
\subsection{Partial application} | \subsection{Partial application} | ||||
\slide{./content/VL2_currying6.tex} | \slide{./content/VL2_currying6.tex} | ||||
\slide{./content/VL2_currying6.2.tex} | |||||
\subsection{Curry \ifger{und}{and} Uncurry} | \subsection{Curry \ifger{und}{and} Uncurry} | ||||
\slide{./content/VL2_currying7.tex} | \slide{./content/VL2_currying7.tex} | ||||
@@ -10,4 +10,4 @@ addInt x y = x + y | |||||
addInt :: (Int, Int) -> Int | addInt :: (Int, Int) -> Int | ||||
addInt (x, y) = x + y | addInt (x, y) = x + y | ||||
\end{haskellcode} | \end{haskellcode} | ||||
\ifger{was im Grunde der Sache sogar recht nahe kommt.}{which is actually pretty close.} | |||||
\ifger{was im Grunde der Sache sogar recht nahe kommt. Denn die Beziehung beider Schreibweisen ist eigentlich schon \textbf{Currying}.}{which is actually pretty close. Because the connection between both syntax is exactly that: \textbf{currying}.} |
@@ -4,7 +4,7 @@ $f(x, y) = y / x$ | |||||
\\ | \\ | ||||
\pause | \pause | ||||
\ifger{Um diese Funktion für $x = 2$ und $y = 3$ zu berechnen würden wir einfach einsetzen:}{In order to evaluate the function for $x = 2$ and $y = 3$ we would do:}\\ | \ifger{Um diese Funktion für $x = 2$ und $y = 3$ zu berechnen würden wir einfach einsetzen:}{In order to evaluate the function for $x = 2$ and $y = 3$ we would do:}\\ | ||||
$f(2, 3) = 2 / 3$\\ | |||||
$f(2, 3) = 3 / 2$\\ | |||||
\ifger{und fertig sein.}{and be done.} | \ifger{und fertig sein.}{and be done.} | ||||
\vspace{\baselineskip} | \vspace{\baselineskip} | ||||
\\ | \\ | ||||
@@ -0,0 +1,15 @@ | |||||
\ifger{Wer es unbedingt wissen will, der Grund warum wir \hinline{x} auslassen können ist, dass}{The reason we can omit the \hinline{x} here is that} | |||||
\begin{haskellcode} | |||||
f x y z = ... | |||||
\end{haskellcode} | |||||
\ifger{mehr oder weniger nur syntax sugar ist für}{is more or less just syntax sugar for} | |||||
\begin{haskellcode} | |||||
f = \x -> (\y -> (\z -> ... )) -- right-associative, ofc | |||||
\end{haskellcode} | |||||
\ifger{D.h. wir hätten auch folgendes schreiben können:}{That means we could have said:} | |||||
\begin{haskellcode} | |||||
addTwo :: Int -> Int | |||||
addTwo = \x -> (addInt 2) x | |||||
-- instead of | |||||
addTwo x = (addInt 2) x | |||||
\end{haskellcode} |
@@ -7,13 +7,8 @@ addInt x y = x + y | |||||
addTwo :: Int -> Int | addTwo :: Int -> Int | ||||
addTwo = addInt 2 | addTwo = addInt 2 | ||||
\end{haskellcode} | \end{haskellcode} | ||||
\ifger{Warum haben wir nicht \hinline{addTwo x = ...} geschrieben? Wieso sollten wir? Wir haben \hinline{addInt} ein Argument übergeben, also ist die Arität (im Beispiel vorher Dimension) einer weniger und damit ist noch ein Argument notwendig um den endgültigen Wert zu bekommen.}{You probably noticed that we did not write \hinline{addTwo x = ...}, but why would we? We gave \hinline{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.} | |||||
\pause | |||||
\ifger{Der Grund warum wir \hinline{x} auslassen können ist, dass}{The reason we can omit the \hinline{x} here is that} | |||||
\begin{haskellcode} | |||||
f x y z = ... | |||||
\end{haskellcode} | |||||
\ifger{nur syntax sugar ist für}{is just syntax sugar for} | |||||
\begin{haskellcode} | |||||
f = \x -> (\y -> (\z -> ... )) -- right-associative, ofc | |||||
\end{haskellcode} | |||||
\ifger{Warum haben wir nicht \hinline{addTwo x = ...} geschrieben? Wieso sollten wir? Wir haben \hinline{addInt} ein Argument übergeben, also ist die Arität (im Beispiel vorher Dimension) einer weniger und damit ist noch ein Argument notwendig um den endgültigen Wert zu bekommen. | |||||
\vspace{\baselineskip}\\ | |||||
Oder in anderen Worten: wir haben der Zwischenfunktion, die Currying für uns erstellt hat, lediglich den Namen \hinline{addTwo} gegeben.}{You probably noticed that we did not write \hinline{addTwo x = ...}, but why would we? We gave \hinline{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}\\ | |||||
Or in other words: we just gave the intermediate function that currying created for us the name \hinline{addTwo}. That's it.}\vspace{\baselineskip}\\ |