jonnifyfsharp

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

C1.03.1 as values C1.03.2 currying C1.03.3 partial application a function is a value supply some, get a function
C1.03.1 · Functions as values

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.

key result List.map square [1; 2; 3] = [1; 4; 9]

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.

live module hub built dive ready soon specified

References

Sources

Related in this course