I was wondering is it possible to use System.Type as the static parameter in F# type provider, so that I can write something like:
type HelperType = HelperProvider<typeof<int>>
The idea is, is it possible to let type provider generating some helper type based on some .NET type.
No, type provider parameters can only be of primitive types (like int
and string
). The best you can do is to take the type name as a string:
type HelperType = HelperProvider<"int">
This will do the trick for primitive (and standard types), but it won't work for types that are defined earlier in the file (or in the project) where you're using the type provider.
As far as I know, this is definitely something that the F# team has been looking into - it would allow some interesting meta-programming applications. The main focus for now has been on data access, so this has not been such a priority (out o curiosity, what application do you have in mind?)
By the way - passing types as parameters can cause some interesting tricky questions. For example, how would the compiler handle something like this:
type A = MyProvider<B>
and B = MyProvider<A>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With