Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

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

Creates a list by calling the given generator on each index.

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

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

// Signature:
List.init : int -> (int -> 'T) -> 'T list

// Usage:
List.init length initializer


Type: int

The length of the list to generate.


Type: int -> 'T

The function to generate an element from an index.

The list of generated elements.

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 shows how to use List.init.

printfn "List of squares: %A" (List.init 10 (fun index -> index * index))


List 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.0, Portable

© 2015 Microsoft