Conversion of lambda expressions to Func

后端 未结 1 1606
逝去的感伤
逝去的感伤 2021-01-15 06:31

Given the following:

open System.Linq

let seqA = { 1..10 }

this works:

seqA.All (fun n -> n > 0)

H

相关标签:
1条回答
  • 2021-01-15 06:57

    This is covered in the (rather involved) section of the spec on Method Resolution and again in Type-directed Conversions at Member Invocations. Quoting from the latter:

    As described in Method Application Resolution (see §14.4), two type-directed conversions are applied at method invocations.

    The first type-directed conversion converts anonymous function expressions and other function-valued arguments to delegate types. Given:

    • A formal parameter of delegate type D
    • An actual argument farg of known type ty1 -> ... -> tyn -> rty
    • Precisely n arguments to the Invoke method of delegate type D

    Then:

    • The parameter is interpreted as if it were written:
      new D(fun arg1 ... argn -> farg arg1 ... argn)

    It seems to suggest this conversion would be applied to any function value, but observation suggests it's applied only to anonymous functions.

    0 讨论(0)
提交回复
热议问题