F # on Linux as a cure for the soul

    Have you ever had the feeling that "this" is already tired? What do you want something new? “This one” can be anything: a game, a job, a car. Anything that repeats day after day. And in programming? Under the cut you will find a story about C # fatigue and a more interesting approach.

    I give the floor to the author.

    Recently, I’m a little tired of C #, endless lines of the same type of code cease to warm my soul over time. At such moments, sometimes you want to do something for the soul. In my case, these are Linux and F #.

    For the most part, it is important for me that I go out of my comfort zone. In general, I did just that, changed the system and language.

    Organizing my vacation, I was faced with the fact that it is not clear where to start. Let’s take a look at the situation with F # on Linux.


    • Need a lightweight syntax editor
    • Need F # Interactive Support
    • Need a .NET environment
    • Need a debugger (however, as always)

    Sophisticated habrozhiteli already realized that the " lightweight editor" + Microsoft = Visual Studio Code . I hope you already have it :)

    Let's get down to business

    So, we sorted out the editor’s choice, now with everything else in order:

    • You need to install the mono and fsharp package, for most Linux systems you will find instructions here . Although there are no Arch Linux (and distributions based on it) in the manual, these packages are, however, present in the standard pacman repository, and the instructions show how to compile from source, so there should be no problems.

    In principle, to start something already, this is enough, but then the article would quickly end.

    • We will also install .NET Core 2.0.0 (Runtime + SDK), again, for most systems you will find instructions here . For Arch Linux, the easiest way is to install the dotnet and dotnet-sdk-2.0 packages from AUR. If something, then here is github After that, we will go directly to the preparation of VS Code for our work.

    We will install extensions to support F # syntax, build and package management Nuget.

    For completeness, you can put a Nuget manager compatible with .Net Core.

    We will install the extension for debugging (Yes, everything is correct, it is written by C #).

    After that , we’re driving this rap , and then following the instructions we do:

    dotnet restore && code .

    Now we reboot VS Codeand wait until the extension of the "debugger" downloads its packages and normally deploys.

    In fact, now almost everything is ready, it remains only to test.

    • Create a folder somewhere, run the console there. Next we do:

    dotnet new console -lang F#
    dotnet run

    We get the cherished Hello World from F#!

    • Open VS Code in this code folder.
    • Go to Program.fs and select a piece of code and press Alt + Enter:

    the long-awaited F # Interactive will launch.

    It can also be used for more useful purposes:

    Next, let's see the assembly and debugging.

    • To configure the build directive, press Ctrl + Shift + B and select .Net Core.

    We do not need to change the automatically configured file.

    • After that, click again Ctrl+Shift+Band see that the assembly is successful:

    • After this F5, select .Net Core as well and then simply change the path to the program.

    • That's all, after that you can put a breakpoint (F9) on our only line and check the debugger:

    So, your machine is tuned and ready for new achievements in a wonderful functional language. A nice bonus will be that your achievements can be embedded in a C # project (by connecting .dll).

    Well, you never know who knew)

    about the author

    Maximilian Spiridonov - C # developer, student of Moscow Aviation Institute, Microsoft Student Partner. I came to professional development on .NET at school. He has been working with real projects on WPF (MVVM) + C # for more than 2.5 years, MySQL, he has been developing in C # for more than 5.5 years. The main area of ​​interest right now is mobile development on Xamarin. Also, by chance, in the area of ​​interest were C / C ++ and Linux.

    Previous article by Maximilian on C / C ++ on Linux in Visual Studio Code.

    We also invite you to chat on F # in Telegram.

    Also popular now: