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
