liveBook · Manning

Struct annotation

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

A struct annotation is F# syntax using the struct keyword to specify a value-tuple representation in a type expression or construction.

A struct annotation uses F#’s struct keyword to select a value-tuple representation in a type expression or tuple operation. section 5.2.2

Apply the keyword consistently across the tuple’s use:

A struct tuple in a function

let makeDoctor (name : struct (string * string)) = let struct(_, sname) = name struct ("Dr", sname) The function accepts a struct tuple, ignores the forename, and returns a struct tuple containing a title and surname. section 5.2.2

let makeDoctor (name : struct (string * string)) =   #1
    let struct(_, sname) = name                      #2
    struct ("Dr", sname)                             #3
#1 Struct keyword on tuple type annotation
#2 Struct keyword on tuple deconstruction
#3 Struct keyword on tuple construction

Inspect the complete example with the struct keyword marked at the type annotation, deconstruction, and construction sites. section 5.2.2

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

How deep it goes
Shows three required syntax positions and contrasts value tuples with reference tuples, without descending into runtime internals.
Examples
Uses a makeDoctor function that transforms a name tuple into a titled surname tuple.
What it assumes
Builds from ordinary tuple type signatures, inference, and deconstruction before adding struct syntax.
What you can do after
Apply struct syntax consistently when declaring, unpacking, and returning value tuples.
How it connects
Connects struct annotations with tuples, type annotations, tuple deconstruction, System.Tuple, and System.ValueTuple.

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.