From 686f4fc43803cf0f136803067f296625441d305d Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sat, 2 May 2015 13:45:22 +0200 Subject: [PATCH] Improve currying slides --- VL2/VL2_document_structure.tex | 2 +- VL2/content/VL2_currying5.1.tex | 10 ++++++++++ VL2/content/VL2_currying5.tex | 6 ++---- VL2/content/VL2_currying6.2.tex | 15 --------------- VL2/content/VL2_currying6.tex | 8 ++++++-- 5 files changed, 19 insertions(+), 22 deletions(-) create mode 100644 VL2/content/VL2_currying5.1.tex delete mode 100644 VL2/content/VL2_currying6.2.tex diff --git a/VL2/VL2_document_structure.tex b/VL2/VL2_document_structure.tex index f7b2dc7..b2da55d 100644 --- a/VL2/VL2_document_structure.tex +++ b/VL2/VL2_document_structure.tex @@ -54,10 +54,10 @@ \subsection{\ifger{Schlussfolgerung}{Conclusion}} \slide{./content/VL2_currying5.tex} +\slide{./content/VL2_currying5.1.tex}[ (cnt.)] \subsection{Partial application} \slide{./content/VL2_currying6.tex} -\slide{./content/VL2_currying6.2.tex} \subsection{Curry \ifger{und}{and} Uncurry} \slide{./content/VL2_currying7.tex} diff --git a/VL2/content/VL2_currying5.1.tex b/VL2/content/VL2_currying5.1.tex new file mode 100644 index 0000000..3ab0ce0 --- /dev/null +++ b/VL2/content/VL2_currying5.1.tex @@ -0,0 +1,10 @@ +\ifger{Also, wenn wir in Haskell scheinbar mehrere Argumente einer Funktion übergeben, steckt immer Currying dahinter. Es erzeugt eine Reihe von Zwischenfunktionen (oder anonyme Funktionen) mit jeweils einem Argument und evaluiert diese dann schrittweise.}{So, if we seemingly pass multiple arguments into a function, then there is always currying behind it. It creates those intermediate/anonymous functions, all with one argument only, and then evaluates them stepwise.} + +\begin{haskellcode} +-- this is more or less just syntax sugar... +f x y z = x + y + z +-- ...for this +f = \x -> (\y -> (\z -> x + y + z)) -- right-associative +\end{haskellcode} + +\ifger{Frage: was passiert, wenn wir nur $x = 3$ übergeben?}{Question: what happens if we just pass $x = 3$?} \ No newline at end of file diff --git a/VL2/content/VL2_currying5.tex b/VL2/content/VL2_currying5.tex index aac0e20..6190600 100644 --- a/VL2/content/VL2_currying5.tex +++ b/VL2/content/VL2_currying5.tex @@ -1,5 +1,6 @@ \ifger{D.h. mathematisch gesehen können wir schreiben:}{So in mathematical terms you can say:}\\ $f : A_1 \times ... \times A_n \mapsto B$ +\vspace{\baselineskip} \\ \ifger{wird zu}{gets modified into:}\\ \pause @@ -15,7 +16,4 @@ f :: Int -> (Int -> Int) -- but this is NOT the same f :: (Int -> Int) -> Int \end{haskellcode} -\ifger{Auf der anderen Seite ist Funktionsanwendung \emph{links}-assoziativ, d.h.}{On the other hand function application is \emph{left}-associative, so} \hinline{f 3 2} \ifger{ist nur die Kurzform für}{is just a shorthand of} \hinline{(f 3) 2}. -\vspace{\baselineskip} -\\ -\ifger{Also, wenn wir in Haskell scheinbar mehrere Argumente einer Funktion übergeben, steckt immer Currying dahinter. Es erzeugt eine Reihe von (Zwischen-)Funktionen mit jeweils einem Argument und evaluiert diese dann schrittweise.}{So, if we seemingly pass multiple arguments into a function, then that's always currying in disguise. It create those (intermediate) functions, all with one argument only, and then evaluates them stepwise.} \ No newline at end of file +\ifger{Auf der anderen Seite ist Funktionsanwendung \emph{links}-assoziativ, d.h.}{On the other hand function application is \emph{left}-associative, so} \hinline{f 3 2} \ifger{ist nur die Kurzform für}{is just a shorthand of} \hinline{(f 3) 2}. \ No newline at end of file diff --git a/VL2/content/VL2_currying6.2.tex b/VL2/content/VL2_currying6.2.tex deleted file mode 100644 index 0cc6a52..0000000 --- a/VL2/content/VL2_currying6.2.tex +++ /dev/null @@ -1,15 +0,0 @@ -\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} \ No newline at end of file diff --git a/VL2/content/VL2_currying6.tex b/VL2/content/VL2_currying6.tex index 69f0355..ae8ea9a 100644 --- a/VL2/content/VL2_currying6.tex +++ b/VL2/content/VL2_currying6.tex @@ -3,12 +3,16 @@ \begin{haskellcode} addInt :: Int -> Int -> Int addInt x y = x + y +-- which is equivalent to this as we already know +addInt = \x -> (\y -> x + y) addTwo :: Int -> Int addTwo = addInt 2 +-- equivalent to +addTwo = \y -> addInt 2 y \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. +\ifger{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. +Oder in anderen Worten: wir haben der Zwischenfunktion, die Currying für uns erstellt hat, lediglich den Namen \hinline{addTwo} gegeben.}{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 argument 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}\\ \ No newline at end of file