我的风格:
open System
type MyType (myFn : unit -> bool) =
member this.MyResult with get () = myFn ()
new (myFn : Func<bool>) = MyType (myFn.Invoke)
我得到的错误:
A unique overload for method 'MyType' could not be determined based on type information prior to this program point. A type annotation may be needed. Candidates: new : myFn:(unit -> bool) -> MyType, new : myFn:Func<bool> -> MyType
既然我已经提供了类型注释,那么什么不起作用的真正原因是什么?
如果F#需要Func<bool>
委托,则它将能够调用构造函数。因此,只需执行一次重载即可Func<bool>
对C#和F#都适用:
open System
type MyType (myFn : Func<bool>) =
member this.MyResult with get () = myFn.Invoke ()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句