27 people like it.

Using the 'lazy' Keyword

This snippet uses the lazy keyword to create a delayed computation. It then show's using 'force' to evaluate the computation.

1: 
2: 
3: 
4: 
let lazyValue = lazy ( 2 + 2 )
let actualValue = Lazy.force lazyValue

printfn "%i" actualValue
val lazyValue : Lazy<int>

Full name: Script.lazyValue
val actualValue : int

Full name: Script.actualValue
Multiple items
active recognizer Lazy: Lazy<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.( |Lazy| )

--------------------
type Lazy<'T> = System.Lazy<'T>

Full name: Microsoft.FSharp.Control.Lazy<_>
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Raw view Test code New version

More information

Link:http://fssnip.net/x
Posted:13 years ago
Author:Robert Pickering
Tags: lazy