Bruno Fiorentino
Bruno Fiorentino

Reputation: 311

Is it possible to declare an abstract auto-implemented property in F#?

I'm trying to do the following F# equivalent:

[C#]
public virtual int Property { get; set; }

But this code (and many other combinations) does not work:

[F#]
abstract member Id: int with get, set
default val this.Id = 123 with get, set

Upvotes: 5

Views: 724

Answers (2)

Brian
Brian

Reputation: 118865

It's not possible in the Dev11 preview.

Upvotes: 5

Alastair Pitts
Alastair Pitts

Reputation: 19601

Ok, looking at the MSDN documentation on F# properties, this line in the abstract properties immediately jumps out:

Alternatively, abstract can just mean that a property is virtual, and in that case, a definition must be present in the same class.

The example syntax they give is:

type Base1() =
   let mutable value = 10
   abstract Property1 : int with get, set
   default this.Property1 with get() = value and set(v : int) = value <- v

Now I'm not overly familiar with F#, but my guess is that you could set let mutable value = 10 to your requirement of let mutable value = 123

Upvotes: 1

Related Questions