function - 为什么只能在成员方法中将 F# 函数传递给 System.Func 参数?

标签 function f#

这有效:

type MyType () =
    static member MyFn (fn : Func<bool>) = fn.Invoke ()

MyType.MyFn (fun _ -> false)

这不是(错误 FS0002):

let myFn (fn : Func<bool>) = fn.Invoke ()

myFn (fun _ -> false)

这也不是(错误 FS0002):

type MyDU = Fn of Func<bool>

Fn (fun _ -> false)

造成这种相当烦人的不一致的原因是什么?

最佳答案

F# spec 的第 8.13.7 节(成员调用时的类型定向转换)涵盖了此行为,其中指出:

Note: These type-directed conversions are primarily for interoperability with existing member-based .NET libraries and do not apply at invocations of functions defined in modules or bound locally in expressions.

关于function - 为什么只能在成员方法中将 F# 函数传递给 System.Func 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35637310/

相关文章:

function - Haskell 的foldr 函数有多少个参数?

c - 如何在 C 中使用 void 指针作为函数返回类型

regex - 如何编写验证字母数字和空格的正则表达式

debugging - 将 OCaml 转换为 F# : Is there an OCaml IDE with GUI debugging like Visual Studio

wcf - MPI vs. Microsoft WCF vs. Microsoft TPL

JavaScript:异步函数是否创建新线程?

angularjs - ng-click 首先应用类,然后执行函数

c# - Silverlight F# 库和 WCF

F# Fable 和 JS 互操作 : unsafe list casting

c# - 在应用程序的某些部分需要完全并行的情况下,F# 是否优于 C#?