DerivedPatterns Module
Contains a set of derived F# active patterns to analyze F# expression objects
Active patterns
Active pattern |
Description
|
|
An active pattern to recognize expressions of the form
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer AndAlso: Quotations.Expr -> (Quotations.Expr * Quotations.Expr) option
val a: Quotations.Expr
val b: Quotations.Expr
val failwith: message: string -> 'T
Evaluates to <@ true @>, <@ false @> .
|
An active pattern to recognize expressions that represent the application of a (possibly curried or tupled) first class function value
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module Patterns
from Microsoft.FSharp.Quotations
namespace Microsoft.FSharp
module DerivedPatterns
from Microsoft.FSharp.Quotations
val f: (int * int -> int -> obj)
active recognizer Lambda: Quotations.Expr -> (Quotations.Var * Quotations.Expr) option
active recognizer Applications: Quotations.Expr -> (Quotations.Expr * Quotations.Expr list list) option
val f: Quotations.Expr
val curriedArgs: Quotations.Expr list list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val map: mapping: ('T -> 'U) -> list: 'T list -> 'U list
val args: Quotations.Expr list
property List.Length: int with get
val failwith: message: string -> 'T
Evaluates to [2; 1] .
|
|
|
An active pattern to recognize constant boolean expressions
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer Bool: Quotations.Expr -> bool option
val v: bool
val failwith: message: string -> 'T
Evaluates to true .
|
|
An active pattern to recognize constant byte expressions
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer Byte: Quotations.Expr -> byte option
val v: byte
val failwith: message: string -> 'T
Evaluates to 8uy .
|
|
An active pattern to recognize constant unicode character expressions
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer Char: Quotations.Expr -> char option
val v: char
val failwith: message: string -> 'T
Evaluates to 'a' .
|
|
An active pattern to recognize constant decimal expressions
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer Decimal: Quotations.Expr -> decimal option
val v: decimal
val failwith: message: string -> 'T
Evaluates to 8.0M .
|
|
An active pattern to recognize constant 64-bit floating point number expressions
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer Double: Quotations.Expr -> float option
val v: float
val failwith: message: string -> 'T
Evaluates to 1.0 .
|
|
An active pattern to recognize constant int16 expressions
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer Int16: Quotations.Expr -> int16 option
val v: int16
val failwith: message: string -> 'T
Evaluates to 8s .
|
|
An active pattern to recognize constant int32 expressions
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer Int32: Quotations.Expr -> int32 option
val v: int32
val failwith: message: string -> 'T
Evaluates to 8 .
|
|
An active pattern to recognize constant int64 expressions
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer Int64: Quotations.Expr -> int64 option
val v: int64
val failwith: message: string -> 'T
Evaluates to 8L .
|
An active pattern to recognize expressions that represent a (possibly curried or tupled) first class function value
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module Patterns
from Microsoft.FSharp.Quotations
namespace Microsoft.FSharp
module DerivedPatterns
from Microsoft.FSharp.Quotations
val a1: obj
val a2: obj
val b: obj
active recognizer Lambdas: Quotations.Expr -> (Quotations.Var list list * Quotations.Expr) option
val curriedVars: Quotations.Var list list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val map: mapping: ('T -> 'U) -> list: 'T list -> 'U list
val arg: Quotations.Var
property Quotations.Var.Name: string with get
val failwith: message: string -> 'T
Evaluates to [["a1"; "a2"]; ["b"]] .
|
|
Full Usage:
(|MethodWithReflectedDefinition|_|) methodBase
Parameters:
MethodBase
-
The description of the method.
Returns: Expr option
The expression of the method definition if found, or None.
|
An active pattern to recognize methods that have an associated ReflectedDefinition
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
namespace Microsoft.FSharp
module Patterns
from Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
Multiple items
type ReflectedDefinitionAttribute = inherit Attribute new: unit -> ReflectedDefinitionAttribute + 1 overload member IncludeValue: bool -------------------- new: unit -> ReflectedDefinitionAttribute new: includeValue: bool -> ReflectedDefinitionAttribute val f: x: 'a -> 'a * 'a
val x: 'a
val inpExpr: Expr<int * int>
val implExpr: Expr
active recognizer Call: Expr -> (Expr option * System.Reflection.MethodInfo * Expr list) option
union case Option.None: Option<'T>
active recognizer MethodWithReflectedDefinition: System.Reflection.MethodBase -> Expr option
val _argExpr: Expr
val failwith: message: string -> 'T
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 instantiation has been applied to the implementation to reflect
the type at the callsite.
|
|
An active pattern to recognize expressions of the form
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer OrElse: Quotations.Expr -> (Quotations.Expr * Quotations.Expr) option
val a: Quotations.Expr
val b: Quotations.Expr
val failwith: message: string -> 'T
Evaluates to <@ true @>, <@ false @> .
|
Full Usage:
(|PropertyGetterWithReflectedDefinition|_|) propertyInfo
Parameters:
PropertyInfo
-
The description of the property.
Returns: 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
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
namespace Microsoft.FSharp
module Patterns
from Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
Multiple items
type ReflectedDefinitionAttribute = inherit Attribute new: unit -> ReflectedDefinitionAttribute + 1 overload member IncludeValue: bool -------------------- new: unit -> ReflectedDefinitionAttribute new: includeValue: bool -> ReflectedDefinitionAttribute type C<'T> =
new: unit -> C<'T>
member Identity: C<'T>
'T
val x: C<'T>
val inpExpr: Expr<C<int>>
new: unit -> C<'T>
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val implExpr: Expr
active recognizer PropertyGet: Expr -> (Expr option * System.Reflection.PropertyInfo * Expr list) option
union case Option.Some: Value: 'T -> Option<'T>
active recognizer PropertyGetterWithReflectedDefinition: System.Reflection.PropertyInfo -> Expr option
val failwith: message: string -> 'T
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 instantiation has been applied to the implementation to reflect
the type at the callsite.
|
Full Usage:
(|PropertySetterWithReflectedDefinition|_|) propertyInfo
Parameters:
PropertyInfo
-
The description of the property.
Returns: Expr option
The expression of the method definition if found, or None.
|
An active pattern to recognize property setters that have an associated ReflectedDefinition
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
namespace Microsoft.FSharp
module Patterns
from Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
Multiple items
type ReflectedDefinitionAttribute = inherit Attribute new: unit -> ReflectedDefinitionAttribute + 1 overload member IncludeValue: bool -------------------- new: unit -> ReflectedDefinitionAttribute new: includeValue: bool -> ReflectedDefinitionAttribute type C<'T> =
new: unit -> C<'T>
member Count: int with set
'T
val x: C<'T>
val set: elements: 'T seq -> Set<'T> (requires comparison)
val v: int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val inpExpr: Expr<unit>
new: unit -> C<'T>
val implExpr: Expr
active recognizer PropertySet: Expr -> (Expr option * System.Reflection.PropertyInfo * Expr list * Expr) option
union case Option.Some: Value: 'T -> Option<'T>
active recognizer PropertySetterWithReflectedDefinition: System.Reflection.PropertyInfo -> Expr option
val _valueExpr: Expr
val failwith: message: string -> 'T
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 instantiation has been applied to the implementation to reflect
the type at the callsite.
|
|
An active pattern to recognize constant signed byte expressions
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer SByte: Quotations.Expr -> sbyte option
val v: sbyte
val failwith: message: string -> 'T
Evaluates to 8y .
|
|
An active pattern to recognize constant 32-bit floating point number expressions
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer Single: Quotations.Expr -> float32 option
val v: float32
val failwith: message: string -> 'T
Evaluates to 1.0f .
|
Full Usage:
(|SpecificCall|_|) templateParameter
Parameters:
Expr
-
The input template expression to specify the method to call.
Returns: 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.
ExampleMatch a specific call to Console.WriteLine taking one string argument:
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
namespace Microsoft.FSharp
module Patterns
from Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
val inpExpr: Expr<obj>
active recognizer SpecificCall: Expr -> Expr -> (Expr option * System.Type list * Expr list) option
union case Option.None: Option<'T>
val argExpr: Expr
val failwith: message: string -> 'T
Evaluates to a quotation with the same structure as <@ "hello" @> .
ExampleCalls to this active pattern can be partially applied to pre-evaluate some aspects of the matching. For example:
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
namespace Microsoft.FSharp
module Patterns
from Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer SpecificCall: Expr -> Expr -> (Expr option * System.Type list * Expr list) option
val inpExpr: Expr<obj>
active recognizer ConsoleWriteLineOneArg: Expr<obj> -> (Expr option * System.Type list * Expr list) option
union case Option.None: Option<'T>
val argExpr: Expr
val failwith: message: string -> 'T
Evaluates to a quotation with the same structure as <@ "hello" @> .
|
|
An active pattern to recognize constant string expressions
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
Multiple items
active recognizer String: Quotations.Expr -> string option -------------------- module String from Microsoft.FSharp.Core val v: string
val failwith: message: string -> 'T
Evaluates to "a" .
|
|
An active pattern to recognize constant unsigned int16 expressions
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer UInt16: Quotations.Expr -> uint16 option
val v: uint16
val failwith: message: string -> 'T
Evaluates to 8us .
|
|
An active pattern to recognize constant unsigned int32 expressions
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer UInt32: Quotations.Expr -> uint32 option
val v: uint32
val failwith: message: string -> 'T
Evaluates to 8u .
|
|
An active pattern to recognize constant unsigned int64 expressions
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer UInt64: Quotations.Expr -> uint64 option
val v: uint64
val failwith: message: string -> 'T
Evaluates to 8UL .
|
|
An active pattern to recognize
Example
Multiple items
namespace Microsoft.FSharp -------------------- namespace FSharp namespace Microsoft.FSharp.Quotations
module DerivedPatterns
from Microsoft.FSharp.Quotations
active recognizer Unit: Quotations.Expr -> unit option
val v: unit
val failwith: message: string -> 'T
Evaluates to true .
|