FSharp.Core


Expr Type

Quoted expressions annotated with System.Type values.

Instance members

Instance member Description

this.CustomAttributes

Full Usage: this.CustomAttributes

Returns: Expr list

Returns the custom attributes of an expression. For quotations deriving from quotation literals this may include the source location of the literal.

Returns: Expr list
Example

 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let sampleQuotation =  <@ 1 + 1 @>

 sampleQuotation.CustomAttributes
Evaluates to a list of expressions containing one custom attribute for the source location of the quotation literal.

this.GetFreeVars

Full Usage: this.GetFreeVars

Returns: seq<Var> A sequence of the free variables in the expression.

Gets the free expression variables of an expression as a list.

Returns: seq<Var>

A sequence of the free variables in the expression.

Example

 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let sampleQuotation =  <@ fun v -> v * v @>

 let v, body =
     match sampleQuotation with
     | Lambda(v, body) -> (v, body)
     | _ -> failwith "unreachable"

 body.GetFreeVars()
Evaluates to a set containing the single variable for v

this.Substitute

Full Usage: this.Substitute

Parameters:
    substitution : Var -> Expr option - The function to map variables into expressions.

Returns: Expr The expression with the given substitutions.

Substitutes through the given expression using the given functions to map variables to new values. The functions must give consistent results at each application. Variable renaming may occur on the target expression if variable capture occurs.

substitution : Var -> Expr option

The function to map variables into expressions.

Returns: Expr

The expression with the given substitutions.

Example

 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let sampleQuotation =  <@ fun v -> v * v @>

 let v, body =
     match sampleQuotation with
     | Lambda(v, body) -> (v, body)
     | _ -> failwith "unreachable"

 body.Substitute(function v2 when v = v2 -> Some <@ 1 + 1 @> | _ -> None)
Evaluates to <@ (1 + 1) * (1 + 1)>.

this.ToString

Full Usage: this.ToString

Parameters:
    full : bool - Indicates if method, property, constructor and type objects should be printed in detail. If false, these are abbreviated to their name.

Returns: string The formatted string.

Format the expression as a string

full : bool

Indicates if method, property, constructor and type objects should be printed in detail. If false, these are abbreviated to their name.

Returns: string

The formatted string.

Example

 open FSharp.Quotations

 let expr1 = <@ 1 + 1 @>

 expr1.ToString(true)
Evaluates "Call (None, Int32 op_Addition[Int32,Int32,Int32](Int32, Int32),[Value (1), Value (1)])".

this.Type

Full Usage: this.Type

Returns: Type

Returns type of an expression.

Returns: Type
Example

 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let sampleQuotation =  <@ 1 + 1 @>

 sampleQuotation.Type
Evaluates to typeof<int>.

Static members

Static member Description

Expr.AddressOf(target)

Full Usage: Expr.AddressOf(target)

Parameters:
    target : Expr - The target expression.

Returns: Expr The resulting expression.

Builds an expression that represents getting the address of a value.

target : Expr

The target expression.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 let array = [| 1; 2; 3 |]
 
 Expr.AddressOf(<@ array.[1] @>)
Evaluates to AddressOf (Call (None, GetArray, [PropertyGet (None, array, []), Value (1)])).

Expr.AddressSet(target, value)

Full Usage: Expr.AddressSet(target, value)

Parameters:
    target : Expr - The target expression.
    value : Expr - The value to set at the address.

Returns: Expr The resulting expression.

Builds an expression that represents setting the value held at a particular address.

target : Expr

The target expression.

value : Expr

The value to set at the address.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 let array = [| 1; 2; 3 |]
 
 let addrExpr = Expr.AddressOf(<@ array.[1] @>)
 
 Expr.AddressSet(addrExpr, <@ 4 @>)
Evaluates to AddressSet (AddressOf (Call (None, GetArray, [PropertyGet (None, array, []), Value (1)])), Value (4)).

Expr.Application(functionExpr, argument)

Full Usage: Expr.Application(functionExpr, argument)

Parameters:
    functionExpr : Expr - The function to apply.
    argument : Expr - The argument to the function.

Returns: Expr The resulting expression.

Builds an expression that represents the application of a first class function value to a single argument.

functionExpr : Expr

The function to apply.

argument : Expr

The argument to the function.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 let funcExpr = <@ (fun x -> x + 1) @>
 let argExpr = <@ 3 @>

 Expr.Application(funcExpr, argExpr)
Evaluates to a quotation with the same structure as <@ (fun x -> x + 1) 3 @>.

Expr.Applications(functionExpr, arguments)

Full Usage: Expr.Applications(functionExpr, arguments)

Parameters:
    functionExpr : Expr - The function to apply.
    arguments : Expr list list - The list of lists of arguments to the function.

Returns: Expr The resulting expression.

Builds an expression that represents the application of a first class function value to multiple arguments

functionExpr : Expr

The function to apply.

arguments : Expr list list

The list of lists of arguments to the function.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 let funcExpr = <@ (fun (x, y) z -> x + y + z) @>
 let curriedArgExprs = [[ <@ 1 @>; <@ 2 @> ]; [ <@ 3 @> ]]

 Expr.Applications(funcExpr, curriedArgExprs)
Evaluates to a quotation with the same structure as <@ (fun (x, y) z -> x + y + z) (1,2) 3 @>.

Expr.Call(obj, methodInfo, arguments)

Full Usage: Expr.Call(obj, methodInfo, arguments)

Parameters:
    obj : Expr - The input object.
    methodInfo : MethodInfo - The description of the method to call.
    arguments : Expr list - The list of arguments to the method.

Returns: Expr The resulting expression.

Builds an expression that represents a call to an instance method associated with an object

obj : Expr

The input object.

methodInfo : MethodInfo

The description of the method to call.

arguments : Expr list

The list of arguments to the method.

Returns: Expr

The resulting expression.

Example

 open System
 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let objExpr, methInfo =
     match <@ Console.Out.WriteLine("1") @> with
     | Call(Some obj, mi, _) -> obj, mi
     | _ -> failwith "call expected"

 let argExpr = <@ "Hello World" @>

 Expr.Call(objExpr, methInfo, [argExpr])
Evaluates to a quotation with the same structure as <@ Console.Out.WriteLine("Hello World") @>.

Expr.Call(methodInfo, arguments)

Full Usage: Expr.Call(methodInfo, arguments)

Parameters:
    methodInfo : MethodInfo - The MethodInfo describing the method to call.
    arguments : Expr list - The list of arguments to the method.

Returns: Expr The resulting expression.

Builds an expression that represents a call to an static method or module-bound function

methodInfo : MethodInfo

The MethodInfo describing the method to call.

arguments : Expr list

The list of arguments to the method.

Returns: Expr

The resulting expression.

Example

 open System
 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let methInfo =
     match <@ Console.WriteLine("1") @> with
     | Call(_, mi, _) -> mi
     | _ -> failwith "call expected"

 let argExpr = <@ "Hello World" @>

 Expr.Call(methInfo, [argExpr])
Evaluates to a quotation with the same structure as <@ Console.WriteLine("Hello World") @>.

Expr.CallWithWitnesses(obj, methodInfo, methodInfoWithWitnesses, witnesses, arguments)

Full Usage: Expr.CallWithWitnesses(obj, methodInfo, methodInfoWithWitnesses, witnesses, arguments)

Parameters:
    obj : Expr - The input object.
    methodInfo : MethodInfo - The description of the method to call.
    methodInfoWithWitnesses : MethodInfo - The additional MethodInfo describing the method to call, accepting witnesses.
    witnesses : Expr list - The list of witnesses to the method.
    arguments : Expr list - The list of arguments to the method.

Returns: Expr The resulting expression.

Builds an expression that represents a call to an instance method associated with an object, potentially passing additional witness arguments

obj : Expr

The input object.

methodInfo : MethodInfo

The description of the method to call.

methodInfoWithWitnesses : MethodInfo

The additional MethodInfo describing the method to call, accepting witnesses.

witnesses : Expr list

The list of witnesses to the method.

arguments : Expr list

The list of arguments to the method.

Returns: Expr

The resulting expression.

Example

See examples for Call and CallWithWitnesses

Expr.CallWithWitnesses(methodInfo, methodInfoWithWitnesses, witnesses, arguments)

Full Usage: Expr.CallWithWitnesses(methodInfo, methodInfoWithWitnesses, witnesses, arguments)

Parameters:
    methodInfo : MethodInfo - The MethodInfo describing the method to call.
    methodInfoWithWitnesses : MethodInfo - The additional MethodInfo describing the method to call, accepting witnesses.
    witnesses : Expr list - The list of witnesses to the method.
    arguments : Expr list - The list of arguments to the method.

Returns: Expr The resulting expression.

Builds an expression that represents a call to an static method or module-bound function, potentially passing additional witness arguments

methodInfo : MethodInfo

The MethodInfo describing the method to call.

methodInfoWithWitnesses : MethodInfo

The additional MethodInfo describing the method to call, accepting witnesses.

witnesses : Expr list

The list of witnesses to the method.

arguments : Expr list

The list of arguments to the method.

Returns: Expr

The resulting expression.

Example

In this example, we show how to use a witness to cosntruct an `op_Addition` call for a type that doesn't support addition directly:

 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 // Get the entrypoint for inline addition that takes an explicit witness
 let addMethInfoG, addMethInfoGW =
     match <@ 1+1 @> with
     | CallWithWitnesses(None, mi, miW, _, _) ->
         mi.GetGenericMethodDefinition(), miW.GetGenericMethodDefinition()
     | _ ->
         failwith "call expected"
 
 // Make a non-standard witness for addition for a type C

 type C(value: int) =
     member x.Value = value

 let witnessExpr = <@ (fun (x: C) (y: C) -> C(x.Value + y.Value)) @>
 let argExpr1 = <@ C(4) @>
 let argExpr2 = <@ C(5) @>

 // Instantiate the generic method at the right type

 let addMethInfo = addMethInfoG.MakeGenericMethod(typeof<C>, typeof<C>, typeof<C>)
 let addMethInfoW = addMethInfoGW.MakeGenericMethod(typeof<C>, typeof<C>, typeof<C>)

 Expr.CallWithWitnesses(addMethInfo, addMethInfoW, [witnessExpr], [argExpr1; argExpr2])
Evaluates to a quotation with the same structure as <@ Call (None, op_Addition, [NewObject (C, Value (4)), NewObject (C, Value (5))]) @>.

Expr.Cast(source)

Full Usage: Expr.Cast(source)

Parameters:
    source : Expr - The expression to cast.

Returns: Expr<'T> The resulting typed expression.

Returns a new typed expression given an underlying runtime-typed expression. A type annotation is usually required to use this function, and using an incorrect type annotation may result in a later runtime exception.

source : Expr

The expression to cast.

Returns: Expr<'T>

The resulting typed expression.

Example

 open FSharp.Quotations

 let rawExpr = <@ 1 @>

 Expr.Cast<int>(rawExpr)
Evaluates with type Expr<int>.

Expr.Coerce(source, target)

Full Usage: Expr.Coerce(source, target)

Parameters:
    source : Expr - The expression to coerce.
    target : Type - The target type.

Returns: Expr The resulting expression.

Builds an expression that represents the coercion of an expression to a type

source : Expr

The expression to coerce.

target : Type

The target type.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 let expr = <@ box "3" @>

 Expr.Coerce(expr, typeof<string>)
Evaluates to a quotation with the same structure as <@ (fun x -> x + 1) 3 @>.

Expr.DefaultValue(expressionType)

Full Usage: Expr.DefaultValue(expressionType)

Parameters:
    expressionType : Type - The type on which the constructor is invoked.

Returns: Expr The resulting expression.

Builds an expression that represents the invocation of a default object constructor

expressionType : Type

The type on which the constructor is invoked.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 Expr.DefaultValue(typeof<int>)
Evaluates to the quotation DefaultValue (Int32).

Expr.Deserialize(qualifyingType, spliceTypes, spliceExprs, bytes)

Full Usage: Expr.Deserialize(qualifyingType, spliceTypes, spliceExprs, bytes)

Parameters:
    qualifyingType : Type - A type in the assembly where the quotation occurs.
    spliceTypes : Type list - The spliced types, to replace references to type variables.
    spliceExprs : Expr list - The spliced expressions to replace references to spliced expressions.
    bytes : byte[] - The serialized form of the quoted expression.

Returns: Expr The resulting expression.

This function is called automatically when quotation syntax (<@ @>) and other sources of quotations are used.

qualifyingType : Type

A type in the assembly where the quotation occurs.

spliceTypes : Type list

The spliced types, to replace references to type variables.

spliceExprs : Expr list

The spliced expressions to replace references to spliced expressions.

bytes : byte[]

The serialized form of the quoted expression.

Returns: Expr

The resulting expression.

Expr.Deserialize40(qualifyingType, referencedTypes, spliceTypes, spliceExprs, bytes)

Full Usage: Expr.Deserialize40(qualifyingType, referencedTypes, spliceTypes, spliceExprs, bytes)

Parameters:
    qualifyingType : Type - A type in the assembly where the quotation occurs.
    referencedTypes : Type[] - The type definitions referenced.
    spliceTypes : Type[] - The spliced types, to replace references to type variables.
    spliceExprs : Expr[] - The spliced expressions to replace references to spliced expressions.
    bytes : byte[] - The serialized form of the quoted expression.

Returns: Expr The resulting expression.

This function is called automatically when quotation syntax (<@ @>) and other sources of quotations are used.

qualifyingType : Type

A type in the assembly where the quotation occurs.

referencedTypes : Type[]

The type definitions referenced.

spliceTypes : Type[]

The spliced types, to replace references to type variables.

spliceExprs : Expr[]

The spliced expressions to replace references to spliced expressions.

bytes : byte[]

The serialized form of the quoted expression.

Returns: Expr

The resulting expression.

Expr.FieldGet(obj, fieldInfo)

Full Usage: Expr.FieldGet(obj, fieldInfo)

Parameters:
    obj : Expr - The input object.
    fieldInfo : FieldInfo - The description of the field to access.

Returns: Expr The resulting expression.

Builds an expression that represents the access of a field of an object

obj : Expr

The input object.

fieldInfo : FieldInfo

The description of the field to access.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let fieldInfo = typeof<int ref>.GetField("contents@")
 let refValue = ref 3
 let refExpr = <@ refValue @>

 Expr.FieldGet(refExpr, fieldInfo)
Evaluates to FieldGet (Some (PropertyGet (None, refValue, [])), contents@). Note that for technical reasons the quotation <@ refValue.contents @> evaluates to a different quotation accessing the contents field via a property.

Expr.FieldGet(fieldInfo)

Full Usage: Expr.FieldGet(fieldInfo)

Parameters:
    fieldInfo : FieldInfo - The description of the field to access.

Returns: Expr The resulting expression.

Builds an expression that represents the access of a static field

fieldInfo : FieldInfo

The description of the field to access.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let fieldInfo = typeof<System.DayOfWeek>.GetField("Monday")

 Expr.FieldGet(fieldInfo)
Evaluates to FieldGet (None, Monday). Note that for technical reasons the quotation <@ System.DayOfWeek.Monday @> evaluates to a different quotation containing a constant enum value Value (Monday).

Expr.FieldSet(obj, fieldInfo, value)

Full Usage: Expr.FieldSet(obj, fieldInfo, value)

Parameters:
    obj : Expr - The input object.
    fieldInfo : FieldInfo - The description of the field to write to.
    value : Expr - The value to set to the field.

Returns: Expr The resulting expression.

Builds an expression that represents writing to a field of an object

obj : Expr

The input object.

fieldInfo : FieldInfo

The description of the field to write to.

value : Expr

The value to set to the field.

Returns: Expr

The resulting expression.

Example

Create an expression setting a reference cell via the public backing field:

 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let fieldInfo = typeof<int ref>.GetField("contents@")
 let refValue = ref 3
 let refExpr = <@ refValue @>
 let valueExpr = <@ 6 @>

 Expr.FieldSet(refExpr, fieldInfo, valueExpr)
Evaluates to FieldSet (Some (PropertyGet (None, refValue, [])), contents@, Value (6)). Note that for technical reasons the quotation <@ refValue.contents <- 6 @> evaluates to a slightly different quotation accessing the contents field via a property.

Expr.FieldSet(fieldInfo, value)

Full Usage: Expr.FieldSet(fieldInfo, value)

Parameters:
    fieldInfo : FieldInfo - The description of the field to write to.
    value : Expr - The value to the set to the field.

Returns: Expr The resulting expression.

Builds an expression that represents writing to a static field

Settable public static fields are rare in F# and .NET libraries, so examples of using this method are uncommon.

fieldInfo : FieldInfo

The description of the field to write to.

value : Expr

The value to the set to the field.

Returns: Expr

The resulting expression.

Expr.ForIntegerRangeLoop(loopVariable, start, endExpr, body)

Full Usage: Expr.ForIntegerRangeLoop(loopVariable, start, endExpr, body)

Parameters:
    loopVariable : Var - The sub-expression declaring the loop variable.
    start : Expr - The sub-expression setting the initial value of the loop variable.
    endExpr : Expr - The sub-expression declaring the final value of the loop variable.
    body : Expr - The sub-expression representing the body of the loop.

Returns: Expr The resulting expression.

Builds a 'for i = ... to ... do ...' expression that represent loops over integer ranges

loopVariable : Var

The sub-expression declaring the loop variable.

start : Expr

The sub-expression setting the initial value of the loop variable.

endExpr : Expr

The sub-expression declaring the final value of the loop variable.

body : Expr

The sub-expression representing the body of the loop.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 let loopVariable = Var("x", typeof<int>)
 let startExpr = <@ 6 @>
 let endExpr = <@ 7 @>
 let body = <@ System.Console.WriteLine("hello") @>

 Expr.ForIntegerRangeLoop(loopVariable, startExpr, endExpr, body)
Evaluates to a quotation with the same structure as <@ if 1 > 3 then 6 else 7 @>.

Expr.GlobalVar(name)

Full Usage: Expr.GlobalVar(name)

Parameters:
    name : string - The variable name.

Returns: Expr<'T> The created of fetched typed global variable.

Fetches or creates a new variable with the given name and type from a global pool of shared variables indexed by name and type. The type is given by the explicit or inferred type parameter

name : string

The variable name.

Returns: Expr<'T>

The created of fetched typed global variable.

Example

 open FSharp.Quotations

 let expr1 = Expr.GlobalVar<int>("x")
 let expr2 = Expr.GlobalVar<int>("x")
Evaluates expr1 and expr2 to identical quotations.

Expr.IfThenElse(guard, thenExpr, elseExpr)

Full Usage: Expr.IfThenElse(guard, thenExpr, elseExpr)

Parameters:
    guard : Expr - The condition expression.
    thenExpr : Expr - The then sub-expression.
    elseExpr : Expr - The else sub-expression.

Returns: Expr The resulting expression.

Builds 'if ... then ... else' expressions.

guard : Expr

The condition expression.

thenExpr : Expr

The then sub-expression.

elseExpr : Expr

The else sub-expression.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 let guardExpr = <@ 1 > 3 @>
 let thenExpr = <@ 6 @>
 let elseExpr = <@ 7 @>

 Expr.IfThenElse(guardExpr, thenExpr, elseExpr)
Evaluates to a quotation with the same structure as <@ if 1 > 3 then 6 else 7 @>.

Expr.Lambda(parameter, body)

Full Usage: Expr.Lambda(parameter, body)

Parameters:
    parameter : Var - The parameter to the function.
    body : Expr - The body of the function.

Returns: Expr The resulting expression.

Builds an expression that represents the construction of an F# function value

parameter : Var

The parameter to the function.

body : Expr

The body of the function.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let vVar = Var("v", typeof<int>)
 let vExpr = Expr.Var(vVar)

 Expr.Lambda(vVar, vExpr)
Evaluates to Lambda (v, v).

Expr.Let(letVariable, letExpr, body)

Full Usage: Expr.Let(letVariable, letExpr, body)

Parameters:
    letVariable : Var - The variable in the let expression.
    letExpr : Expr - The expression bound to the variable.
    body : Expr - The sub-expression where the binding is in scope.

Returns: Expr The resulting expression.

Builds expressions associated with 'let' constructs

letVariable : Var

The variable in the let expression.

letExpr : Expr

The expression bound to the variable.

body : Expr

The sub-expression where the binding is in scope.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 let vVar = Var("v", typeof<int>)
 let rhsExpr = <@ 6 @>
 let vExpr = Expr.Var(vVar)

 Expr.Let(vVar, rhsExpr, vExpr)
Evaluates to a quotation with the same structure as <@ let v = 6 in v @>.

Expr.LetRecursive(bindings, body)

Full Usage: Expr.LetRecursive(bindings, body)

Parameters:
    bindings : (Var * Expr) list - The list of bindings for the let expression.
    body : Expr - The sub-expression where the bindings are in scope.

Returns: Expr The resulting expression.

Builds recursive expressions associated with 'let rec' constructs

bindings : (Var * Expr) list

The list of bindings for the let expression.

body : Expr

The sub-expression where the bindings are in scope.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let fVar = Var("f", typeof<int -> int>)
 let gVar = Var("v", typeof<int -> int>)
 let fExpr = Expr.Var(fVar)
 let gExpr = Expr.Var(gVar)
 let fImplExpr = <@ fun x -> (%%gExpr : int -> int) (x - 1) + 1 @>
 let gImplExpr = <@ fun x -> if x > 0 then (%%fExpr : int -> int) (x - 1) else 0 @>
 let bodyExpr = <@ (%%gExpr : int -> int) 10 @>

 Expr.LetRecursive([(fVar, fImplExpr); (gVar, gImplExpr)], bodyExpr)
Evaluates to a quotation with the same structure as <@ let rec f x = g (x-1) + 1 and g x = if x > 0 then f (x - 1) else 0 in g 10 @>.

Expr.NewArray(elementType, elements)

Full Usage: Expr.NewArray(elementType, elements)

Parameters:
    elementType : Type - The type for the elements of the array.
    elements : Expr list - The list of elements of the array.

Returns: Expr The resulting expression.

Builds an expression that represents the creation of an array value initialized with the given elements

elementType : Type

The type for the elements of the array.

elements : Expr list

The list of elements of the array.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 Expr.NewArray(typeof<int>, [ <@ 1 @>; <@ 2 @> ])
Evaluates to a quotation with the same structure as <@ [| 1; 2 |] @>.

Expr.NewDelegate(delegateType, parameters, body)

Full Usage: Expr.NewDelegate(delegateType, parameters, body)

Parameters:
    delegateType : Type - The type of delegate.
    parameters : Var list - The parameters for the delegate.
    body : Expr - The body of the function.

Returns: Expr The resulting expression.

Builds an expression that represents the creation of a delegate value for the given type

delegateType : Type

The type of delegate.

parameters : Var list

The parameters for the delegate.

body : Expr

The body of the function.

Returns: Expr

The resulting expression.

Example

 open System
 open FSharp.Quotations

 let vVar = Var("v", typeof<int>)
 let vExpr = Expr.Var(vVar)

 Expr.NewDelegate(typeof<Func<int,int>>, [vVar], vExpr)
Evaluates to a quotation with the same structure as <@ new System.Func<int, int>(fun v -> v) @>.

Expr.NewObject(constructorInfo, arguments)

Full Usage: Expr.NewObject(constructorInfo, arguments)

Parameters:
    constructorInfo : ConstructorInfo - The description of the constructor.
    arguments : Expr list - The list of arguments to the constructor.

Returns: Expr The resulting expression.

Builds an expression that represents the invocation of an object constructor

constructorInfo : ConstructorInfo

The description of the constructor.

arguments : Expr list

The list of arguments to the constructor.

Returns: Expr

The resulting expression.

Example

 open System
 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let ctorInfo =
     match <@ new System.DateTime(100L) @> with
     | NewObject(ci, _) -> ci
     | _ -> failwith "call expected"

 let argExpr = <@ 100000L @>

 Expr.NewObject(ctorInfo, [argExpr])
Evaluates to a quotation with the same structure as <@ NewObject (DateTime, Value (100000L)) @>.

Expr.NewRecord(recordType, elements)

Full Usage: Expr.NewRecord(recordType, elements)

Parameters:
    recordType : Type - The type of record.
    elements : Expr list - The list of elements of the record.

Returns: Expr The resulting expression.

Builds record-construction expressions

recordType : Type

The type of record.

elements : Expr list

The list of elements of the record.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 type R = { Y: int; X: string }

 Expr.NewRecord(typeof<R>, [ <@ 1 @>; <@ "a" @> ])
Evaluates to a quotation with the same structure as <@ { Y = 1; X = "a" } @>.

Expr.NewStructTuple(asm, elements)

Full Usage: Expr.NewStructTuple(asm, elements)

Parameters:
    asm : Assembly - Runtime assembly containing System.ValueTuple definitions.
    elements : Expr list - The list of elements of the tuple.

Returns: Expr The resulting expression.

Builds an expression that represents the creation of an F# tuple value

asm : Assembly

Runtime assembly containing System.ValueTuple definitions.

elements : Expr list

The list of elements of the tuple.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 Expr.NewStructTuple(typeof<struct (int * int)>.Assembly, [ <@ 1 @>; <@ "a" @> ])
Evaluates to a quotation with the same structure as <@ struct (1, "a") @>.

Expr.NewTuple(elements)

Full Usage: Expr.NewTuple(elements)

Parameters:
    elements : Expr list - The list of elements of the tuple.

Returns: Expr The resulting expression.

Builds an expression that represents the creation of an F# tuple value

elements : Expr list

The list of elements of the tuple.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 Expr.NewTuple([ <@ 1 @>; <@ "a" @> ])
Evaluates to a quotation with the same structure as <@ (1, "a") @>.

Expr.NewUnionCase(unionCase, arguments)

Full Usage: Expr.NewUnionCase(unionCase, arguments)

Parameters:
    unionCase : UnionCaseInfo - The description of the union case.
    arguments : Expr list - The list of arguments for the case.

Returns: Expr The resulting expression.

Builds an expression that represents the creation of a union case value

unionCase : UnionCaseInfo

The description of the union case.

arguments : Expr list

The list of arguments for the case.

Returns: Expr

The resulting expression.

Example

 open System
 open FSharp.Quotations
 open FSharp.Reflection

 let ucCons = FSharpType.GetUnionCases(typeof<int list>)[1]

 Expr.NewUnionCase(ucCons, [ <@ 10 @>; <@ [11] @> ])
Evaluates to a quotation with the same structure as <@ 10 :: [11] @>.

Expr.PropertyGet(property, ?indexerArgs)

Full Usage: Expr.PropertyGet(property, ?indexerArgs)

Parameters:
    property : PropertyInfo - The description of the property.
    ?indexerArgs : Expr list - List of indices for the property if it is an indexed property.

Returns: Expr The resulting expression.

Builds an expression that represents reading a static property

property : PropertyInfo

The description of the property.

?indexerArgs : Expr list

List of indices for the property if it is an indexed property.

Returns: Expr

The resulting expression.

Example

 open System
 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let propInfo =
     match <@ Console.Out @> with
     | PropertyGet(None, pi, _) -> pi
     | _ -> failwith "property get expected"

 Expr.PropertyGet(propInfo)
Evaluates to a quotation with the same structure as <@ Console.Out @>.

Expr.PropertyGet(obj, property, ?indexerArgs)

Full Usage: Expr.PropertyGet(obj, property, ?indexerArgs)

Parameters:
    obj : Expr - The input object.
    property : PropertyInfo - The description of the property.
    ?indexerArgs : Expr list - List of indices for the property if it is an indexed property.

Returns: Expr The resulting expression.

Builds an expression that represents reading a property of an object

obj : Expr

The input object.

property : PropertyInfo

The description of the property.

?indexerArgs : Expr list

List of indices for the property if it is an indexed property.

Returns: Expr

The resulting expression.

Example

 open System
 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let propInfo =
     match <@ "a".Length @> with
     | PropertyGet(Some _, pi, _) -> pi
     | _ -> failwith "property get expected"

 let objExpr = <@ "bb" @>

 Expr.PropertyGet(objExpr, propInfo)
Evaluates to a quotation with the same structure as <@ "bb".Length @>.

Expr.PropertySet(property, value, ?indexerArgs)

Full Usage: Expr.PropertySet(property, value, ?indexerArgs)

Parameters:
    property : PropertyInfo - The description of the property.
    value : Expr - The value to set.
    ?indexerArgs : Expr list - List of indices for the property if it is an indexed property.

Returns: Expr The resulting expression.

Builds an expression that represents writing to a static property

property : PropertyInfo

The description of the property.

value : Expr

The value to set.

?indexerArgs : Expr list

List of indices for the property if it is an indexed property.

Returns: Expr

The resulting expression.

Example

 open System
 open System.Collections.Generic
 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let propInfo =
     match <@ Console.BackgroundColor <- ConsoleColor.Red  @> with
     | PropertySet(None, pi, _, _) -> pi
     | _ -> failwith "property get expected"

 Expr.PropertySet(propInfo, <@ ConsoleColor.Blue @>)
Evaluates to a quotation with the same structure as <@ Console.BackgroundColor <- ConsoleColor.Blue @>.

Expr.PropertySet(obj, property, value, ?indexerArgs)

Full Usage: Expr.PropertySet(obj, property, value, ?indexerArgs)

Parameters:
    obj : Expr - The input object.
    property : PropertyInfo - The description of the property.
    value : Expr - The value to set.
    ?indexerArgs : Expr list - List of indices for the property if it is an indexed property.

Returns: Expr The resulting expression.

Builds an expression that represents writing to a property of an object

obj : Expr

The input object.

property : PropertyInfo

The description of the property.

value : Expr

The value to set.

?indexerArgs : Expr list

List of indices for the property if it is an indexed property.

Returns: Expr

The resulting expression.

Example

 open System
 open System.Collections.Generic
 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 let propInfo =
     match <@ (new List<int>()).Capacity @> with
     | PropertyGet(Some _, pi, _) -> pi
     | _ -> failwith "property get expected"

 let objExpr = <@ (new List<int>()) @>

 Expr.PropertySet(objExpr, propInfo, <@ 6 @>)
Evaluates to a quotation with the same structure as <@ (new List<int>()).Capacity <- 6 @>.

Expr.QuoteRaw(inner)

Full Usage: Expr.QuoteRaw(inner)

Parameters:
    inner : Expr - The expression being quoted.

Returns: Expr The resulting expression.

Builds an expression that represents a nested raw quotation literal

inner : Expr

The expression being quoted.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 Expr.QuoteRaw(<@ 1 @>)
Evaluates to a quotation with the same structure as <@ <@ 1 @> @>.

Expr.QuoteTyped(inner)

Full Usage: Expr.QuoteTyped(inner)

Parameters:
    inner : Expr - The expression being quoted.

Returns: Expr The resulting expression.

Builds an expression that represents a nested typed quotation literal

inner : Expr

The expression being quoted.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 Expr.QuoteTyped(<@ 1 @>)
Evaluates to a quotation with the same structure as <@ <@ 1 @> @>.

Expr.RegisterReflectedDefinitions(assembly, resource, serializedValue, referencedTypes)

Full Usage: Expr.RegisterReflectedDefinitions(assembly, resource, serializedValue, referencedTypes)

Parameters:
    assembly : Assembly - The assembly associated with the resource.
    resource : string - The unique name for the resources being added.
    serializedValue : byte[] - The serialized resource to register with the environment.
    referencedTypes : Type[] - The type definitions referenced.

Permits interactive environments such as F# Interactive to explicitly register new pickled resources that represent persisted top level definitions.

assembly : Assembly

The assembly associated with the resource.

resource : string

The unique name for the resources being added.

serializedValue : byte[]

The serialized resource to register with the environment.

referencedTypes : Type[]

The type definitions referenced.

Expr.RegisterReflectedDefinitions(assembly, resource, serializedValue)

Full Usage: Expr.RegisterReflectedDefinitions(assembly, resource, serializedValue)

Parameters:
    assembly : Assembly - The assembly associated with the resource.
    resource : string - The unique name for the resources being added.
    serializedValue : byte[] - The serialized resource to register with the environment.

Permits interactive environments such as F# Interactive to explicitly register new pickled resources that represent persisted top level definitions.

assembly : Assembly

The assembly associated with the resource.

resource : string

The unique name for the resources being added.

serializedValue : byte[]

The serialized resource to register with the environment.

Expr.Sequential(first, second)

Full Usage: Expr.Sequential(first, second)

Parameters:
    first : Expr - The first expression.
    second : Expr - The second expression.

Returns: Expr The resulting expression.

Builds an expression that represents the sequential execution of one expression followed by another

first : Expr

The first expression.

second : Expr

The second expression.

Returns: Expr

The resulting expression.

Example

 open System
 open FSharp.Quotations

 Expr.Sequential(<@ Console.WriteLine("a") @>, <@ Console.WriteLine("b") @>)
Evaluates to a quotation with the same structure as <@ Console.WriteLine("a"); Console.WriteLine("b") @>.

Expr.TryFinally(body, compensation)

Full Usage: Expr.TryFinally(body, compensation)

Parameters:
    body : Expr - The body of the try expression.
    compensation : Expr - The final part of the expression to be evaluated.

Returns: Expr The resulting expression.

Builds an expression that represents a try/finally construct

body : Expr

The body of the try expression.

compensation : Expr

The final part of the expression to be evaluated.

Returns: Expr

The resulting expression.

Example

 open System
 open FSharp.Quotations

 Expr.TryFinally(<@ 1+1 @>, <@ Console.WriteLine("finally") @>)
Evaluates to a quotation with the same structure as <@ try 1+1 finally Console.WriteLine("finally") @>.

Expr.TryGetReflectedDefinition(methodBase)

Full Usage: Expr.TryGetReflectedDefinition(methodBase)

Parameters:
    methodBase : MethodBase - The description of the method to find.

Returns: Expr option The reflection definition or None if a match could not be found.

Try and find a stored reflection definition for the given method. Stored reflection definitions are added to an F# assembly through the use of the [] attribute.

methodBase : MethodBase

The description of the method to find.

Returns: Expr option

The reflection definition or None if a match could not be found.

Example

 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 [<ReflectedDefinition>]
 let f x = x + 1

 let methInfo =
     match <@ f 1 @> with
     | Call(_, mi, _) -> mi
     | _ -> failwith "call expected"

 Expr.TryGetReflectedDefinition(methInfo)
Evaluates to a quotation with the same structure as <@ fun x -> x + 1 @>, which is the implementation of the method f.

Example

 open FSharp.Quotations
 open FSharp.Quotations.Patterns

 [<ReflectedDefinition>]
 module Methods =
    let f x = (x, x)

 let methInfoGeneric =
     match <@ Methods.f (1, 2) @> with
     | Call(_, mi, _) -> mi.GetGenericMethodDefinition()
     | _ -> failwith "call expected"

 let methInfoAtString = methInfoGeneric.MakeGenericMethod(typeof<string>)

 Expr.TryGetReflectedDefinition(methInfoAtString)
Evaluates to a quotation with the same structure as <@ fun (x: string) -> (x, x) @>, which is the implementation of the generic method f instanatiated at type string.

Expr.TryWith(body, filterVar, filterBody, catchVar, catchBody)

Full Usage: Expr.TryWith(body, filterVar, filterBody, catchVar, catchBody)

Parameters:
    body : Expr - The body of the try expression.
    filterVar : Var -
    filterBody : Expr -
    catchVar : Var - The variable to bind to a caught exception.
    catchBody : Expr - The expression evaluated when an exception is caught.

Returns: Expr The resulting expression.

Builds an expression that represents a try/with construct for exception filtering and catching.

body : Expr

The body of the try expression.

filterVar : Var

filterBody : Expr

catchVar : Var

The variable to bind to a caught exception.

catchBody : Expr

The expression evaluated when an exception is caught.

Returns: Expr

The resulting expression.

Example

 open System
 open FSharp.Quotations

 let exnVar = Var("exn", typeof<exn>)

 Expr.TryWith(<@ 1+1 @>, exnVar, <@ 1 @>, exnVar, <@ 2+2 @>)
Evaluates to a quotation with the same structure as <@ try 1+1 with exn -> 2+2 @>.

Expr.TupleGet(tuple, index)

Full Usage: Expr.TupleGet(tuple, index)

Parameters:
    tuple : Expr - The input tuple.
    index : int - The index of the tuple element to get.

Returns: Expr The resulting expression.

Builds an expression that represents getting a field of a tuple

tuple : Expr

The input tuple.

index : int

The index of the tuple element to get.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 let tupExpr = <@ (1, 2, 3) @>

 Expr.TupleGet(tupExpr, 1)
Evaluates to quotation that displays as TupleGet (NewTuple (Value (1), Value (2), Value (3)), 1).

Expr.TypeTest(source, target)

Full Usage: Expr.TypeTest(source, target)

Parameters:
    source : Expr - The expression to test.
    target : Type - The target type.

Returns: Expr The resulting expression.

Builds an expression that represents a type test.

source : Expr

The expression to test.

target : Type

The target type.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 let obj = box 1

 Expr.TypeTest( <@ obj @>, typeof<int>)
Evaluates to quotation that displays as TypeTest (Int32, PropertyGet (None, obj, [])).

Expr.UnionCaseTest(source, unionCase)

Full Usage: Expr.UnionCaseTest(source, unionCase)

Parameters:
    source : Expr - The expression to test.
    unionCase : UnionCaseInfo - The description of the union case.

Returns: Expr The resulting expression.

Builds an expression that represents a test of a value is of a particular union case

source : Expr

The expression to test.

unionCase : UnionCaseInfo

The description of the union case.

Returns: Expr

The resulting expression.

Example

 open System
 open FSharp.Quotations
 open FSharp.Reflection

 let ucCons = FSharpType.GetUnionCases(typeof<int list>)[1]

 Expr.UnionCaseTest(<@ [11] @>, ucCons)
Evaluates to a quotation that displays as UnionCaseTest (NewUnionCase (Cons, Value (11), NewUnionCase (Empty)), Cons).

Expr.Value(value)

Full Usage: Expr.Value(value)

Parameters:
    value : 'T - The typed value.

Returns: Expr

Builds an expression that represents a constant value

value : 'T

The typed value.

Returns: Expr
Example

 open FSharp.Quotations

 Expr.Value(1)
Evaluates to a quotation with the same structure as <@ 1 @>.

Expr.Value(value, expressionType)

Full Usage: Expr.Value(value, expressionType)

Parameters:
    value : obj - The untyped object.
    expressionType : Type - The type of the object.

Returns: Expr The resulting expression.

Builds an expression that represents a constant value of a particular type

value : obj

The untyped object.

expressionType : Type

The type of the object.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 Expr.Value(box 1, typeof<int>)
Evaluates to a quotation with the same structure as <@ 1 @>.

Expr.ValueWithName(value, expressionType, name)

Full Usage: Expr.ValueWithName(value, expressionType, name)

Parameters:
    value : obj - The untyped object.
    expressionType : Type - The type of the object.
    name : string - The name of the variable.

Returns: Expr The resulting expression.

Builds an expression that represents a constant value of a particular type, arising from a variable of the given name

value : obj

The untyped object.

expressionType : Type

The type of the object.

name : string

The name of the variable.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 Expr.ValueWithName(box 1, typeof<int>, "name")
Evaluates to a quotation with the same structure as <@ 1 @> and associated information that the name of the value is "name".

Expr.ValueWithName(value, name)

Full Usage: Expr.ValueWithName(value, name)

Parameters:
    value : 'T - The typed value.
    name : string - The name of the variable.

Returns: Expr The resulting expression.

Builds an expression that represents a constant value, arising from a variable of the given name

value : 'T

The typed value.

name : string

The name of the variable.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 Expr.ValueWithName(1, "name")
Evaluates to a quotation with the same structure as <@ 1 @> and associated information that the name of the value is "name".

Expr.Var(variable)

Full Usage: Expr.Var(variable)

Parameters:
    variable : Var - The input variable.

Returns: Expr The resulting expression.

Builds an expression that represents a variable

variable : Var

The input variable.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 let vVar = Var("v", typeof<int>)

 Expr.Var(vVar)
Evaluates to a quotation displayed as v.

Expr.VarSet(variable, value)

Full Usage: Expr.VarSet(variable, value)

Parameters:
    variable : Var - The input variable.
    value : Expr - The value to set.

Returns: Expr The resulting expression.

Builds an expression that represents setting a mutable variable

variable : Var

The input variable.

value : Expr

The value to set.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 let vVar = Var("v", typeof<int>, isMutable=true)

 Expr.VarSet(vVar, <@ 5 @>)
Evaluates to a quotation displayed as VarSet (v, Value (5)).

Expr.WhileLoop(guard, body)

Full Usage: Expr.WhileLoop(guard, body)

Parameters:
    guard : Expr - The predicate to control the loop iteration.
    body : Expr - The body of the while loop.

Returns: Expr The resulting expression.

Builds an expression that represents a while loop

guard : Expr

The predicate to control the loop iteration.

body : Expr

The body of the while loop.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 let guardExpr = <@ true @>
 let bodyExpr = <@ () @>

 Expr.WhileLoop(guardExpr, bodyExpr)
Evaluates to a quotation with the same structure as <@ while true do () @>.

Expr.WithValue(value, expressionType, definition)

Full Usage: Expr.WithValue(value, expressionType, definition)

Parameters:
    value : obj - The untyped object.
    expressionType : Type - The type of the object.
    definition : Expr - The definition of the value being quoted.

Returns: Expr The resulting expression.

Builds an expression that represents a value and its associated reflected definition as a quotation

value : obj

The untyped object.

expressionType : Type

The type of the object.

definition : Expr

The definition of the value being quoted.

Returns: Expr

The resulting expression.

Example

 open FSharp.Quotations

 Expr.WithValue(box 1, typeof<int>, <@ 2 - 1 @>)
Evaluates to a quotation that displays as WithValue (1, Call (None, op_Subtraction, [Value (2), Value (1)])).

Expr.WithValue(value, definition)

Full Usage: Expr.WithValue(value, definition)

Parameters:
    value : 'T - The value being quoted.
    definition : Expr<'T> - The definition of the value being quoted.

Returns: Expr<'T> The resulting expression.

Builds an expression that represents a value and its associated reflected definition as a quotation

value : 'T

The value being quoted.

definition : Expr<'T>

The definition of the value being quoted.

Returns: Expr<'T>

The resulting expression.

Example

 open FSharp.Quotations

 Expr.WithValue(1, <@ 2 - 1 @>)
Evaluates to a quotation that displays as WithValue (1, Call (None, op_Subtraction, [Value (2), Value (1)])).