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

5
什么导致了第一次实现失败?
type IToto  = 
    abstract Toto : unit -> unit

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

{ new IToto with  
        member this.Toto () = ()  }
1个回答

6
在编译表示中,函数类型的属性与获取 unit 并返回 unit 的方法存在区别。函数类型编译为 FSharpFunc<unit, unit> Toto { get; },而获取 unit 并返回 unit 的方法编译为 unit Toto()
第一个对象表达式实现了不同的接口:
type IToto  = 
    abstract Toto : (unit -> unit) // Note: Parentheses around the function type!

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

1
这变得微妙了。我喜欢。 - nicolas

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接