I think @kvb gives a good overview of some of the technical difficulties. I agree type inference would be problematic - you would be basically limited to using provider generated types locally, similarly to anonymous types. I think C# might come with something similar in Roslyn, but I doubt it will be as elegantly and smoothly integrated as in F# (where type providers are actually language feature and not just tool).
To answer your two specific questions:
[How can I] use the F# 3.0 providers in C# code?
The F# type providers are really only understood by F# compiler, so you'll need to use them from F#. For generative type providers (SQL, Entities, WSDL, config files), you can reference the provider from F# and use the generated types from C# projects.
For erasing type providers you won't be able to do this, because the types do not really exist and only F# can see them. So the best option is to write your processing code in F# and return results as collections of records or other types that are easily consumed from C#.
What would a C# implementation need to be able to use them?
I could, of course, just say "C# would have to support type providers!", but here are some more thoughts. Type providers are just .NET assemblies and they do not use any F#-specific types. The ITypeProvider
interface could be consumed by any .NET language including C#, so if C# designers wanted, they could reuse all the great providers already built for F#.
So, submit this suggestion to the C# user voice or advocate it elsewhere (or convince the Mono team to implement this!) and perhaps it will be added in C# (vNext + 1 + ...
). For now, you'll only get all the benefits in F#.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…