Object expression and captured state in F #

What does the first KO implementation do?

type IToto  = 
    abstract Toto : unit -> unit

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

{ new IToto with  
        member this.Toto () = ()  }
+5
source share
1 answer

In the compilation view, there is a difference between a property of a function type compiled as FSharpFunc<unit, unit> Toto { get; }, and a method that takes a block and returned block compiled as unit Toto().

The first expression of the object implements a different interface:

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

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

All Articles