这有效:
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/