liveBook · Manning

ResizeArray

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

ResizeArray is an F# type alias for a dynamically resizing .NET generic list.

ResizeArray is F#’s alias for System.Collections.Generic.List<'T>, a mutable .NET collection that grows automatically when items are added. It stores one generic type and avoids manually managing array capacity. section 3.2.3 section 7.3.3

let explicit = ResizeArray<int>()    #1
let typeHole = ResizeArray<_>()      #2
let omitted = ResizeArray()          #3
 
typeHole.Add 99                      #4
omitted.Add 10                       #4

Compare explicit generic arguments, an inference placeholder, and omitted type information while adding integers. section 3.2.3

Choose the declaration style that matches how much type information the compiler can safely infer:

  • ResizeArray<int>() states the element type explicitly. section 3.2.3
  • ResizeArray<_>() leaves a type hole that later usage can resolve. section 3.2.3
  • ResizeArray() can infer its type from calls such as Add; without usable evidence, annotations may be required. section 3.2.3
  • Generic functions can construct a ResizeArray for values sharing one inferred type. section 3.2.3

Collecting values imperatively

let numbers = ResizeArray<int>() numbers.Add 10 numbers.Add 20 for number in numbers do printfn "%d" number Use ResizeArray when incremental Add operations or mutable updates fit the task. For transformations and pipelines, F# List offers immutable operations; ResizeArray has no dedicated function module, so use Seq or LINQ when needed. section 7.3.3 section 7.2.1

A ResizeArray expands by creating a larger underlying array and copying existing items. This makes insertion convenient, but collection processing may be less direct than with pipeline-oriented immutable lists. section 7.3.3 section 7.2.1

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

How deep it goes
Defines the alias, generic inference, resizing copy behavior, and module limitation, but does not detail capacity policies.
Examples
Uses integer collections, inferred generic arguments, a generic combining function, and an imperative team-summary query.
What it assumes
Assumes basic F# collection syntax while teaching generic arguments, type inference, and automatic resizing through small examples.
What you can do after
Build it from scratch, choose explicit or inferred element types, add values, and select Seq or LINQ for processing.
How it connects
Connects ResizeArray with .NET generics, System.Collections.Generic.List, Array, Seq, LINQ, and immutable F# List.

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.