The cool new F# 3.0 feature type providers can be used to bridge the mismatch between F# data types or classes and data source structures like XML or WSDL. However this mismatch is also a challenge in other .NET languages like C#.
I'd like to use the F# 3.0 providers in C# code. How can I do this, if at all? Further, if we cannot, what would a C# implementation need to be able to use them?
The U.S. Air Force has expressed interest in a new, non-stealthy fighter jet to replace the F-16. Several aviation experts have banded together and invented a new jet out of thin air. The result, the F-36 Kingsnake, would use the F-22's engines, place less of an emphasis on stealth, and use digital engineering.
Sukhoi Su-57 (formerly known as PAK FA) The Russian Sukhoi Su-57 is one of the few rival fifth-generation fighters that currently exist, and its creators insist that it not only rivals the F-22, but some even claim it's better in air-to-air and air-to-surface operations.
But missing from most of the aerial action—both on screen and in real life—is the much anticipated but also delayed F-35 Lightning II, the military's newest fighter jet.
The Air Force completed that evaluation in 2019. The service now plans to gradually decommission A-10s beginning in fiscal year 2023, which starts on October 1, 2022. The process will begin with the divestment of 21 A-10s that will temporarily be replaced by F-16s before the F-35 takes over the Warthog's mission.
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#.
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