liveBook · Manning

Nested tuple

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

A nested tuple is a tuple containing another tuple as one of its elements.

A nested tuple groups one tuple inside another. Parentheses distinguish the grouped inner values from sibling elements in the outer tuple. section 5.2.2

Grouping a name and age

let nameAndAge = ("Joe", "Bloggs"), 28 let name, age = nameAndAge let (forename, surname), theAge = nameAndAge The first pattern binds the inner tuple as one value; the second deconstructs both levels. section 5.2.2

Use nested tuples when related values should remain grouped:

  • Return a two-part result, such as a forename/surname tuple alongside an age and category. section 5.2.2

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

How deep it goes
Explains construction and two-level deconstruction, then stops short of broader tuple runtime representation.
Examples
Demonstrates a nested name-and-age value and an exercise returning personal details with an age category.
What it assumes
Assumes ordinary tuple construction and deconstruction, while teaching nested grouping through parentheses.
What you can do after
Build it from scratch by grouping tuple elements and deconstructing nested results in F#.
How it connects
Connects nested tuples with tuple construction, tuple deconstruction, type annotations, and value tuples.

Also explained in

Compare how 2 books explain nested tuple →

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.