Module C1.03
Functions, currying & partial application
A function is a value, it takes one argument, and the rest follows from those two facts.
In F# a function is a value — bind it to a name, pass it to another function, return it from one. And every F# function takes exactly one argument: a function that looks like it takes two takes the first and returns a function that takes the second. That shape is called currying, and it is what makes partial application — supplying some arguments now and the rest later — fall out for free. This module covers the three in order: functions as values, currying, then partial application.
One idea, taken apart in three steps
The three dives build on each other. The first establishes that a function is an ordinary value: it can be
named, passed, and returned, like an integer or a string. The second shows currying — why a
function written with two parameters is really a function of one that returns a function of one — and reads
the type int -> int -> int the way F# means it. The third puts the two
together: supply one argument to a curried function and a new, specialised function comes back, ready for the
pipe.
Select a dive below to read its one-line summary and the result it works through. Each example is valid F# that type-checks and evaluates as written.
The three dives · select one
A function binding and a lambda are both values: bind one to a name, pass one as an argument, return one. Higher-order functions are the whole point.
Open this dive · or pick another above
A value, one argument, and the rest later: three small facts that together explain how F# code is shaped.
The three dives
Read them in order. Each stands on valid, runnable F# — the binding, the type signature, and the result the F# Interactive prints.
Functions as values
Bindings and lambdas are values; pass them in, return them out — higher-order functions.
- valuea function is data you can name, pass, and return
Currying
Every F# function takes one argument; int -> int -> int means int -> (int -> int).
- arrowthe type associates right; application associates left
Partial application
Supply some arguments now; a new, specialised function comes back, ready for the pipe.
- pipedata-last makes
List.map (add 10)natural
References
Sources
- Microsoft — F# documentation — functions, currying, and partial application in F#.
- The F# Language Specification — the definitive account of function types and application.
- FSharp.Core API reference —
List.mapand the data-last collection functions.
Related in this course
- C1.03.1 — Functions as values — the first dive, where the module begins.
- C1 — F# Language — the chapter this module sits in.
- Elixir — Functions — first-class functions and anonymous functions, told for the BEAM.