")">
Expr
The input expression to match against.
(Expr * Expr) option
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"
<@ true @>, <@ false @>
.An active pattern to recognize expressions that represent the application of a (possibly curried or tupled) first class function value
Expr
The input expression to match against.
(Expr * Expr list list) option
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"
[2; 1]
.
An active pattern to recognize constant boolean expressions
Expr
The input expression to match against.
bool option
When successful, the pattern binds the constant value from the input expression
open FSharp.Quotations.DerivedPatterns
match <@ true @> with
| Bool v -> v
| _ -> failwith "unexpected"
true
.
An active pattern to recognize constant byte expressions
Expr
The input expression to match against.
byte option
When successful, the pattern binds the constant value from the input expression
open FSharp.Quotations.DerivedPatterns
match <@ 8uy @> with
| Byte v -> v
| _ -> failwith "unexpected"
8uy
.
An active pattern to recognize constant unicode character expressions
Expr
The input expression to match against.
char option
When successful, the pattern binds the constant value from the input expression
open FSharp.Quotations.DerivedPatterns
match <@ 'a' @> with
| Char v -> v
| _ -> failwith "unexpected"
'a'
.
An active pattern to recognize constant decimal expressions
Expr
The input expression to match against.
decimal option
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"
8.0M
.
An active pattern to recognize constant 64-bit floating point number expressions
Expr
The input expression to match against.
float option
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"
1.0
.
An active pattern to recognize constant int16 expressions
Expr
The input expression to match against.
int16 option
When successful, the pattern binds the constant value from the input expression
open FSharp.Quotations.DerivedPatterns
match <@ 8s @> with
| Int16 v -> v
| _ -> failwith "unexpected"
8s
.
An active pattern to recognize constant int32 expressions
Expr
The input expression to match against.
int32 option
When successful, the pattern binds the constant value from the input expression
open FSharp.Quotations.DerivedPatterns
match <@ 8 @> with
| Int32 v -> v
| _ -> failwith "unexpected"
8
.
An active pattern to recognize constant int64 expressions
Expr
The input expression to match against.
int64 option
When successful, the pattern binds the constant value from the input expression
open FSharp.Quotations.DerivedPatterns
match <@ 8L @> with
| Int64 v -> v
| _ -> failwith "unexpected"
8L
.An active pattern to recognize expressions that represent a (possibly curried or tupled) first class function value
Expr
The input expression to match against.
(Var list list * Expr) option
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"
[["a1"; "a2"]; ["b"]]
.
(|MethodWithReflectedDefinition|_|) methodBase
MethodBase
- The description of the method.Expr option
The expression of the method definition if found, or None.An active pattern to recognize methods that have an associated ReflectedDefinition
MethodBase
The description of the method.
Expr option
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"
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 instantiation has been applied to the implementation to reflect the type at the callsite.
An active pattern to recognize expressions of the form a || b
Expr
The input expression to match against.
(Expr * Expr) option
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"
<@ true @>, <@ false @>
.
(|PropertyGetterWithReflectedDefinition|_|) propertyInfo
PropertyInfo
- The description of the property.Expr option
The expression of the method definition if found, or None.An active pattern to recognize property getters or values in modules that have an associated ReflectedDefinition
PropertyInfo
The description of the property.
Expr option
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"
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 instantiation has been applied to the implementation to reflect the type at the callsite.
(|PropertySetterWithReflectedDefinition|_|) propertyInfo
PropertyInfo
- The description of the property.Expr option
The expression of the method definition if found, or None.An active pattern to recognize property setters that have an associated ReflectedDefinition
PropertyInfo
The description of the property.
Expr option
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"
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 instantiation has been applied to the implementation to reflect the type at the callsite.
An active pattern to recognize constant signed byte expressions
Expr
The input expression to match against.
sbyte option
When successful, the pattern binds the constant value from the input expression
open FSharp.Quotations.DerivedPatterns
match <@ 8y @> with
| SByte v -> v
| _ -> failwith "unexpected"
8y
.
An active pattern to recognize constant 32-bit floating point number expressions
Expr
The input expression to match against.
float32 option
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"
1.0f
.
(|SpecificCall|_|) templateParameter
Expr
- The input template expression to specify the method to call.Expr -> (Expr option * Type list * Expr list) option
The optional target object (present if the target is an instance method), the generic type instantiation (non-empty if the target is a generic instantiation), and the arguments to the function or method.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 instance method), the generic type instantiation (non-empty if the target is a generic instantiation), and the arguments to the function or method.
Expr
The input template expression to specify the method to call.
Expr -> (Expr option * Type list * Expr list) option
The optional target object (present if the target is an 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"
<@ "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"
<@ "hello" @>
.
An active pattern to recognize constant string expressions
Expr
The input expression to match against.
string option
When successful, the pattern binds the constant value from the input expression
open FSharp.Quotations.DerivedPatterns
match <@ "a" @> with
| String v -> v
| _ -> failwith "unexpected"
"a"
.
An active pattern to recognize constant unsigned int16 expressions
Expr
The input expression to match against.
uint16 option
When successful, the pattern binds the constant value from the input expression
open FSharp.Quotations.DerivedPatterns
match <@ 8us @> with
| UInt16 v -> v
| _ -> failwith "unexpected"
8us
.
An active pattern to recognize constant unsigned int32 expressions
Expr
The input expression to match against.
uint32 option
When successful, the pattern binds the constant value from the input expression
open FSharp.Quotations.DerivedPatterns
match <@ 8u @> with
| UInt32 v -> v
| _ -> failwith "unexpected"
8u
.
An active pattern to recognize constant unsigned int64 expressions
Expr
The input expression to match against.
uint64 option
When successful, the pattern binds the constant value from the input expression
open FSharp.Quotations.DerivedPatterns
match <@ 8UL @> with
| UInt64 v -> v
| _ -> failwith "unexpected"
8UL
.
An active pattern to recognize ()
constant expressions
Expr
The input expression to match against.
unit option
When successful, the pattern does not bind any results
open FSharp.Quotations.DerivedPatterns
match <@ () @> with
| Unit v -> v
| _ -> failwith "unexpected"
true
.