F#中的对象表达和捕获状态

时间:2013-03-06 11:53:37

标签: interface f#

第一次实施KO的原因是什么?

type IToto  = 
    abstract Toto : unit -> unit

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

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

1 个答案:

答案 0 :(得分:6)

在编译表示中,函数类型的属性(编译为FSharpFunc<unit, unit> Toto { get; })与获取单位和返回单位的方法之间存在差异,编译为unit Toto()

第一个对象表达式实现了不同的接口:

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

{ new IToto with  
      member this.Toto = 
             fun () -> () }
相关问题