Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could F# type providers be incorporated in C#

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?

like image 458
carstenj Avatar asked Dec 07 '12 22:12

carstenj


People also ask

What plane replaced F-16?

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.

What can defeat F-22?

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.

What is the newest fighter jet in the US?

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.

What planes will the F-35 replace?

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.


1 Answers

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#.

like image 86
Tomas Petricek Avatar answered Oct 23 '22 21:10

Tomas Petricek