object expression and captured state in F#

放肆的年华 提交于 2019-12-10 14:56:33

问题


What makes the first implementation KO ?

type IToto  = 
    abstract Toto : unit -> unit

{ new IToto with  
      member this.Toto = 
             fun () -> () }

{ new IToto with  
        member this.Toto () = ()  }

回答1:


In the compile representation, there is a difference between property of a function type, compiled as FSharpFunc<unit, unit> Toto { get; }, and a method taking unit and returning unit, compiled as unit Toto().

The first object expression implements a different interface:

type IToto  = 
    abstract Toto : (unit -> unit) // Note: Parentheses around the function type!

{ new IToto with  
      member this.Toto = 
             fun () -> () }


来源:https://stackoverflow.com/questions/15246660/object-expression-and-captured-state-in-f

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!