Hi there,
F# 1.9.4 only supports "explicit" interface implementations. Implicit interface implementations have been requested and it is likely we'll support them in a future version of F#.
However, it's also worth learning other techniques for partial implementations of objects. For example, you can simulate many partial implementation techniques through function parameters, object expressions and/or optional arguments. For example, consider the following
type IProduct =
abstract Name: string
abstract Work: unit -> unit
let BuildProduct(name) =
{ new IProduct with
member x.Name = name
member x.Work() = printfn "work" }
Here an object expression has been used for your original request (Name variable, Work fixed). More generally, a object builder parameterized by optional arguments with sensible defaults can be quite flexible :
type ProductBuilders =
static member BuildProduct(?name,?work) =
{ new IProduct with
member x.Name = match name with None -> "" | Some n -> n
member x.Work() = match work with None -> () | Some f -> f() }
ProductBuilders.BuildProduct(name="1")
ProductBuilders.BuildProduct(work=(fun () -> printfn "work"))
ProductBuilders.BuildProduct(name="3",work=(fun () -> printfn "work"))
You may also define types that implement an interface in a similar way:
type Product(?name,?work) =
interface IProduct with
member x.Name = match name with None -> "" | Some n -> n
member x.Work() = match work with None -> () | Some f -> f()
let p = (Product(name="1") :> IProduct)
Kind regards
don