问题
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