Chapter 3Elementary Discrete Mathslides.en.pdf:167-170

Currying & Notations

f(a,b) → f(a)(b); prefix, postfix, infix

Def 4.3CurryingDef 4.8λ-notationDef 4.6Fixity
Concept

Currying transforms an nn-ary function into a chain of unary functions.

curry(f):A1(A2((AnB)))\text{curry}(f): A_1 \to (A_2 \to (\dots \to (A_n \to B)))

Instead of f(a,b,c)f(a, b, c), you write f(a)(b)(c)f(a)(b)(c) — apply one argument at a time.

Why? Each partial application can be stored, reused, or passed around.
Adding 3 to a number is a function that waits for the second argument.

λ-notation: λxX.E\lambda x \in X. E is the function {(x,E)xX}\{(x, E) \mid x \in X\}.
In SML: fn x => E.

Fixity / notation styles:
- Prefix: f(a,b)f(a, b) — function before arguments
- Postfix: a!a! — function after argument
- Infix: a+ba + b — function between arguments (used for binary ops)
- Circumfix: (a,b)(a, b) — function wraps argument

Animation — currying
Transcript — click a line to jump8 cues
  1. 0.0sCurrying: Cartesian to Cascaded
  2. 1.3sCartesian form on the left: (x, y) maps to x + y
  3. 2.6sCascaded form on the right: x maps to y maps to x + y
  4. 5.6sThe comma flashes amber in the Cartesian form
  5. 6.2sThe single arrow flashes amber
  6. 6.8sBoth arrows flash amber in the cascaded form
  7. 7.9sA double-headed arrow says the two forms are equivalent
  8. 9.1sTwo equivalent ways to write a 2-argument function
Practice — score 100% to advance
Multiple choice
Q1
What is currying?
Q2
In λx.x+1\lambda x. x + 1, what is xx?
Q3
In SML, what is the expression fn x => x + 1?
Q4
Which notation is infix?
Q5
In SML, what is add 3 (where add takes two args)?
Loading…