F# Programming Guide

F# (pronounced F sharp) is an open-source, cross-platform, general purpose programming language first created by Microsoft Research Cambridge in 2005.

F# runs on Linux, Mac OS X, Android, iOS, Windows, FreeBSD and GPU platforms.

Common uses for F# include enterprise programming, data sciences, web programming, mobile app and game development, machine learning, cloud programming, financial computing, math and statistics, and data access.

What is F#?

It is a multi-paradigm (functional, imperative, object-oriented, metaprogramming, concurrent) programming language that is normally used as a cross-platform Common Language Infrastructure (CLI) language, and so it most often associated with .NET Framework.

F# is a mature programming language, enabling users to solve complex computing problems with simple, robust, and maintainable code.

The primary role of F# is to reduce the development time for analytical software components in modern enterprise software. F# originated from the ML programming language and it was further influenced by a number of other languages such as C#, Python, and Haskell.

F# is open source, published under the Apache license. The open source community includes the F# Software Foundation and the F# Open Source Group at GitHub, where the F# source code is hosted.

Brief History

F# development work was started by Don Syme from Microsoft Research. The first release of F# 1.x came in May 2005, but this first version was limited to Windows platforms.

Version 2.0 of F# was released in April 2010, bringing support beyond Windows to Linux and OS X. In addition, meta-programming was added to it that allowed compiled F# code to be used in JavaScript and graphics processing unit (GPU) coding.

Version 3.0 cam out in August 2012, followed just over a year later by version 3.1. The current stable release of F# is version 4.0, released in July 2015.

In spite of being open-source, primary development of the F# language, the open-source compiler and the open-source core tools is still handled by Microsoft, and is focused on the Windows platform.

Features

F# is a strongly typed, multi-paradigm language. But besides specialist areas of use, like scientific or data analysis, it is also a great choice for enterprise development because of its powerful features.

Functions in F# are elevated to first-class status, meaning that you can name functions, store functions in a data structure, pass functions as an argument and return a function as the value of a function call.

F# removes the clutter of curly brackets or semicolons, so code is easier to read and write.

Type inference is another powerful feature — in F#, the programmer does not declare types — the compiler deduces types during compilation.

Most problems can be solved in F# using fewer lines of code than in C#, and many programming tasks are much simpler in F#, including list processing, state machines, comparison and equality, creating and using complex type definitions, etc.

Use of asynchronous programming and parallelism in CPU intensive work is also very easy in F#.

F# uses the .NET Framework (or Mono on Linux and mobiles), which gives it access to all of the available .NET libraries and tools. F# is also well integrated with several Integrated Development Environments (IDE’s), providing the developer with debuggers, plug-ins, and other useful tools.

Getting Started with F#

If you have previous experience with Windows development, Visual Studio IDE, and the .NET Framework, getting started with F# programming should not be problematic, as F# uses the same, familiar development environment.

Your Development Environment

Before you can start coding in F#, you'll need to get your development environment set up. Currently supported host development operating systems are OS X, Linux, Windows and FreeBSD, and you can create applications for Android, iOS and GPUs.

F# is well integrated into Xamarin (for Windows and OS X operating systems) and Visual Studio (Windows only) IDE’s.

Visual Studio 2015 Community Edition is free for individual developers, open-source projects, academic research, education, and small professional teams, so you can try it out at no cost.

Installing and using F# on Linux systems can be accomplished in a few different ways, detailed instructions are available at Fsharp.org.

Resources

We browsed the web in search for the best F# tutorials, e-books, and interactive courses. Our recommendation is that you make use of several of these resources and work your way through the resources that best fit your learning style.

Free Interactive Courses

Just reading about a programming language will not be enough to learn it. To really find out what the F# language can do, you have to see it in action. Free interactive courses provide a good starting point to learning the basic syntax of a programming language:

  • Try F# is an interactive environment where you can explore F# in your web browser (on Mac and Windows) with an online compiler. It contains a number of online step-by-step tutorials demonstrating the power of F#. And it is free.

  • Programming in F# is Microsoft’s official free online course for F#. E-mail registration is required, and the course is archived, but it can still be viewed.

Additional Resources

Working through tutorials and official programming language reference with sample code can help you a lot in getting to grips with F# programming. These are some of the most comprehensive and detailed resources on F#:

E-Books

We decided to single out two e-books about F# programming. These e-books will come in handy as reference while programming in F#:

  • F# Programming on WikiBooks also has lots of interesting resources and examples for F# programming.

  • Expert F# 4.0 by Syme, Granicz and Cisternino is a comprehensive guide to F# 4.0, with a case book of F# applications, concepts, syntax and features.

Summary

If you successfully make it through some of the resources and tutorials listed above, you will surely master the basics of F# programming, and probably much more.