Is it possible to convert F # code to C # code?

The reason I ask is because I am learning F # and want to compete in TopCoder. However, F # is not included in the list of languages ​​supported there. But C # is on the list (frankly, this applies to almost all online coding competitions, with the exception of the Google Code Jam and Facebook Hacker cup).

Possible workarounds that I can think of right now are 1) to find a translator who can translate the F # source code directly to C # 2) first compile the F # code into a .net executable file and then break it into C # code

The minimum requirement is that the generated C # must be able to compile into an executable .net executable file, preferably as little external dependency as possible.

The first approach seems unlikely, a quick Google search has nothing to do. The approach of the two looks more promising; there are .net disassemblers.

I tried the most popular --- Red Gate Reflector. Although it knows how to smooth C # executables, it seems to have problems with executables compiled from F #: it is happily parsed, but the resulting C # code has some special characters, such as adding a leading $ sign to the class name and other weird stuff, so it cannot be compiled. I used Visual Studio 2010 Professional, the latest beta version of Reflector (which is free).

Am I missing something? Is it possible?

Update: It seems like it's still not possible. While I'm using C #.

+4
source share
1 answer

As already noted in the comments, if there is some way to do this, there will be quite a few unpleasant cases where it probably will not work, and it will be very fragile ...

One way to solve the problem (for you) is to simply write the solution in F # and then rewrite it in C #. This may seem silly, but there are some advantages:

  • In F #, you can easily prototype a solution so that you can quickly find the right solution.
  • When translating code into C #, you are most likely to use functions such as lambda expressions, so it can even improve your C # skills ...
  • If you rely on .NET libraries, this part of the code is easy to translate.

Of course, it would be best to convince the organizers that they should support F # (which is probably not too difficult if they allow C # already), but I understand that this can be a problem.

+6
source

Source: https://habr.com/ru/post/1337342/


All Articles