F#, like most programming languages, uses Strict Evaluation by default. In Strict Evaluation, computations are executed immediately. In contrast, Lazy Evaluation, defers execution of computations until their results are needed. Moreover, the results of a computation under Lazy Evaluation are cached, thereby obviating the need for the re-evaluation of an expression.
We can use Lazy evaluation in F# through both the lazy
keyword and Sequences
// 23 * 23 is not evaluated here
// lazy keyword creates lazy computation whose evaluation is deferred
let x = lazy(23 * 23)
// we need to force the result
let y = x.Force()
// Hello World not printed here
let z = lazy(printfn "Hello World\n"; 23424)
// Hello World printed and 23424 returned
let ans1 = z.Force()
// Hello World not printed here as z as already been evaluated, but 23424 is
// returned
let ans2 = z.Force()