NoEagerConstraintApplicationAttribute Type
Adding this attribute to the method adjusts the processing of some generic methods during overload resolution.
During overload resolution, caller arguments are matched with called arguments
to extract type information. By default, when the caller argument type is unconstrained (for example
a simple value x
without known type information), and a method qualifies for
lambda constraint propagation, then member trait constraints from a method overload
are eagerly applied to the caller argument type. This causes that overload to be preferred,
regardless of other method overload resolution rules. Using this attribute suppresses this behaviour.
Example
Consider the following overloads:
type OverloadsWithSrtp() =
[<NoEagerConstraintApplicationAttribute>]
static member inline SomeMethod< ^T when ^T : (member Number: int) > (x: ^T, f: ^T -> int) = 1
static member SomeMethod(x: 'T list, f: 'T list -> int) = 2
let inline f x =
OverloadsWithSrtp.SomeMethod (x, (fun a -> 1))
type OverloadsWithSrtp = new: unit -> OverloadsWithSrtp static member SomeMethod: x: 'T list * f: ('T list -> int) -> int + 1 overload
--------------------
new: unit -> OverloadsWithSrtp
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
static member OverloadsWithSrtp.SomeMethod: x: 'T list * f: ('T list -> int) -> int
Constructors
Constructor |
Description
|
Full Usage:
NoEagerConstraintApplicationAttribute()
Returns: NoEagerConstraintApplicationAttribute
NoEagerConstraintApplicationAttribute
|
Creates an instance of the attribute
|