Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

object expression and captured state in F#

Tags:

interface

f#

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 () = ()  }
like image 764
nicolas Avatar asked Mar 06 '13 11:03

nicolas


1 Answers

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 () -> () }
like image 102
Tomas Petricek Avatar answered Oct 11 '22 16:10

Tomas Petricek