I'm not going to claim that I have a very elegant solution, but the following works.
Assume that the MyFunc
method is declared on Class1
.
You can declare the MyType
record like this:
type MyType = {
MyFunc: Foo * Bar * option<int> -> Qux
}
This doesn't enable you to directly assign the original MyFunc
method to the record, but a little helper function does:
let myFunc (h : Class1) (foo, bar, baz : int option) =
match baz with
| Some(i) -> h.MyFunc(foo, bar, i)
| _ -> h.MyFunc(foo, bar)
Now you can create a value of MyType
like this:
let mt = { MyFunc = myFunc c1 }
assuming that c1
is an instance of Class1
.
You can now use it to get various values of Qux
:
let q2 = mt.MyFunc(Foo(), Bar(), None)
let q3 = mt.MyFunc(Foo(), Bar(), Some(42))