I’ve struggled with this problem for quite some time now, and can’t seem to find any solution. Let me simplify it for you.
I have a generic function that I want to call, but the type argument I want to call it with only as an instance. Example
let foo_a<'a> () = typeof<'a>
let foo_b (t : System.Type) = foo_a<t>() // of course this does not work
I would like the following statement to be true
foo_a<int>() = foo_b(typeof<int>)
In C# I would’ve reflected out foo_a’s MethodInfo and do MakeGenericMethod(t), but how do I do this in F#?
Just to clearify, flipping the dependency and making foo_a calling foo_b instead, is not an option for me.
As @svick said, there’s no special way to do this in F# — you need to use Reflection just like you would in C#.
Here’s a simple example you can paste into F# interactive:
Output: