Reputation: 2415
This works:
type MyType () =
static member MyFn (fn : Func<bool>) = fn.Invoke ()
MyType.MyFn (fun _ -> false)
This does not (error FS0002):
let myFn (fn : Func<bool>) = fn.Invoke ()
myFn (fun _ -> false)
Neither does this (error FS0002):
type MyDU = Fn of Func<bool>
Fn (fun _ -> false)
What is the reason for this rather annoying inconsistency?
Upvotes: 8
Views: 405
Reputation: 55184
This behavior is covered by section 8.13.7 (Type-directed Conversions at Member Invocations) of the F# spec, where it states:
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.
Upvotes: 12