Array.init<'T> Function
Collapse the table of content
Expand the table of content

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


Type: int

The number of elements to initialize.


Type: int -> 'T

The function to generate the initial values for each index.

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

F# Core Library Versions

Supported in: 2.0, 4

© 2016 Microsoft