diff --git a/src/fsharp/FSharp.Core/Linq.fsi b/src/fsharp/FSharp.Core/Linq.fsi
index 24f61321b1..1c8b3184af 100644
--- a/src/fsharp/FSharp.Core/Linq.fsi
+++ b/src/fsharp/FSharp.Core/Linq.fsi
@@ -29,7 +29,7 @@ module LeafExpressionConverter =
// certain expression trees are constructed using methods with a signature that expects an
// expression tree of type Expression but are passed an expression tree of type T.
//[]
- val ImplicitExpressionConversionHelper : 'T -> Expression<'T>
+ val ImplicitExpressionConversionHelper: 'T -> Expression<'T>
///
/// When used in a quotation, this function indicates a specific conversion
@@ -38,7 +38,7 @@ module LeafExpressionConverter =
/// This function should not be called directly.
///
//[]
- val MemberInitializationHelper : 'T -> 'T
+ val MemberInitializationHelper: 'T -> 'T
///
/// When used in a quotation, this function indicates a specific conversion
@@ -47,7 +47,7 @@ module LeafExpressionConverter =
/// This function should not be called directly.
///
//[]
- val NewAnonymousObjectHelper : 'T -> 'T
+ val NewAnonymousObjectHelper: 'T -> 'T
///
/// Converts a subset of F# quotations to a LINQ expression, for the subset of LINQ expressions represented by the
@@ -55,7 +55,7 @@ module LeafExpressionConverter =
///
///
///
- val QuotationToExpression : Expr -> Expression
+ val QuotationToExpression: Expr -> Expression
///
/// Converts a subset of F# quotations to a LINQ expression, for the subset of LINQ expressions represented by the
@@ -63,7 +63,7 @@ module LeafExpressionConverter =
///
///
///
- val QuotationToLambdaExpression : Expr<'T> -> Expression<'T>
+ val QuotationToLambdaExpression: Expr<'T> -> Expression<'T>
///
/// Evaluates a subset of F# quotations by first converting to a LINQ expression, for the subset of LINQ expressions represented by the
@@ -71,20 +71,20 @@ module LeafExpressionConverter =
///
///
///
- val EvaluateQuotation : Expr -> obj
+ val EvaluateQuotation: Expr -> obj
///
/// A runtime helper used to evaluate nested quotation literals.
///
///
///
- val SubstHelper : Expr * Var[] * obj[] -> Expr<'T>
+ val SubstHelper: Expr * Var[] * obj[] -> Expr<'T>
///
/// A runtime helper used to evaluate nested quotation literals.
///
///
///
- val SubstHelperRaw : Expr * Var[] * obj[] -> Expr
+ val SubstHelperRaw: Expr * Var[] * obj[] -> Expr
- val internal (|SpecificCallToMethod|_|) : System.RuntimeMethodHandle -> (Expr -> (Expr option * Type list * Expr list) option)
+ val internal (|SpecificCallToMethod|_|): System.RuntimeMethodHandle -> (Expr -> (Expr option * Type list * Expr list) option)
diff --git a/src/fsharp/FSharp.Core/list.fsi b/src/fsharp/FSharp.Core/list.fsi
index ce4270287b..822f52ff7c 100644
--- a/src/fsharp/FSharp.Core/list.fsi
+++ b/src/fsharp/FSharp.Core/list.fsi
@@ -27,6 +27,7 @@ module List =
///
/// let people = ["Kirk"; "Spock"; "McCoy"]
/// let numbers = [1;2]
+ ///
/// people |> List.allPairs numbers
///
/// The sample evaluates to
@@ -98,11 +99,14 @@ module List =
/// type People = {
/// name: string
/// age: int }
+ ///
/// let getAgeAsFloat person = float person.age
+ ///
/// let people =
/// [ { name = "Kirk"; age = 26 }
/// { name = "Spock"; age = 90 }
/// { name = "McCoy"; age = 37 } ]
+ ///
/// people |> List.averageBy getAgeAsFloat // evaluates 51.0
///
///
@@ -129,34 +133,52 @@ module List =
///
///
///
- /// type Happiness = AlwaysHappy | MostOfTheTimeGrumpy
- /// type People = {
- /// name: string
- /// happiness: Happiness }
+ /// type Happiness =
+ /// | AlwaysHappy
+ /// | MostOfTheTimeGrumpy
+ ///
+ /// type People =
+ /// {
+ /// Name: string
+ /// Happiness: Happiness
+ /// }
+ ///
/// let takeJustHappyPersons person =
- /// match person.happiness with
- /// | AlwaysHappy -> Some person.name
+ /// match person.Happiness with
+ /// | AlwaysHappy -> Some person.Name
/// | MostOfTheTimeGrumpy -> None
+ ///
/// let candidatesForTheTrip =
- /// [ { name = "SpongeBob"; happiness = AlwaysHappy }
- /// { name = "Patrick"; happiness = AlwaysHappy }
- /// { name = "Squidward"; happiness = MostOfTheTimeGrumpy } ]
+ /// [ { Name = "SpongeBob"; Happiness = AlwaysHappy }
+ /// { Name = "Patrick"; Happiness = AlwaysHappy }
+ /// { Name = "Squidward"; Happiness = MostOfTheTimeGrumpy } ]
+ ///
/// candidatesForTheTrip |> List.choose takeJustHappyPersons
///
/// The sample evaluates to [ "SpongeBob"; "Patrick" ]
///
///
///
+ /// Using the identity function id (is defined like fun x -> x):
///
- /// // Using the identity function "id" (is defined like fun x -> x)
+ ///
/// let input1 = [ Some 1; None; Some 3; None ]
+ ///
/// input1 |> List.choose id // evaluates [1; 3]
- ///
+ ///
+ ///
+ ///
+ ///
/// let input2: int option list = []
- /// input2 |> List.choose id // evaluates [] (notice that has the type "int list")
- ///
- /// let input3: string option list =[ None; None ]
- /// input3 |> List.choose id // evaluates [] (notice that has the type "string list")
+ ///
+ /// input2 |> List.choose id // evaluates to the empty list
+ ///
+ ///
+ ///
+ ///
+ /// let input3: string option list = [None; None]
+ ///
+ /// input3 |> List.choose id // evaluates to the empty list
///
///
[]
@@ -178,15 +200,16 @@ module List =
/// Evaluates to [[1; 2; 3]; [4; 5; 6]; [7; 8; 9]; [10]] . Please notice the last chunk.
///
///
- /// let output2 = [1 .. 5 ] |> List.chunkBySize 10
+ /// [1 .. 5 ] |> List.chunkBySize 10
///
/// Evaluates to [[1; 2; 3; 4; 5]]
///
///
/// let input : string list = []
- /// let output3 = input |> List.chunkBySize 10
+ ///
+ /// input |> List.chunkBySize 10
///
- /// Evaluates to []. Please notice that has the type string list list.
+ /// Evaluates to []. The result has type string list list.
///
[]
val chunkBySize: chunkSize:int -> list:'T list -> 'T list list
@@ -356,6 +379,7 @@ module List =
///
///
/// let input = [6;1;2;3;1;4;5;5]
+ ///
/// input |> List.distinct
///
/// Evaluates to [6; 1; 2; 3; 4; 5].
@@ -375,7 +399,9 @@ module List =
///
///
/// let isEven x = 0 = x % 2
+ ///
/// let input = [6;1;2;3;1;4;5;5]
+ ///
/// input |> List.distinctBy isEven // evaluates [6; 1]
///
///
@@ -483,6 +509,7 @@ module List =
///
///
/// let input : string list = []
+ ///
/// input |> List.exactlyOne
///
/// Will throw the exception: System.ArgumentException: The input sequence was empty
@@ -579,7 +606,9 @@ module List =
///
///
/// let isEven x = 0 = x % 2
+ ///
/// let isGreaterThan x y = y > x
+ ///
/// let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"]
///
/// input |> List.find (fun (x,_) -> isEven x) // evaluates (2, "Kirk")
@@ -603,7 +632,9 @@ module List =
///
///
/// let isEven x = 0 = x % 2
+ ///
/// let isGreaterThan x y = y > x
+ ///
/// let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"]
///
/// input |> List.findBack (fun (x,_) -> isEven x) // evaluates (4, "Kenobi")
@@ -628,7 +659,9 @@ module List =
///
///
/// let isEven x = 0 = x % 2
+ ///
/// let isGreaterThan x y = y > x
+ ///
/// let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"]
///
/// input |> List.findIndex (fun (x,_) -> isEven x) // evaluates 1
@@ -653,7 +686,9 @@ module List =
///
///
/// let isEven x = 0 = x % 2
+ ///
/// let isGreaterThan x y = y > x
+ ///
/// let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"]
///
/// input |> List.findIndexBack (fun (x,_) -> isEven x) // evaluates 3
@@ -674,6 +709,7 @@ module List =
///
///
/// let input = [1, "Luke"; 2, "Kirk"; 3, "Kenobi"; 4, "Spock"]
+ ///
/// let isComingFromStarTrek (x,_) = isEven x
///
/// input |> List.filter isComingFromStarTrek
@@ -705,16 +741,19 @@ module List =
/// Shopping for fruits hungry, you tend to take more of each as the hunger grows
///
/// type Fruit = Apple | Pear | Orange
+ ///
/// type BagItem = { fruit: Fruit; quantity: int }
+ ///
/// let takeMore (previous: BagItem list) fruit =
/// let toTakeThisTime =
/// match previous with
/// | bagItem :: otherBagItems -> bagItem.quantity + 1
/// | [] -> 1
/// { fruit = fruit; quantity = toTakeThisTime } :: previous
- /// let input = [ Apple; Pear; Orange ]
+ ///
+ /// let inputs = [ Apple; Pear; Orange ]
///
- /// ([], input) ||> List.fold takeMore
+ /// ([], inputs) ||> List.fold takeMore
///
/// Evaluates to
///
@@ -742,16 +781,16 @@ module List =
/// Count the numer of times the coins match:
/// type CoinToss = Head | Tails
///
- /// let data1 = [Tails; Head; Tails]
- /// let data2 = [Tails; Head; Head]
+ /// let inputs1 = [Tails; Head; Tails]
+ /// let inputs2 = [Tails; Head; Head]
///
- /// (0, data1, data2) |||> List.fold2 (fun acc a b ->
- /// match (a, b) with
+ /// (0, inputs1, inputs2) |||> List.fold2 (fun acc input1 input2 ->
+ /// match (input1, input2) with
/// | Head, Head -> acc + 1
/// | Tails, Tails -> acc + 1
/// | _ -> acc - 1)
///
- /// Evaluates to 1
+ /// Evaluates to 1. Note acc is a commonly used abbreviation for "accumulator".
///
[]
val fold2<'T1,'T2,'State> : folder:('State -> 'T1 -> 'T2 -> 'State) -> state:'State -> list1:'T1 list -> list2:'T2 list -> 'State
@@ -768,20 +807,24 @@ module List =
///
/// Making the sum of squares for the first 5 natural numbers
///
- /// ([1..5], 0) ||> List.foldBack (fun v s -> s + v * v) // evaluates 55
+ /// ([1..5], 0) ||> List.foldBack (fun v acc -> acc + v * v) // evaluates 55
///
+ /// Note acc is a commonly used abbreviation for "accumulator".
///
///
/// Shopping for fruits hungry, you tend to take more of each as the hunger grows
///
/// type Fruit = Apple | Pear | Orange
+ ///
/// type BagItem = { fruit: Fruit; quantity: int }
+ ///
/// let takeMore fruit (previous: BagItem list) =
/// let toTakeThisTime =
/// match previous with
/// | bagItem :: otherBagItems -> bagItem.quantity + 1
/// | [] -> 1
/// { fruit = fruit; quantity = toTakeThisTime } :: previous
+ ///
/// let input = [ Apple; Pear; Orange ]
///
/// (input, []) ||> List.foldBack takeMore
@@ -837,6 +880,7 @@ module List =
/// Negative = 1
/// Text = "(-3,1) (-2,2) (-1,3) " }
///
+ /// Note acc is a commonly used abbreviation for "accumulator".
///
[]
val foldBack2<'T1,'T2,'State> : folder:('T1 -> 'T2 -> 'State -> 'State) -> list1:'T1 list -> list2:'T2 list -> state:'State -> 'State
@@ -1300,6 +1344,7 @@ module List =
/// | Out o -> Out (o*2), acc - o)
///
/// Evaluates newCharges to [In 2; Out 4; In 6] and balance to 2.
+ /// Note acc is a commonly used abbreviation for "accumulator".
///
[]
val mapFold<'T,'State,'Result> : mapping:('State -> 'T -> 'Result * 'State) -> state:'State -> list:'T list -> 'Result list * 'State
@@ -1319,15 +1364,16 @@ module List =
/// | In of int
/// | Out of int
///
- /// let inputs = [ In 1; Out 2; In 3 ]
+ /// let charges = [ In 1; Out 2; In 3 ]
///
/// let newCharges, balance =
- /// (inputs, 0) ||> List.mapFoldBack (fun charge acc ->
+ /// (charges, 0) ||> List.mapFoldBack (fun charge acc ->
/// match charge with
/// | In i -> In (i*2), acc + i
/// | Out o -> Out (o*2), acc - o)
///
/// Evaluates newCharges to [In 2; Out 4; In 6] and balance to 2.
+ /// Note acc is a commonly used abbreviation for "accumulator".
///
[]
val mapFoldBack<'T,'State,'Result> : mapping:('T -> 'State -> 'Result * 'State) -> list:'T list -> state:'State -> 'Result list * 'State
@@ -1736,6 +1782,7 @@ module List =
///
/// Evaluates to [0; 1; -1; 2]. Note 0 is the intial
/// state, 1 the next state, -1 the next state, and 2 the final state.
+ /// Note acc is a commonly used abbreviation for "accumulator".
///
[]
val scan<'T,'State> : folder:('State -> 'T -> 'State) -> state:'State -> list:'T list -> 'State list
@@ -1764,6 +1811,7 @@ module List =
/// Evaluates to [2; 1; 3; 0] by processing each input from back to front. Note 0 is the intial
/// state, 3 the next state, 1 the next state, and 2 the final state, and the states
/// are produced from back to front.
+ /// Note acc is a commonly used abbreviation for "accumulator".
///
[]
val scanBack<'T,'State> : folder:('T -> 'State -> 'State) -> list:'T list -> state:'State -> 'State list
diff --git a/src/fsharp/FSharp.Core/quotations.fsi b/src/fsharp/FSharp.Core/quotations.fsi
index 28f349f357..2e7623b6ce 100644
--- a/src/fsharp/FSharp.Core/quotations.fsi
+++ b/src/fsharp/FSharp.Core/quotations.fsi
@@ -13,24 +13,54 @@ open System.Reflection
///
///
/// Library functionality for F# quotations.
-/// See also F# Code Quotations in the F# Language Guide.
+/// See also F# Code Quotations in the F# Language Guide.
///
[]
[]
type Var =
/// The type associated with the variable
///
- ///
- member Type : Type
+ ///
+ ///
+ /// open FSharp.Quotations
+ /// open FSharp.Quotations.Patterns
+ ///
+ /// match <@ fun v -> v @> with
+ /// | Lambda(v, body) -> v.Type
+ /// | _ -> failwith "unreachable"
+ ///
+ /// Evaluates to typeof<int>
+ ///
+ member Type: Type
/// The declared name of the variable
///
- ///
- member Name : string
+ ///
+ ///
+ /// open FSharp.Quotations
+ /// open FSharp.Quotations.Patterns
+ ///
+ /// match <@ fun v -> v @> with
+ /// | Lambda(v, body) -> v.Name
+ /// | _ -> failwith "unreachable"
+ ///
+ /// Evaluates to "v"
+ ///
+ member Name: string
/// Indicates if the variable represents a mutable storage location
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations
+ /// open FSharp.Quotations.Patterns
+ ///
+ /// match <@ fun v -> v @> with
+ /// | Lambda(v, body) -> v.IsMutable
+ /// | _ -> failwith "unreachable"
+ ///
+ /// Evaluates to false.
+ ///
member IsMutable: bool
/// Creates a new variable with the given name, type and mutability
@@ -41,8 +71,16 @@ type Var =
///
/// The created variable.
///
- ///
- new : name:string * typ:Type * ?isMutable : bool -> Var
+ ///
+ ///
+ /// open FSharp.Quotations
+ /// open FSharp.Quotations.Patterns
+ ///
+ /// let valueVar = Var("value"), typeof<int>)
+ ///
+ /// Evaluates to a new quotation variable with the given name and type.
+ ///
+ new: name: string * typ: Type * ?isMutable: bool -> Var
/// Fetches or create a new variable with the given name and type from a global pool of shared variables
/// indexed by name and type
@@ -52,8 +90,17 @@ type Var =
///
/// The retrieved or created variable.
///
- ///
- static member Global : name:string * typ:Type -> Var
+ ///
+ ///
+ /// open FSharp.Quotations
+ /// open FSharp.Quotations.Patterns
+ ///
+ /// let valueVar1 = Var.Global("value", typeof<int>)
+ /// let valueVar2 = Var.Global("value", typeof<int>)
+ ///
+ /// Evaluates both to valueVar1 and valueVar2 to the same variable from a global pool of shared variables.
+ ///
+ static member Global: name: string * typ: Type -> Var
interface System.IComparable
@@ -71,26 +118,76 @@ type Expr =
///
/// The expression with the given substitutions.
///
- ///
- member Substitute : substitution:(Var -> Expr option) -> Expr
+ ///
+ ///
+ /// 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)>.
+ ///
+ member Substitute: substitution: (Var -> Expr option) -> Expr
/// Gets the free expression variables of an expression as a list.
/// A sequence of the free variables in the expression.
///
- ///
- member GetFreeVars : unit -> seq
+ ///
+ ///
+ /// 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
+ ///
+ member GetFreeVars: unit -> seq
/// Returns type of an expression.
///
- ///
- member Type : Type
+ ///
+ ///
+ /// open FSharp.Quotations
+ /// open FSharp.Quotations.Patterns
+ ///
+ /// let sampleQuotation = <@ 1 + 1 @>
+ ///
+ /// sampleQuotation.Type
+ ///
+ /// Evaluates to typeof<int>.
+ ///
+ member Type: Type
- /// Returns the custom attributes of an expression.
+ /// Returns the custom attributes of an expression. For quotations deriving from quotation literals this may include the source location of the literal.
///
- ///
- member CustomAttributes : Expr list
+ ///
+ ///
+ /// 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.
+ ///
+ member CustomAttributes: Expr list
- override Equals : obj:obj -> bool
+ override Equals: obj: obj -> bool
/// Builds an expression that represents getting the address of a value.
///
@@ -98,8 +195,17 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member AddressOf : target:Expr -> Expr
+ ///
+ ///
+ /// open FSharp.Quotations
+ ///
+ /// let array = [| 1; 2; 3 |]
+ ///
+ /// Expr.AddressOf(<@ array.[1] @>)
+ ///
+ /// Evaluates to AddressOf (Call (None, GetArray, [PropertyGet (None, array, []), Value (1)])).
+ ///
+ static member AddressOf: target: Expr -> Expr
/// Builds an expression that represents setting the value held at a particular address.
///
@@ -108,8 +214,19 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member AddressSet : target:Expr * value:Expr -> Expr
+ ///
+ ///
+ /// 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)).
+ ///
+ static member AddressSet: target: Expr * value: Expr -> Expr
/// Builds an expression that represents the application of a first class function value to a single argument.
///
@@ -118,8 +235,18 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member Application: functionExpr:Expr * argument:Expr -> Expr
+ ///
+ ///
+ /// 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 @>.
+ ///
+ static member Application: functionExpr: Expr * argument: Expr -> Expr
/// Builds an expression that represents the application of a first class function value to multiple arguments
///
@@ -128,8 +255,18 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member Applications: functionExpr:Expr * arguments:list> -> Expr
+ ///
+ ///
+ /// 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 @>.
+ ///
+ static member Applications: functionExpr: Expr * arguments: list> -> Expr
/// Builds an expression that represents a call to an static method or module-bound function
///
@@ -138,8 +275,24 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member Call : methodInfo:MethodInfo * arguments:list -> Expr
+ ///
+ ///
+ /// 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") @>.
+ ///
+ static member Call: methodInfo: MethodInfo * arguments: list -> Expr
/// Builds an expression that represents a call to an instance method associated with an object
///
@@ -149,10 +302,26 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member Call : obj:Expr * methodInfo:MethodInfo * arguments:list -> Expr
+ ///
+ ///
+ /// 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") @>.
+ ///
+ static member Call: obj: Expr * methodInfo: MethodInfo * arguments: list -> Expr
- /// Builds an expression that represents a call to an static method or module-bound function
+ /// Builds an expression that represents a call to an static method or module-bound function, potentially passing additional witness arguments
///
/// The MethodInfo describing the method to call.
/// The additional MethodInfo describing the method to call, accepting witnesses.
@@ -161,10 +330,40 @@ type Expr =
///
/// The resulting expression.
///
- ///
+ /// 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))]) @>.
+ ///
static member CallWithWitnesses: methodInfo: MethodInfo * methodInfoWithWitnesses: MethodInfo * witnesses: Expr list * arguments: Expr list -> Expr
- /// Builds an expression that represents a call to an instance method associated with an object
+ /// Builds an expression that represents a call to an instance method associated with an object, potentially passing additional witness arguments
///
/// The input object.
/// The description of the method to call.
@@ -174,8 +373,8 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member CallWithWitnesses: obj:Expr * methodInfo:MethodInfo * methodInfoWithWitnesses: MethodInfo * witnesses: Expr list * arguments:Expr list -> Expr
+ /// See examples for Call and CallWithWitnesses
+ static member CallWithWitnesses: obj: Expr * methodInfo: MethodInfo * methodInfoWithWitnesses: MethodInfo * witnesses: Expr list * arguments: Expr list -> Expr
/// Builds an expression that represents the coercion of an expression to a type
///
@@ -184,8 +383,17 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member Coerce : source:Expr * target:Type -> Expr
+ ///
+ ///
+ /// 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 @>.
+ ///
+ static member Coerce: source: Expr * target: Type -> Expr
/// Builds 'if ... then ... else' expressions.
///
@@ -195,8 +403,19 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member IfThenElse : guard:Expr * thenExpr:Expr * elseExpr:Expr -> Expr
+ ///
+ ///
+ /// 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 @>.
+ ///
+ static member IfThenElse: guard: Expr * thenExpr: Expr * elseExpr: Expr -> Expr
/// Builds a 'for i = ... to ... do ...' expression that represent loops over integer ranges
///
@@ -207,17 +426,39 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member ForIntegerRangeLoop: loopVariable:Var * start:Expr * endExpr:Expr * body:Expr -> Expr
+ ///
+ ///
+ /// 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 @>.
+ ///
+ static member ForIntegerRangeLoop: loopVariable: Var * start: Expr * endExpr: Expr * body: Expr -> Expr
/// Builds an expression that represents the access of a static field
///
/// The description of the field to access.
///
/// The resulting expression.
- ///
- ///
- static member FieldGet: fieldInfo:FieldInfo -> Expr
+ ///
+ ///
+ ///
+ /// 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).
+ ///
+ static member FieldGet: fieldInfo: FieldInfo -> Expr
/// Builds an expression that represents the access of a field of an object
///
@@ -226,8 +467,22 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member FieldGet: obj:Expr * fieldInfo:FieldInfo -> Expr
+ ///
+ ///
+ /// 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.
+ ///
+ static member FieldGet: obj: Expr * fieldInfo: FieldInfo -> Expr
/// Builds an expression that represents writing to a static field
///
@@ -236,8 +491,8 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member FieldSet: fieldInfo:FieldInfo * value:Expr -> Expr
+ /// Settable public static fields are rare in F# and .NET libraries, so examples of using this method are uncommon.
+ static member FieldSet: fieldInfo: FieldInfo * value: Expr -> Expr
/// Builds an expression that represents writing to a field of an object
///
@@ -247,8 +502,23 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member FieldSet: obj:Expr * fieldInfo:FieldInfo * value:Expr -> Expr
+ /// 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.
+ ///
+ static member FieldSet: obj: Expr * fieldInfo: FieldInfo * value: Expr -> Expr
/// Builds an expression that represents the construction of an F# function value
///
@@ -257,8 +527,19 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member Lambda : parameter:Var * body:Expr -> Expr
+ ///
+ ///
+ /// 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).
+ ///
+ static member Lambda: parameter: Var * body: Expr -> Expr
/// Builds expressions associated with 'let' constructs
///
@@ -268,8 +549,19 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member Let : letVariable:Var * letExpr:Expr * body:Expr -> Expr
+ ///
+ ///
+ /// 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 @>.
+ ///
+ static member Let: letVariable: Var * letExpr: Expr * body: Expr -> Expr
/// Builds recursive expressions associated with 'let rec' constructs
///
@@ -278,8 +570,25 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member LetRecursive : bindings:(Var * Expr) list * body:Expr -> Expr
+ ///
+ ///
+ ///
+ /// 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 @>.
+ ///
+ static member LetRecursive: bindings: (Var * Expr) list * body: Expr -> Expr
/// Builds an expression that represents the invocation of an object constructor
///
@@ -288,8 +597,24 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member NewObject: constructorInfo:ConstructorInfo * arguments:Expr list -> Expr
+ ///
+ ///
+ /// 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)) @>.
+ ///
+ static member NewObject: constructorInfo: ConstructorInfo * arguments: Expr list -> Expr
/// Builds an expression that represents the invocation of a default object constructor
///
@@ -297,17 +622,31 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member DefaultValue: expressionType:Type -> Expr
+ ///
+ ///
+ /// open FSharp.Quotations
+ ///
+ /// Expr.DefaultValue(typeof<int>)
+ ///
+ /// Evaluates to the quotation DefaultValue (Int32).
+ ///
+ static member DefaultValue: expressionType: Type -> Expr
/// Builds an expression that represents the creation of an F# tuple value
///
/// The list of elements of the tuple.
///
/// The resulting expression.
- ///
- ///
- static member NewTuple: elements:Expr list -> Expr
+ ///
+ ///
+ ///
+ /// open FSharp.Quotations
+ ///
+ /// Expr.NewTuple([ <@ 1 @>; <@ "a" @> ])
+ ///
+ /// Evaluates to a quotation with the same structure as <@ (1, "a") @>.
+ ///
+ static member NewTuple: elements: Expr list -> Expr
/// Builds an expression that represents the creation of an F# tuple value
///
@@ -315,9 +654,16 @@ type Expr =
/// The list of elements of the tuple.
///
/// The resulting expression.
- ///
- ///
- static member NewStructTuple: asm:Assembly * elements:Expr list -> Expr
+ ///
+ ///
+ ///
+ /// open FSharp.Quotations
+ ///
+ /// Expr.NewStructTuple(typeof<struct (int * int)>.Assembly, [ <@ 1 @>; <@ "a" @> ])
+ ///
+ /// Evaluates to a quotation with the same structure as <@ struct (1, "a") @>.
+ ///
+ static member NewStructTuple: asm: Assembly * elements: Expr list -> Expr
/// Builds record-construction expressions
///
@@ -325,9 +671,18 @@ type Expr =
/// The list of elements of the record.
///
/// The resulting expression.
- ///
- ///
- static member NewRecord: recordType:Type * elements:Expr list -> Expr
+ ///
+ ///
+ ///
+ /// 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" } @>.
+ ///
+ static member NewRecord: recordType: Type * elements: Expr list -> Expr
/// Builds an expression that represents the creation of an array value initialized with the given elements
///
@@ -335,9 +690,16 @@ type Expr =
/// The list of elements of the array.
///
/// The resulting expression.
- ///
- ///
- static member NewArray: elementType:Type * elements:Expr list -> Expr
+ ///
+ ///
+ ///
+ /// open FSharp.Quotations
+ ///
+ /// Expr.NewArray(typeof<int>, [ <@ 1 @>; <@ 2 @> ])
+ ///
+ /// Evaluates to a quotation with the same structure as <@ [| 1; 2 |] @>.
+ ///
+ static member NewArray: elementType: Type * elements: Expr list -> Expr
/// Builds an expression that represents the creation of a delegate value for the given type
///
@@ -346,9 +708,20 @@ type Expr =
/// The body of the function.
///
/// The resulting expression.
- ///
- ///
- static member NewDelegate: delegateType:Type * parameters:Var list * body:Expr -> Expr
+ ///
+ ///
+ ///
+ /// 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) @>.
+ ///
+ static member NewDelegate: delegateType: Type * parameters: Var list * body: Expr -> Expr
/// Builds an expression that represents the creation of a union case value
///
@@ -356,9 +729,20 @@ type Expr =
/// The list of arguments for the case.
///
/// The resulting expression.
- ///
- ///
- static member NewUnionCase: unionCase:UnionCaseInfo * arguments:Expr list -> Expr
+ ///
+ ///
+ ///
+ /// 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] @>.
+ ///
+ static member NewUnionCase: unionCase: UnionCaseInfo * arguments: Expr list -> Expr
/// Builds an expression that represents reading a property of an object
///
@@ -367,9 +751,25 @@ type Expr =
/// List of indices for the property if it is an indexed property.
///
/// The resulting expression.
- ///
- ///
- static member PropertyGet: obj:Expr * property:PropertyInfo * ?indexerArgs: Expr list -> Expr
+ ///
+ ///
+ ///
+ /// 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 @>.
+ ///
+ static member PropertyGet: obj: Expr * property: PropertyInfo * ?indexerArgs: Expr list -> Expr
/// Builds an expression that represents reading a static property
///
@@ -377,9 +777,23 @@ type Expr =
/// List of indices for the property if it is an indexed property.
///
/// The resulting expression.
- ///
- ///
- static member PropertyGet: property:PropertyInfo * ?indexerArgs: Expr list -> Expr
+ ///
+ ///
+ ///
+ /// 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 @>.
+ ///
+ static member PropertyGet: property: PropertyInfo * ?indexerArgs: Expr list -> Expr
/// Builds an expression that represents writing to a property of an object
///
@@ -389,9 +803,26 @@ type Expr =
/// List of indices for the property if it is an indexed property.
///
/// The resulting expression.
- ///
- ///
- static member PropertySet: obj:Expr * property:PropertyInfo * value:Expr * ?indexerArgs: Expr list -> Expr
+ ///
+ ///
+ ///
+ /// 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 @>.
+ ///
+ static member PropertySet: obj: Expr * property: PropertyInfo * value: Expr * ?indexerArgs: Expr list -> Expr
/// Builds an expression that represents writing to a static property
///
@@ -400,19 +831,32 @@ type Expr =
/// List of indices for the property if it is an indexed property.
///
/// The resulting expression.
- ///
- ///
- static member PropertySet: property:PropertyInfo * value:Expr * ?indexerArgs: Expr list -> Expr
+ ///
+ ///
+ ///
+ /// 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 @>.
+ ///
+ static member PropertySet: property: PropertyInfo * value: Expr * ?indexerArgs: Expr list -> Expr
/// Builds an expression that represents a nested typed or raw quotation literal
///
/// The expression being quoted.
///
/// The resulting expression.
- ///
- ///
[]
- static member Quote: inner:Expr -> Expr
+ static member Quote: inner: Expr -> Expr
/// Builds an expression that represents a nested raw quotation literal
///
@@ -420,8 +864,15 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member QuoteRaw: inner:Expr -> Expr
+ ///
+ ///
+ /// open FSharp.Quotations
+ ///
+ /// Expr.QuoteRaw(<@ 1 @>)
+ ///
+ /// Evaluates to a quotation with the same structure as <@ <@ 1 @> @>.
+ ///
+ static member QuoteRaw: inner: Expr -> Expr
/// Builds an expression that represents a nested typed quotation literal
///
@@ -429,8 +880,15 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member QuoteTyped: inner:Expr -> Expr
+ ///
+ ///
+ /// open FSharp.Quotations
+ ///
+ /// Expr.QuoteTyped(<@ 1 @>)
+ ///
+ /// Evaluates to a quotation with the same structure as <@ <@ 1 @> @>.
+ ///
+ static member QuoteTyped: inner: Expr -> Expr
/// Builds an expression that represents the sequential execution of one expression followed by another
///
@@ -439,8 +897,16 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member Sequential: first:Expr * second:Expr -> Expr
+ ///
+ ///
+ /// 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") @>.
+ ///
+ static member Sequential: first: Expr * second: Expr -> Expr
/// Builds an expression that represents a try/with construct for exception filtering and catching.
///
@@ -452,8 +918,18 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member TryWith: body:Expr * filterVar:Var * filterBody:Expr * catchVar:Var * catchBody:Expr -> Expr
+ ///
+ ///
+ /// 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 @>.
+ ///
+ static member TryWith: body: Expr * filterVar: Var * filterBody: Expr * catchVar: Var * catchBody: Expr -> Expr
/// Builds an expression that represents a try/finally construct
///
@@ -462,8 +938,16 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member TryFinally: body:Expr * compensation:Expr -> Expr
+ ///
+ ///
+ /// 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") @>.
+ ///
+ static member TryFinally: body: Expr * compensation: Expr -> Expr
/// Builds an expression that represents getting a field of a tuple
///
@@ -472,9 +956,17 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member TupleGet: tuple:Expr * index:int -> Expr
-
+ ///
+ ///
+ /// 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).
+ ///
+ static member TupleGet: tuple: Expr * index: int -> Expr
/// Builds an expression that represents a type test.
///
@@ -483,8 +975,17 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member TypeTest: source:Expr * target:Type -> Expr
+ ///
+ ///
+ /// open FSharp.Quotations
+ ///
+ /// let obj = box 1
+ ///
+ /// Expr.TypeTest( <@ obj @>, typeof<int>)
+ ///
+ /// Evaluates to quotation that displays as TypeTest (Int32, PropertyGet (None, obj, [])).
+ ///
+ static member TypeTest: source: Expr * target: Type -> Expr
/// Builds an expression that represents a test of a value is of a particular union case
///
@@ -492,9 +993,20 @@ type Expr =
/// The description of the union case.
///
/// The resulting expression.
- ///
- ///
- static member UnionCaseTest: source:Expr * unionCase:UnionCaseInfo -> Expr
+ ///
+ ///
+ ///
+ /// 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).
+ ///
+ static member UnionCaseTest: source: Expr * unionCase: UnionCaseInfo -> Expr
/// Builds an expression that represents a constant value of a particular type
///
@@ -502,18 +1014,30 @@ type Expr =
/// The type of the object.
///
/// The resulting expression.
- ///
- ///
- static member Value : value:obj * expressionType:Type -> Expr
+ ///
+ ///
+ ///
+ /// open FSharp.Quotations
+ ///
+ /// Expr.Value(box 1, typeof<int>)
+ ///
+ /// Evaluates to a quotation with the same structure as <@ 1 @>.
+ ///
+ static member Value: value: obj * expressionType: Type -> Expr
/// Builds an expression that represents a constant value
///
/// The typed value.
///
- /// The resulting expression.
- ///
- ///
- static member Value : value:'T -> Expr
+ ///
+ ///
+ /// open FSharp.Quotations
+ ///
+ /// Expr.Value(1)
+ ///
+ /// Evaluates to a quotation with the same structure as <@ 1 @>.
+ ///
+ static member Value: value: 'T -> Expr
/// Builds an expression that represents a constant value, arising from a variable of the given name
///
@@ -522,8 +1046,15 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member ValueWithName : value:'T * name: string -> Expr
+ ///
+ ///
+ /// 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".
+ ///
+ static member ValueWithName: value: 'T * name: string -> Expr
/// Builds an expression that represents a constant value of a particular type, arising from a variable of the given name
///
@@ -533,8 +1064,15 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member ValueWithName : value:obj * expressionType:Type * name: string -> Expr
+ ///
+ ///
+ /// 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".
+ ///
+ static member ValueWithName: value: obj * expressionType: Type * name: string -> Expr
/// Builds an expression that represents a value and its associated reflected definition as a quotation
///
@@ -543,7 +1081,14 @@ type Expr =
///
/// The resulting expression.
///
- ///
+ ///
+ ///
+ /// 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)])).
+ ///
static member WithValue: value: 'T * definition: Expr<'T> -> Expr<'T>
/// Builds an expression that represents a value and its associated reflected definition as a quotation
@@ -554,8 +1099,15 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member WithValue: value: obj * expressionType:Type * definition: Expr -> Expr
+ ///
+ ///
+ /// 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)])).
+ ///
+ static member WithValue: value: obj * expressionType: Type * definition: Expr -> Expr
/// Builds an expression that represents a variable
///
@@ -563,8 +1115,17 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member Var : variable:Var -> Expr
+ ///
+ ///
+ /// open FSharp.Quotations
+ ///
+ /// let vVar = Var("v", typeof<int>)
+ ///
+ /// Expr.Var(vVar)
+ ///
+ /// Evaluates to a quotation displayed as v.
+ ///
+ static member Var: variable: Var -> Expr
/// Builds an expression that represents setting a mutable variable
///
@@ -573,8 +1134,17 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member VarSet : variable:Var * value:Expr -> Expr
+ ///
+ ///
+ /// 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)).
+ ///
+ static member VarSet: variable: Var * value: Expr -> Expr
/// Builds an expression that represents a while loop
///
@@ -583,8 +1153,18 @@ type Expr =
///
/// The resulting expression.
///
- ///
- static member WhileLoop : guard:Expr * body:Expr -> Expr
+ ///
+ ///
+ /// open FSharp.Quotations
+ ///
+ /// let guardExpr = <@ true @>
+ /// let bodyExpr = <@ () @>
+ ///
+ /// Expr.WhileLoop(guardExpr, bodyExpr)
+ ///
+ /// Evaluates to a quotation with the same structure as <@ while true do () @>.
+ ///
+ static member WhileLoop: guard: Expr * body: Expr -> Expr
/// Returns a new typed expression given an underlying runtime-typed expression.
/// A type annotation is usually required to use this function, and
@@ -594,8 +1174,17 @@ type Expr =
///
/// The resulting typed expression.
///
- ///
- static member Cast : source:Expr -> Expr<'T>
+ ///
+ ///
+ /// open FSharp.Quotations
+ ///
+ /// let rawExpr = <@ 1 @>
+ ///
+ /// Expr.Cast<int>(rawExpr)
+ ///
+ /// Evaluates with type Expr<int>.
+ ///
+ static member Cast: source: Expr -> Expr<'T>
/// 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 [<ReflectedDefinition>] attribute.
@@ -604,8 +1193,47 @@ type Expr =
///
/// The reflection definition or None if a match could not be found.
///
- ///
- static member TryGetReflectedDefinition : methodBase:MethodBase -> Expr option
+ ///
+ ///
+ /// 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.
+ ///
+ ///
+ ///
+ ///
+ /// 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.
+ ///
+ static member TryGetReflectedDefinition: methodBase: MethodBase -> Expr option
/// This function is called automatically when quotation syntax (<@ @>) and other sources of
/// quotations are used.
@@ -616,9 +1244,7 @@ type Expr =
/// The serialized form of the quoted expression.
///
/// The resulting expression.
- ///
- ///
- static member Deserialize : qualifyingType:System.Type * spliceTypes:list * spliceExprs:list * bytes:byte[] -> Expr
+ static member Deserialize: qualifyingType: System.Type * spliceTypes: list * spliceExprs: list * bytes: byte[] -> Expr
/// This function is called automatically when quotation syntax (<@ @>) and other sources of
/// quotations are used.
@@ -630,9 +1256,7 @@ type Expr =
/// The serialized form of the quoted expression.
///
/// The resulting expression.
- ///
- ///
- static member Deserialize40 : qualifyingType:Type * referencedTypes:Type[] * spliceTypes:Type[] * spliceExprs:Expr[] * bytes:byte[] -> Expr
+ static member Deserialize40: qualifyingType: Type * referencedTypes: Type[] * spliceTypes: Type[] * spliceExprs: Expr[] * bytes: byte[] -> Expr
/// Permits interactive environments such as F# Interactive
/// to explicitly register new pickled resources that represent persisted
@@ -642,8 +1266,7 @@ type Expr =
/// The unique name for the resources being added.
/// The serialized resource to register with the environment.
///
- ///
- static member RegisterReflectedDefinitions: assembly:Assembly * resource:string * serializedValue:byte[] -> unit
+ static member RegisterReflectedDefinitions: assembly: Assembly * resource: string * serializedValue: byte[] -> unit
/// Permits interactive environments such as F# Interactive
/// to explicitly register new pickled resources that represent persisted
@@ -654,8 +1277,7 @@ type Expr =
/// The type definitions referenced.
/// The serialized resource to register with the environment.
///
- ///
- static member RegisterReflectedDefinitions: assembly:Assembly * resource:string * serializedValue:byte[] * referencedTypes:Type[] -> unit
+ static member RegisterReflectedDefinitions: assembly: Assembly * resource: string * serializedValue: byte[] * referencedTypes: Type[] -> unit
/// 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
@@ -664,15 +1286,34 @@ type Expr =
///
/// The created of fetched typed global variable.
///
- ///
- static member GlobalVar<'T> : name:string -> Expr<'T>
+ ///
+ ///
+ /// open FSharp.Quotations
+ ///
+ /// let expr1 = Expr.GlobalVar<int>("x")
+ /// let expr2 = Expr.GlobalVar<int>("x")
+ ///
+ /// Evaluates expr1 and expr2 to identical quotations.
+ ///
+ static member GlobalVar<'T> : name: string -> Expr<'T>
/// Format the expression as a string
///
/// Indicates if method, property, constructor and type objects should be printed in detail. If false, these are abbreviated to their name.
///
/// The formatted string.
- member ToString : full: bool -> string
+ ///
+ ///
+ ///
+ /// 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)])".
+ ///
+ member ToString: full: bool -> string
/// Type-carrying quoted expressions. Expressions are generated either
/// by quotations in source text or programatically
@@ -682,8 +1323,17 @@ and []
inherit Expr
/// Gets the raw expression associated with this type-carrying expression
///
- ///
- member Raw : Expr
+ ///
+ ///
+ /// open FSharp.Quotations
+ ///
+ /// let expr1 = <@ 1 + 1 @>
+ ///
+ /// expr1.Raw
+ ///
+ /// Evaluates to the same quotation as <@ expr1 @> except with the weaker type Expr instead of Expr<int>.
+ ///
+ member Raw: Expr
/// Contains a set of primitive F# active patterns to analyze F# expression objects
[]
@@ -697,7 +1347,7 @@ module Patterns =
///
///
[]
- val (|AddressOf|_|) : input:Expr -> Expr option
+ val (|AddressOf|_|): input: Expr -> Expr option
/// An active pattern to recognize expressions that represent setting the value held at an address
///
@@ -707,7 +1357,7 @@ module Patterns =
///
///
[]
- val (|AddressSet|_|) : input:Expr -> (Expr * Expr) option
+ val (|AddressSet|_|): input: Expr -> (Expr * Expr) option
/// An active pattern to recognize expressions that represent applications of first class function values
///
@@ -717,7 +1367,7 @@ module Patterns =
///
///
[]
- val (|Application|_|) : input:Expr -> (Expr * Expr) option
+ val (|Application|_|): input: Expr -> (Expr * Expr) option
/// An active pattern to recognize expressions that represent calls to static and instance methods, and functions defined in modules
///
@@ -727,7 +1377,7 @@ module Patterns =
///
///
[]
- val (|Call|_|) : input:Expr -> (Expr option * MethodInfo * Expr list) option
+ val (|Call|_|): input: Expr -> (Expr option * MethodInfo * Expr list) option
/// An active pattern to recognize expressions that represent calls to static and instance methods, and functions defined in modules, including witness arguments
///
@@ -737,7 +1387,7 @@ module Patterns =
///
///
[]
- val (|CallWithWitnesses|_|) : input:Expr -> (Expr option * MethodInfo * MethodInfo * Expr list * Expr list) option
+ val (|CallWithWitnesses|_|): input: Expr -> (Expr option * MethodInfo * MethodInfo * Expr list * Expr list) option
/// An active pattern to recognize expressions that represent coercions from one type to another
///
@@ -747,7 +1397,7 @@ module Patterns =
///
///
[]
- val (|Coerce|_|) : input:Expr -> (Expr * Type) option
+ val (|Coerce|_|): input: Expr -> (Expr * Type) option
/// An active pattern to recognize expressions that represent getting a static or instance field
///
@@ -757,7 +1407,7 @@ module Patterns =
///
///
[]
- val (|FieldGet|_|) : input:Expr -> (Expr option * FieldInfo) option
+ val (|FieldGet|_|): input: Expr -> (Expr option * FieldInfo) option
/// An active pattern to recognize expressions that represent setting a static or instance field
///
@@ -767,7 +1417,7 @@ module Patterns =
///
///
[]
- val (|FieldSet|_|) : input:Expr -> (Expr option * FieldInfo * Expr) option
+ val (|FieldSet|_|): input: Expr -> (Expr option * FieldInfo * Expr) option
/// An active pattern to recognize expressions that represent loops over integer ranges
///
@@ -777,7 +1427,7 @@ module Patterns =
///
///
[]
- val (|ForIntegerRangeLoop|_|) : input:Expr -> (Var * Expr * Expr * Expr) option
+ val (|ForIntegerRangeLoop|_|): input: Expr -> (Var * Expr * Expr * Expr) option
/// An active pattern to recognize expressions that represent while loops
///
@@ -787,7 +1437,7 @@ module Patterns =
///
///
[]
- val (|WhileLoop|_|) : input:Expr -> (Expr * Expr) option
+ val (|WhileLoop|_|): input: Expr -> (Expr * Expr) option
/// An active pattern to recognize expressions that represent conditionals
///
@@ -797,7 +1447,7 @@ module Patterns =
///
///
[]
- val (|IfThenElse|_|) : input:Expr -> (Expr * Expr * Expr) option
+ val (|IfThenElse|_|): input: Expr -> (Expr * Expr * Expr) option
/// An active pattern to recognize expressions that represent first class function values
///
@@ -807,7 +1457,7 @@ module Patterns =
///
///
[]
- val (|Lambda|_|) : input:Expr -> (Var * Expr) option
+ val (|Lambda|_|): input: Expr -> (Var * Expr) option
/// An active pattern to recognize expressions that represent let bindings
///
@@ -817,7 +1467,7 @@ module Patterns =
///
///
[]
- val (|Let|_|) : input:Expr -> (Var * Expr * Expr) option
+ val (|Let|_|) : input: Expr -> (Var * Expr * Expr) option
/// An active pattern to recognize expressions that represent recursive let bindings of one or more variables
///
@@ -827,7 +1477,7 @@ module Patterns =
///
///
[]
- val (|LetRecursive|_|) : input:Expr -> ((Var * Expr) list * Expr) option
+ val (|LetRecursive|_|): input: Expr -> ((Var * Expr) list * Expr) option
/// An active pattern to recognize expressions that represent the construction of arrays
///
@@ -837,7 +1487,7 @@ module Patterns =
///
///
[]
- val (|NewArray|_|) : input:Expr -> (Type * Expr list) option
+ val (|NewArray|_|): input: Expr -> (Type * Expr list) option
/// An active pattern to recognize expressions that represent invocations of a default constructor of a struct
///
@@ -847,7 +1497,7 @@ module Patterns =
///
///
[]
- val (|DefaultValue|_|) : input:Expr -> Type option
+ val (|DefaultValue|_|): input: Expr -> Type option
/// An active pattern to recognize expressions that represent construction of delegate values
///
@@ -857,7 +1507,7 @@ module Patterns =
///
///
[]
- val (|NewDelegate|_|) : input:Expr -> (Type * Var list * Expr) option
+ val (|NewDelegate|_|): input: Expr -> (Type * Var list * Expr) option
/// An active pattern to recognize expressions that represent invocation of object constructors
///
@@ -867,7 +1517,7 @@ module Patterns =
///
///
[]
- val (|NewObject|_|) : input:Expr -> (ConstructorInfo * Expr list) option
+ val (|NewObject|_|): input: Expr -> (ConstructorInfo * Expr list) option
/// An active pattern to recognize expressions that represent construction of record values
///
@@ -877,7 +1527,7 @@ module Patterns =
///
///
[]
- val (|NewRecord|_|) : input:Expr -> (Type * Expr list) option
+ val (|NewRecord|_|): input: Expr -> (Type * Expr list) option
/// An active pattern to recognize expressions that represent construction of particular union case values
///
@@ -887,7 +1537,7 @@ module Patterns =
///
///
[]
- val (|NewUnionCase|_|) : input:Expr -> (UnionCaseInfo * Expr list) option
+ val (|NewUnionCase|_|): input: Expr -> (UnionCaseInfo * Expr list) option
/// An active pattern to recognize expressions that represent construction of tuple values
///
@@ -897,7 +1547,7 @@ module Patterns =
///
///
[]
- val (|NewTuple|_|) : input:Expr -> (Expr list) option
+ val (|NewTuple|_|): input: Expr -> (Expr list) option
/// An active pattern to recognize expressions that represent construction of struct tuple values
///
@@ -907,7 +1557,7 @@ module Patterns =
///
///
[]
- val (|NewStructTuple|_|) : input:Expr -> (Expr list) option
+ val (|NewStructTuple|_|): input: Expr -> (Expr list) option
/// An active pattern to recognize expressions that represent the read of a static or instance property, or a non-function value declared in a module
///
@@ -917,7 +1567,7 @@ module Patterns =
///
///
[]
- val (|PropertyGet|_|) : input:Expr -> (Expr option * PropertyInfo * Expr list) option
+ val (|PropertyGet|_|): input: Expr -> (Expr option * PropertyInfo * Expr list) option
/// An active pattern to recognize expressions that represent setting a static or instance property, or a non-function value declared in a module
///
@@ -927,7 +1577,7 @@ module Patterns =
///
///
[]
- val (|PropertySet|_|) : input:Expr -> (Expr option * PropertyInfo * Expr list * Expr) option
+ val (|PropertySet|_|): input: Expr -> (Expr option * PropertyInfo * Expr list * Expr) option
/// An active pattern to recognize expressions that represent a nested quotation literal
///
@@ -938,7 +1588,7 @@ module Patterns =
///
[]
[]
- val (|Quote|_|) : input:Expr -> Expr option
+ val (|Quote|_|): input: Expr -> Expr option
/// An active pattern to recognize expressions that represent a nested raw quotation literal
///
@@ -948,7 +1598,7 @@ module Patterns =
///
///
[]
- val (|QuoteRaw|_|) : input:Expr -> Expr option
+ val (|QuoteRaw|_|): input: Expr -> Expr option
/// An active pattern to recognize expressions that represent a nested typed quotation literal
///
@@ -958,7 +1608,7 @@ module Patterns =
///
///
[]
- val (|QuoteTyped|_|) : input:Expr -> Expr option
+ val (|QuoteTyped|_|): input: Expr -> Expr option
/// An active pattern to recognize expressions that represent sequential execution of one expression followed by another
///
@@ -968,7 +1618,7 @@ module Patterns =
///
///
[]
- val (|Sequential|_|) : input:Expr -> (Expr * Expr) option
+ val (|Sequential|_|): input: Expr -> (Expr * Expr) option
/// An active pattern to recognize expressions that represent a try/with construct for exception filtering and catching
///
@@ -978,7 +1628,7 @@ module Patterns =
///
///
[]
- val (|TryWith|_|) : input:Expr -> (Expr * Var * Expr * Var * Expr) option
+ val (|TryWith|_|): input: Expr -> (Expr * Var * Expr * Var * Expr) option
/// An active pattern to recognize expressions that represent a try/finally construct
///
@@ -988,7 +1638,7 @@ module Patterns =
///
///
[]
- val (|TryFinally|_|) : input:Expr -> (Expr * Expr) option
+ val (|TryFinally|_|): input: Expr -> (Expr * Expr) option
/// An active pattern to recognize expressions that represent getting a tuple field
///
@@ -998,7 +1648,7 @@ module Patterns =
///
///
[]
- val (|TupleGet|_|) : input:Expr -> (Expr * int) option
+ val (|TupleGet|_|): input: Expr -> (Expr * int) option
/// An active pattern to recognize expressions that represent a dynamic type test
///
@@ -1008,7 +1658,7 @@ module Patterns =
///
///
[]
- val (|TypeTest|_|) : input:Expr -> (Expr * Type) option
+ val (|TypeTest|_|): input: Expr -> (Expr * Type) option
/// An active pattern to recognize expressions that represent a test if a value is of a particular union case
///
@@ -1018,7 +1668,7 @@ module Patterns =
///
///
[]
- val (|UnionCaseTest|_|) : input:Expr -> (Expr * UnionCaseInfo) option
+ val (|UnionCaseTest|_|): input: Expr -> (Expr * UnionCaseInfo) option
/// An active pattern to recognize expressions that represent a constant value. This also matches expressions matched by ValueWithName.
///
@@ -1028,7 +1678,7 @@ module Patterns =
///
///
[]
- val (|Value|_|) : input:Expr -> (obj * Type) option
+ val (|Value|_|): input: Expr -> (obj * Type) option
/// An active pattern to recognize expressions that represent a constant value
///
@@ -1038,7 +1688,7 @@ module Patterns =
///
///
[]
- val (|ValueWithName|_|) : input:Expr -> (obj * Type * string) option
+ val (|ValueWithName|_|): input: Expr -> (obj * Type * string) option
/// An active pattern to recognize expressions that are a value with an associated definition
///
@@ -1048,7 +1698,7 @@ module Patterns =
///
///
[]
- val (|WithValue|_|) : input:Expr -> (obj * Type * Expr) option
+ val (|WithValue|_|): input: Expr -> (obj * Type * Expr) option
/// An active pattern to recognize expressions that represent a variable
///
@@ -1058,7 +1708,7 @@ module Patterns =
///
///
[]
- val (|Var|_|) : input:Expr -> Var option
+ val (|Var|_|) : input: Expr -> Var option
/// An active pattern to recognize expressions that represent setting a mutable variable
///
@@ -1068,7 +1718,7 @@ module Patterns =
///
///
[]
- val (|VarSet|_|) : input:Expr -> (Var * Expr) option
+ val (|VarSet|_|): input: Expr -> (Var * Expr) option
/// Contains a set of derived F# active patterns to analyze F# expression objects
[]
@@ -1080,9 +1730,20 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the curried variables and body of the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.Patterns
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ (fun (a1, a2) b -> ()) @> with
+ /// | Lambdas(curriedVars, _) ->
+ /// curriedVars |> List.map (List.map (fun arg -> arg.Name))
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to [["a1"; "a2"]; ["b"]].
+ ///
[]
- val (|Lambdas|_|) : input:Expr -> (Var list list * Expr) option
+ val (|Lambdas|_|): input: Expr -> (Var list list * Expr) option
/// An active pattern to recognize expressions that represent the application of a (possibly curried or tupled) first class function value
///
@@ -1090,9 +1751,20 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the function and curried arguments of the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.Patterns
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ (fun f -> f (1, 2) 3) @> with
+ /// | Lambda(_, Applications (f, curriedArgs)) ->
+ /// curriedArgs |> List.map (fun args -> args.Length)
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to [2; 1].
+ ///
[]
- val (|Applications|_|) : input:Expr -> (Expr * Expr list list) option
+ val (|Applications|_|): input: Expr -> (Expr * Expr list list) option
/// An active pattern to recognize expressions of the form a && b
///
@@ -1100,9 +1772,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the left and right parts of the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ true && false @> with
+ /// | AndAlso (a, b) -> (a, b)
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to <@ true @>, <@ false @>.
+ ///
[]
- val (|AndAlso|_|) : input:Expr -> (Expr * Expr) option
+ val (|AndAlso|_|): input: Expr -> (Expr * Expr) option
/// An active pattern to recognize expressions of the form a || b
///
@@ -1110,9 +1791,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the left and right parts of the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ true || false @> with
+ /// | OrElse (a, b) -> (a, b)
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to <@ true @>, <@ false @>.
+ ///
[]
- val (|OrElse|_|) : input:Expr -> (Expr * Expr) option
+ val (|OrElse|_|): input: Expr -> (Expr * Expr) option
/// An active pattern to recognize () constant expressions
///
@@ -1120,9 +1810,18 @@ module DerivedPatterns =
///
/// When successful, the pattern does not bind any results
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ () @> with
+ /// | Unit v -> v
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to true.
+ ///
[]
- val (|Unit|_|) : input:Expr -> unit option
+ val (|Unit|_|): input: Expr -> unit option
/// An active pattern to recognize constant boolean expressions
///
@@ -1130,9 +1829,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the constant value from the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ true @> with
+ /// | Bool v -> v
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to true.
+ ///
[]
- val (|Bool|_|) : input:Expr -> bool option
+ val (|Bool|_|): input: Expr -> bool option
/// An active pattern to recognize constant string expressions
///
@@ -1140,9 +1848,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the constant value from the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ "a" @> with
+ /// | String v -> v
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to "a".
+ ///
[]
- val (|String|_|) : input:Expr -> string option
+ val (|String|_|): input: Expr -> string option
/// An active pattern to recognize constant 32-bit floating point number expressions
///
@@ -1150,9 +1867,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the constant value from the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ 1.0f @> with
+ /// | Single v -> v
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to 1.0f.
+ ///
[]
- val (|Single|_|) : input:Expr -> float32 option
+ val (|Single|_|): input: Expr -> float32 option
/// An active pattern to recognize constant 64-bit floating point number expressions
///
@@ -1160,9 +1886,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the constant value from the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ 1.0 @> with
+ /// | Double v -> v
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to 1.0.
+ ///
[]
- val (|Double|_|) : input:Expr -> float option
+ val (|Double|_|): input: Expr -> float option
/// An active pattern to recognize constant unicode character expressions
///
@@ -1170,9 +1905,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the constant value from the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ 'a' @> with
+ /// | Char v -> v
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to 'a'.
+ ///
[]
- val (|Char|_|) : input:Expr -> char option
+ val (|Char|_|): input: Expr -> char option
/// An active pattern to recognize constant signed byte expressions
///
@@ -1180,9 +1924,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the constant value from the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ 8y @> with
+ /// | SByte v -> v
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to 8y.
+ ///
[]
- val (|SByte|_|) : input:Expr -> sbyte option
+ val (|SByte|_|): input: Expr -> sbyte option
/// An active pattern to recognize constant byte expressions
///
@@ -1190,9 +1943,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the constant value from the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ 8uy @> with
+ /// | Byte v -> v
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to 8uy.
+ ///
[]
- val (|Byte|_|) : input:Expr -> byte option
+ val (|Byte|_|): input: Expr -> byte option
/// An active pattern to recognize constant int16 expressions
///
@@ -1200,9 +1962,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the constant value from the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ 8s @> with
+ /// | Int16 v -> v
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to 8s.
+ ///
[]
- val (|Int16|_|) : input:Expr -> int16 option
+ val (|Int16|_|): input: Expr -> int16 option
/// An active pattern to recognize constant unsigned int16 expressions
///
@@ -1210,9 +1981,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the constant value from the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ 8us @> with
+ /// | UInt16 v -> v
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to 8us.
+ ///
[]
- val (|UInt16|_|) : input:Expr -> uint16 option
+ val (|UInt16|_|): input: Expr -> uint16 option
/// An active pattern to recognize constant int32 expressions
///
@@ -1220,9 +2000,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the constant value from the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ 8 @> with
+ /// | Int32 v -> v
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to 8.
+ ///
[]
- val (|Int32|_|) : input:Expr -> int32 option
+ val (|Int32|_|): input: Expr -> int32 option
/// An active pattern to recognize constant unsigned int32 expressions
///
@@ -1230,9 +2019,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the constant value from the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ 8u @> with
+ /// | UInt32 v -> v
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to 8u.
+ ///
[]
- val (|UInt32|_|) : input:Expr -> uint32 option
+ val (|UInt32|_|): input: Expr -> uint32 option
/// An active pattern to recognize constant int64 expressions
///
@@ -1240,9 +2038,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the constant value from the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ 8L @> with
+ /// | Int64 v -> v
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to 8L.
+ ///
[]
- val (|Int64|_|) : input:Expr -> int64 option
+ val (|Int64|_|): input: Expr -> int64 option
/// An active pattern to recognize constant unsigned int64 expressions
///
@@ -1250,9 +2057,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the constant value from the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ 8UL @> with
+ /// | UInt64 v -> v
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to 8UL.
+ ///
[]
- val (|UInt64|_|) : input:Expr -> uint64 option
+ val (|UInt64|_|): input: Expr -> uint64 option
/// An active pattern to recognize constant decimal expressions
///
@@ -1260,9 +2076,18 @@ module DerivedPatterns =
///
/// When successful, the pattern binds the constant value from the input expression
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// match <@ 8.0M @> with
+ /// | Decimal v -> v
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to 8.0M.
+ ///
[]
- val (|Decimal|_|) : input:Expr -> decimal option
+ val (|Decimal|_|): input: Expr -> decimal option
/// A parameterized active pattern to recognize calls to a specified function or method.
/// The returned elements are the optional target object (present if the target is an
@@ -1275,9 +2100,39 @@ module DerivedPatterns =
/// instance method), the generic type instantiation (non-empty if the target is a generic
/// instantiation), and the arguments to the function or method.
///
- ///
+ /// Match a specific call to Console.WriteLine taking one string argument:
+ ///
+ /// open FSharp.Quotations
+ /// open FSharp.Quotations.Patterns
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// let inpExpr = <@ Console.WriteLine("hello") @>
+ ///
+ /// match inpExpr with
+ /// | SpecificCall <@ Console.WriteLine("1") @> (None, [], [ argExpr ]) -> argExpr
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to a quotation with the same structure as <@ "hello" @>.
+ ///
+ ///
+ /// Calls to this active pattern can be partially applied to pre-evaluate some aspects of the matching. For example:
+ ///
+ /// open FSharp.Quotations
+ /// open FSharp.Quotations.Patterns
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// let (|ConsoleWriteLineOneArg|_|) = (|SpecificCall|_|) <@ Console.WriteLine("1") @>
+ ///
+ /// let inpExpr = <@ Console.WriteLine("hello") @>
+ ///
+ /// match inpExpr with
+ /// | ConsoleWriteLineOneArg (None, [], [ argExpr ]) -> argExpr
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates to a quotation with the same structure as <@ "hello" @>.
+ ///
[]
- val (|SpecificCall|_|) : templateParameter:Expr -> (Expr -> (Expr option * list * list) option)
+ val (|SpecificCall|_|): templateParameter: Expr -> (Expr -> (Expr option * Type list * Expr list) option)
/// An active pattern to recognize methods that have an associated ReflectedDefinition
///
@@ -1285,9 +2140,29 @@ module DerivedPatterns =
///
/// The expression of the method definition if found, or None.
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations
+ /// open FSharp.Quotations.Patterns
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// [<ReflectedDefinition>]
+ /// let f x = (x, x)
+ ///
+ /// let inpExpr = <@ f 4 @>
+ ///
+ /// let implExpr =
+ /// match inpExpr with
+ /// | Call(None, MethodWithReflectedDefinition implExpr, [ _argExpr ]) -> implExpr
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates implExpr to a quotation with the same structure as <@ fun (x: int) -> (x, x) @>, which is the implementation of the
+ /// method f. Note that the correct generic instantaition has been applied to the implementation to reflect
+ /// the the type at the callsite.
+ ///
+ ///
[]
- val (|MethodWithReflectedDefinition|_|) : methodBase:MethodBase -> Expr option
+ val (|MethodWithReflectedDefinition|_|): methodBase: MethodBase -> Expr option
/// An active pattern to recognize property getters or values in modules that have an associated ReflectedDefinition
///
@@ -1295,9 +2170,30 @@ module DerivedPatterns =
///
/// The expression of the method definition if found, or None.
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations
+ /// open FSharp.Quotations.Patterns
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// [<ReflectedDefinition>]
+ /// type C<'T>() =
+ /// member x.Identity = x
+ ///
+ /// let inpExpr = <@ C<int>().Identity @>
+ ///
+ /// let implExpr =
+ /// match inpExpr with
+ /// | PropertyGet(Some _, PropertyGetterWithReflectedDefinition implExpr, [ ]) -> implExpr
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates implExpr to a quotation with the same structure as <@ fun (x: C<int>) () -> x @>, which is the implementation of the
+ /// property Identity. Note that the correct generic instantaition has been applied to the implementation to reflect
+ /// the the type at the callsite.
+ ///
+ ///
[]
- val (|PropertyGetterWithReflectedDefinition|_|) : propertyInfo:PropertyInfo -> Expr option
+ val (|PropertyGetterWithReflectedDefinition|_|): propertyInfo: PropertyInfo -> Expr option
/// An active pattern to recognize property setters that have an associated ReflectedDefinition
///
@@ -1305,9 +2201,30 @@ module DerivedPatterns =
///
/// The expression of the method definition if found, or None.
///
- ///
+ ///
+ ///
+ /// open FSharp.Quotations
+ /// open FSharp.Quotations.Patterns
+ /// open FSharp.Quotations.DerivedPatterns
+ ///
+ /// [<ReflectedDefinition>]
+ /// type C<'T>() =
+ /// member x.Count with set (v: int) = ()
+ ///
+ /// let inpExpr = <@ C<int>().Count <- 3 @>
+ ///
+ /// let implExpr =
+ /// match inpExpr with
+ /// | PropertySet(Some _, PropertySetterWithReflectedDefinition implExpr, [], _valueExpr) -> implExpr
+ /// | _ -> failwith "unexpected"
+ ///
+ /// Evaluates implExpr to a quotation with the same structure as <@ fun (x: C<int>) (v: int) -> () @>, which is the implementation of the
+ /// setter for the property Count. Note that the correct generic instantaition has been applied to the implementation to reflect
+ /// the the type at the callsite.
+ ///
+ ///
[]
- val (|PropertySetterWithReflectedDefinition|_|) : propertyInfo:PropertyInfo -> Expr option
+ val (|PropertySetterWithReflectedDefinition|_|): propertyInfo: PropertyInfo -> Expr option
/// Active patterns for traversing, visiting, rebuilding and transforming expressions in a generic way
[]
@@ -1321,10 +2238,11 @@ module ExprShape =
///
///
[]
- val (|ShapeVar|ShapeLambda|ShapeCombination|) :
- input:Expr -> Choice)> // ConstApp
+ val (|ShapeVar|ShapeLambda|ShapeCombination|):
+ input: Expr
+ -> Choice)> // ConstApp
/// Re-build combination expressions. The first parameter should be an object
/// returned by the ShapeCombination case of the active pattern in this module.
@@ -1333,4 +2251,6 @@ module ExprShape =
/// The list of arguments.
///
/// The rebuilt expression.
- val RebuildShapeCombination : shape:obj * arguments:list -> Expr
+ ///
+ ///
+ val RebuildShapeCombination: shape: obj * arguments: list -> Expr