Is it possible to create a generic type via type providers so that
[<TypeProvider>]
type SampleTypeProvider(config: TypeProviderConfig) as this =
...
//the below would be the generated type
type A<'b> () =
member this.C() : 'b = ...
member this.D() : 'b = ...
//
...
[<assembly:TypeProviderAssembly>]
do()
....
so that in the usage scenario would look something to
#r @".\bin\Debug\SampleTypeProvider.dll"
type A = SampleTypeProvider.A
type intA = A<int>
type strA = A<str>
And if that is possible - How can I approach it.
This is not possible using standard methods. I tried looking around, but could not find a canonical reference, but it is a known limitation and there have been various suggestions to lift the restriction.
Ross McKinlay has a somewhat extreme project called Mixin type provider that works around this by actually generating a file with F# source code when type provider is run (and you can then include this file in your project). This is perhaps more code-generation than type provider, but his talk about the topic is also a good explanation of some of the limitations.
How to address this very much depends on the purpose of the type provider. If you only need limited number of types, you could use something like static parameters and write A<"int">
or A<"string">
. You could also mix ordinary non-provided generic types with non-generic provided types (in some clever way). But I think you need to write more about your concrete use case to get a better answer.