liveBook · Manning

Currying

As explained in F# in Action: A Revised Edition of Get Programming with F#

A curried function is a function represented as a sequence of single-argument functions, allowing arguments to be supplied incrementally.

Currying represents a function as a sequence of single-argument functions. Supplying one argument returns a new function that accepts the next, while supplying all arguments at once remains valid. section 6.1.1 section 6.4

Build a specialized function

let add (firstNumber:int) (secondNumber:int) = firstNumber + secondNumber let addFive = add 5 let fifteen = addFive 10 Here, addFive remembers 5 and waits for the remaining number. The same pattern can specialize an email sender: let sendEmailToFred = sendEmail "fred@email.com". section 6.1.1 section 6.1.2

Currying is useful when you want to:

  • Inject stable arguments once, then reuse the returned function with changing values. section 6.4
  • Replace boilerplate associated with manually constructing partially configured objects or functions. section 6.1.1 section 6.1.2
  • Compose naturally with pipelines and F# functions, which support partial application and full type inference. section 6.1.6 section 6.4
Listing 6.2 Calling an F# function
let add (firstNumber:int) (secondNumber:int) =   #1
    firstNumber + secondNumber 
let addFive = add 5                              #2
let fifteen = addFive 10                         #3

Inspect the staged add, addFive, and fifteen calls as a compact model of incremental argument application. section 6.1.1

How F# in Action: A Revised Edition of Get Programming with F# covers it

How deep it goes
Explains staged application, signatures, partial application, and practical benefits without descending into formal functional-programming theory.
Examples
Demonstrates arithmetic specialization with addFive and domain modeling with a reusable email sender.
What it assumes
Teaches the behavior through basic F# function definitions, signatures, and calls rather than assuming formal functional-programming theory.
What you can do after
Apply it via F# to create reusable specialized functions and call multi-argument functions incrementally or all at once.
How it connects
Connects currying with partial application, pipelines, type inference, tuples, records, modules, and functions.

Also explained in

Compare how 7 books explain currying →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of F# in Action: A Revised Edition of Get Programming with F#. The section links point to the parts of the book it draws on.