ExtraTopLevelOperators.Lazy<'T> Active Pattern (F#)

An active pattern to force the execution of values of type Lazy.

Namespace/Module Path: Microsoft.FSharp.Core.ExtraTopLevelOperators

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

// Signature:
( |Lazy| ) : Lazy<'T> -> 'T

input

Type: Lazy<'T>

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

The following code illustrates the use of the Lazy active pattern.

let rec factorial n = match n with 0 | 1 -> 1 | n -> n * (factorial (n-1))
let lazyValue = lazy ( factorial (10) )
// No computation occurs until the match expression executes. 
match lazyValue with
| Lazy value -> printfn "10 factorial is %d" value

Output

10 factorial is 3628800

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

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft