Why does "override val" not exist in f#?

Viewed 75
1 Answers

There is a thing called override val in F#, it did make it into the language. The example on page 155 compiles:

type MyBase () =
    abstract Property : string with get, set
    default val Property = "default" with get, set
type MyDerived() =
    inherit MyBase()
    override val Property = "derived" with get, set

Typing this into FSI shows that the overridden val is properly accessed and returned:

> type MyBase =
  new: unit -> MyBase
  abstract Property: string
  override Property: string
type MyDerived =
  inherit MyBase
  new: unit -> MyDerived
  override Property: string

> MyDerived().Property;;
val it: string = "derived"

I agree though, that the docs should also mention it. At best you could say it is said implicitly, where (under "Interfaces") it says that you can use val or members with override or default. This should certainly be improved.

Related