As Brian suggests, you can use the as this clause. However, in F # it is usually recommended to use a subclass (inheritance) only when there is a really good reason for this (for example, you need to implement some kind of virtual class and pass it to the .NET library).
If I implemented your example, I would prefer the return IDisposable function with a simple object expression:
let disposableOpenClose(openargs) = let oc = new OpenCloseClass() oc.Open(openargs) { new IDisposable with member this.Dispose() = oc.Close() } let f() = use docc = disposableOpenClose(42) printfn "inside"
At some point, this is just a personal preference, but I think this is the preferred option because it is simpler than using inheritance (although I don't have any document for reference here :-)). Also, compiled code might be a little simpler, as some execution checks may be required to process as this .
Tomas petricek
source share