Hacker News new | ask | show | jobs
by FlorianRappl 2457 days ago
I don't expect the C# compiler to understand F#, but in my opinion there should be language independent ways to create CLR assemblies. MSBuild (which calls the right compiler for each project) could also understand (and did iirc) compiler-independent project types that still produce assemblies, however, from mixed sources. Now the C# compiler would only be called for the C# sources.

> Basically a single assembly has to be written in the same language.

This is like saying a single js file has to come from only js files, still bundlers today merge all kinds of types in there - in a single sweep.

I am not writing this since I think mixing C#/F# is the future (well, it would be cool), but because it could allow the C# ecosystem to improve. Right now the best thing we have for metaprogramming in C# is Fody; and I personally think we could do better.

Hopefully this expressed my idea a little bit better.

1 comments

The C# (and other .NET compilers) treat an assembly as the smallest unit they will emit. You'd have to change that to some semblance of "object files" instead along with a "linker" step afterwards to allow for an assembly to be made up of different languages. Again, this is how the compilers work currently, so MSBuild (well, the default targets) just go along with this. This has nothing to do with MSBuild, which basically just tracks items, properties, targets, and tasks. It doesn't care about the semantics of all that.

Or, you know, use ILMerge, which is pretty much the equivalent of the JS bundlers you mention. With some custom MSBuild targets you should be able to create a project file that contains C# and F# files, both of them compile to intermediate assemblies (although you can't have circular dependencies between both), and a step afterwards merges the assemblies into the actual one.

> The C# (and other .NET compilers) treat an assembly as the smallest unit they will emit.

`<OutputType>module</OutputType>` in your project file (or `/target:module` at the command line, and you get a smaller unit.

Ah, learned something new today. Thanks.