How to define a static member in an Interface?
Why it is not possible?
I want to force a F# type (class) to have a static method to create an instance of itself from a string (JSON parsing). I want this Interface example:
[<Interface>]
type public ILikeJson<'T> =
abstract member ToJson: unit -> string // OK
static abstract member FromJson: string -> 'T // <-- "static" is not valid here !
Alternatively a constructor from a string can do the work but a static method sounds better because it will have an appropriate name and I don't know how to define a constructor in the Interface too.
dotnet fsi
:type I = static abstract i: unit -> string;; type A = A interface I with static member i () = "lofa";;
(albeit, I couldn't figure out how to use it asA.i()
will blow up... I also couldn't find any docs other than the linked RFC itself). – Magnesium