Is it possible to use System.Type as a static parameter in a provider of type F #?

I was wondering if System.Type can be used as a static parameter in a provider like F # so that I can write something like:

type HelperType = HelperProvider<typeof<int>> 

The idea is whether it is possible to allow a type provider to generate some helper type based on some .NET type.

+6
source share
1 answer

No, type provider parameters can only be primitive types (for example, int and string ). The best you can do is take the type name as a string:

 type HelperType = HelperProvider<"int"> 

This will do the trick for primitive (and standard types), but will not work for types that are previously defined in the file (or in the project) where you use the type provider.

As far as I know, this is definitely what the F # team is learning - this will allow some interesting metaprogramming applications. Currently, the focus is on data access, so this was not such a priority (due to curiosity, which application do you mean?)

By the way, passing types as parameters can raise some interesting complex questions. For example, how the handler handles something like this:

 type A = MyProvider<B> and B = MyProvider<A> 
+7
source

All Articles