是什么让第一个实现 KO ?
type IToto =
abstract Toto : unit -> unit
{ new IToto with
member this.Toto =
fun () -> () }
{ new IToto with
member this.Toto () = () }
最佳答案
在编译表示中,函数类型的属性之间存在差异,编译为FSharpFunc<unit, unit> Toto { get; }
, 以及取单元和返回单元的方法,编译为unit Toto()
.
第一个对象表达式实现了一个不同的接口(interface):
type IToto =
abstract Toto : (unit -> unit) // Note: Parentheses around the function type!
{ new IToto with
member this.Toto =
fun () -> () }
关于interface - F# 中的对象表达式和捕获的状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15246660/