Header menu logo FSharp.Core

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))
Multiple items
type OverloadsWithSrtp = new: unit -> OverloadsWithSrtp static member SomeMethod: x: 'T list * f: ('T list -> int) -> int + 1 overload

--------------------
new: unit -> OverloadsWithSrtp
'T
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int
val x: 'T (requires member Number)
val f: ('T -> int) (requires member Number)
val x: 'T list
type 'T list = List<'T>
val f: ('T list -> int)
val f: x: 'a -> int (requires member Number)
val x: 'a (requires member Number)
static member OverloadsWithSrtp.SomeMethod: x: 'T * f: ('T -> int) -> int (requires member Number)
static member OverloadsWithSrtp.SomeMethod: x: 'T list * f: ('T list -> int) -> int
val a: 'a (requires member Number)
With the attribute, the overload resolution fails, because both members are applicable. Without the attribute, the overload resolution succeeds, because the member constraint is eagerly applied, making the second member non-applicable.

Constructors

Constructor Description

NoEagerConstraintApplicationAttribute()

Full Usage: NoEagerConstraintApplicationAttribute()

Returns: NoEagerConstraintApplicationAttribute NoEagerConstraintApplicationAttribute

Creates an instance of the attribute

Returns: NoEagerConstraintApplicationAttribute

NoEagerConstraintApplicationAttribute

Type something to start searching.