liveBook · Manning

Type argument

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

A generic type argument is a concrete type supplied for a parameterized generic type or function.

A type argument is the concrete type supplied to a generic type or function. In F#, angle brackets make an explicit argument visible, as in ResizeArray<int>(), while inference can often determine the type from later usage. section 3.2.3

F# supports several ways to express or infer a generic type argument:

  • ResizeArray<int>() explicitly creates a collection of integers. section 3.2.3
  • ResizeArray<_>() leaves a type hole for the compiler to resolve. section 3.2.3
  • ResizeArray() can infer its element type from operations such as Add; without usable context, inference may require an annotation. section 3.2.3
  • A generic function can declare 'T and accept an explicit call such as combineElements<int> 1 2 3. section 3.2.3

Inference and uniform element types

let combineElements a b c = let output = ResizeArray() output.Add a output.Add b output.Add c output combineElements 1 2 3 Automatic generalization lets this function work with integers, strings, or user-defined types, but its arguments must share one inferred type. Combining 1, 2, and "test" produces a type error rather than enabling dynamic mixing. section 3.2.3

mapping : ('T -> 'U) -> 'T list -> 'U list

The List.map signature shows generic arguments 'T and 'U: a mapping function transforms a 'T list into a 'U list, with concrete types determined by use. section 7.2.3

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

How deep it goes
Explains explicit arguments, type holes, inference, automatic generalization, and the error produced by incompatible argument types.
Examples
Demonstrates ResizeArray, combineElements, mixed-type errors, and List.map from int list to string list.
What you can do after
Apply it via F# syntax, choose explicit annotations when inference lacks context, and read generic function signatures.
How it connects
Connects type arguments with generics, type inference, automatic generalization, higher-order functions, and List.map.

Also explained in

Compare how 5 books explain type argument →

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.