Browse Source

Improve currying slides

master
Julian Ospald 9 years ago
parent
commit
686f4fc438
No known key found for this signature in database GPG Key ID: 220CD1C5BDEED020
5 changed files with 19 additions and 21 deletions
  1. +1
    -1
      VL2/VL2_document_structure.tex
  2. +10
    -0
      VL2/content/VL2_currying5.1.tex
  3. +2
    -4
      VL2/content/VL2_currying5.tex
  4. +0
    -14
      VL2/content/VL2_currying6.2.tex
  5. +6
    -2
      VL2/content/VL2_currying6.tex

+ 1
- 1
VL2/VL2_document_structure.tex View File

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


+ 10
- 0
VL2/content/VL2_currying5.1.tex View File

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

+ 2
- 4
VL2/content/VL2_currying5.tex View File

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

+ 0
- 14
VL2/content/VL2_currying6.2.tex View File

@@ -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
addTwo x = (addInt 2) x
\end{haskellcode}

+ 6
- 2
VL2/content/VL2_currying6.tex View File

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

Loading…
Cancel
Save