Array.init<'T> Function (F#)

Creates an array given the dimension and a generator function to compute the elements.

Namespace/Module Path: Microsoft.FSharp.Collections.Array

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
Array.init : int -> (int -> 'T) -> 'T []

// Usage:
Array.init count initializer


  • count
    Type: int

    The number of elements to initialize.

  • initializer
    Type: int -> 'T

    The function to generate the initial values for each index.

Return Value

The created array.


This function is named Initialize in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.


The following code demonstrates the use of Array.init.

printfn "Array of squares: %A" (Array.init 10 (fun index -> index * index))
Array of squares: [|0; 1; 4; 9; 16; 25; 36; 49; 64; 81|]


Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 2.0, 4

See Also


Collections.Array Module (F#)

Microsoft.FSharp.Collections Namespace (F#)