Programming Languages Section

F# Programming Language

What is Fsharp Programming Language
Post by Amina Delali, January 03rd, 2023

Some Facts

The F# programming language, is a .NET language that combines valuable features of three different programming languages: C#, python, and Java. It is a functional, imperative, and an object oriented programming language that is free and open source.
It is a robust and performant language that can generate; with the righ tools, JavaScript and GPU code, and that can be used to develop web, cloud, data-sience, and mobile applications. The library is also a .NET Standard 2.0 compatible framework

One of the known applications written by F# is Buckaroo C++ package manager (and friends) that allow you to easily integrate a large ecosystem of projects to your C++ application.

There is also the Vaughan - F# music library that allows you to work with music theory and also to create music programmatically.



How to install it

  • on Windows:

    There are multiple ways in which you can install F# on your Windows system. This is the one that I tested:

    1. First, you have to install .NET Core SDK. On the download page (same previous link) you may find 2 versions. The one I have tested is the recommended .NET 7.0, and it worked just fine. To install it, just download the corresponding installer, run it, and follow the steps.
    2. To simplify programming with F#, you can install Visual Studio code editor, alongside with the Ionide-fsharp visual studio code extension.
      • To install Visual Studio Code, just go to the official download page, and download the installer for Windows operating systems. Run it and follow the instructions.
      • To install the Ionide-fsharp extension, just open Visual Studio Code, click on the extensions button, on the side menu, then write on the search bar "Ionide-fsharp"". Hit Enter. After that, the extension will appear in the search results. Click on it, and the corresponding page will open as a tab in the visual studio code editor. Now, click on the button install, available in that page, and wait for the installation to end. That's it. Now you are set up to start programming with F#.

  • on ubuntu :

    According to the official installation page of the F# Software Foundation, you can follow the same steps I described before, but you have to download the packages that are available for Ubuntu, instead of those available of Windows 10.

    • To install .NET SDK on Ubuntu, follow the steps available in this page. To install the latest version, you will have to:
      • add the Microsoft package signing key and the package repository. On the command prompt, run the following commands: wget https://packages.microsoft.com/config/ubuntu/22.10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb

        sudo dpkg -i packages-microsoft-prod.deb
        rm packages-microsoft-prod.deb
      • Install .NET SDK with the following commands sudo apt-get update
        sudo apt-get install -y dotnet-sdk-7.0
        You may encounter an error, indicating that the netstandard-targeting-pack-2.1 package is missing. To solve this issue, you can go to this download page, recuperate the link of the .deb file, download it, then install it. For example: wget http://security.ubuntu.com/ubuntu/pool/universe/d/dotnet6/netstandard-targeting-pack-2.1_6.0.110-0ubuntu1_amd64.deb
        sudo dpkg ‘netstandard-targeting-pack-2.1_6.0.110-0ubuntu1_amd64.deb’
        After that, you can repeat the previous SDK installation commands.
      • You may also need to install the ASP.NET Core Runtime, to run .NET apps that don't provide runtime. To install it, run the following commands: sudo apt-get update && \
        sudo apt-get install -y aspnetcore-runtime-7.0
    • To install Visual Studio Code on Ubuntu, go to the official download page, then click on the .deb Debian, Ubuntu button. Save the .deb installer in the folder you want. To run the installer, just go to that folder, and open the terminal. Then run the following command: sudo dpkg --i "name-of-downloaded-file".deb For example, at the time of writing this post, the name of the file is (without the extension): code_1.74.2-1671533413_amd64, so the command will be: sudo dpkg --i code_1.74.2-1671533413_amd64.deb
    • To install the Ionide-fsharp extension, follow the same steps described above (for the Windows Version)



The Hello World Example

  1. Create a file named hello.fsx. In that file, write the following code:

    printfn "Hello World!"

  2. Now you have two options:
    • If you are using Visual studio code, and the Ionide-fsharp extension, just click on the run button, you will see the message "Hello World!" printed on the terminal window, available at the bottom of the editor.

    • If you are not using visual studio code, just open the terminal, change the location to the folder to where you saved your hello.fsx file, and run the following command:

      dotnet fsi hello.fsx It will compile and run your code.


Something to say ?

If you want to add something about the F# language or about this post, please feel free to do it by commenting below 🙂 .