Programming with F#❘1159
The four static members on this type provide a convenient way to construct values of this type, but still adhering to the constraint that any expression must be quantifi ed with the same unit. So, the following will not work:
As you saw earlier in this chapter, sequences provide one important way to express lazy
computations as sequences of elements that are enumerated on demand, and indeed this is suffi cient to model most scenarios with the need of lazy evaluation. The other most readily available way is to use Lazy values directly.
let a = lazy (LongRunningComputation ())
This is roughly equivalent to defi ning lazyResult as shown earlier, in the sense that it must be “ pinged ” to evaluate the lazy computation it carries. You can accomplish that by invoking the Value member:
Language Integrated Queries (LINQ) in C# and VB have received quite a bit of attention since their introduction and incorporation into those languages. The general idea of LINQ is to give you typed query access to various data sources using the same (language integrated) query language. Various SQL - like constructs were then added to C# and VB to utilize LINQ, including from , select , where , and so on.
Underneath the covers, when you use LINQ queries in C# or VB, the LINQ extensions to the compiler take care of translating those queries to expression trees , which are then evaluated at run - time and converted to various alternate representations and executed.
val q2 : Expr < int > =
Call (None, Int32 op_Addition[Int32,Int32,Int32](Int32, Int32), [Value (1), Value (2)])
> let q1 =
< @ let add x y = x+y
add 10 20 @ > ;;