Friday 16 January 2009

Introduction to Microsoft F# - Part 1

I have recently been tasked with putting together some internal training materials on Microsoft’s new F# programming language. F# is a functional programming language, and in this post I aim to give you an overview of its many benefits and hopefully inspire you to add it to your development toolset. In later posts we will start delving into the language and get our hands dirty with some code.

As many of you may know, F# has been knocking around for some time now; originally starting out at Microsoft Research in Cambridge as a pet project of Don Syme. So popular has the language become that it is about to break into the mainstream when it is officially released as part of Visual Studio 2010.

So what is functional programming?

Functional programming is a method of programming that allows computation based upon the evaluation of mathematical functions. Typically a functional language does not contain state or mutable data and the emphasis is very much on the application of functions. Imperative and OO based languages such as C# however allow changes in state and data types within these languages are very often mutable.

Functional programming can trace its roots back to the early 1950 with languages such as LISP, however they have never really gained momentum outside of the academic and scientific domains.

As a .NET developer functional programming is not new to you. Features common place in .NET such as generics, and LINQ all have their roots in functional programming.

What does F# bring to the party?

F# brings typed functional programming to the .NET Framework. It is very succinct and expressive and allows for a new style of application development. As a (soon to be) fully CLR / CLS compliant language an F# application or library has full access to the entire range of .NET Framework APIs and is fully interoperable with other .NET languages such as C# and VB.NET.

Pure functional programming is often the best approach for solving complex computational problems however the traditional languages such as Haskel, Lisp and OCaml suffer with a lack of interoperability. F# is a natural extension of these languages in that it combines the 3 main programming paradigms (imperative, object orientated, and functional). Doing so gives us a general purpose .NET language that can be used in any style that takes your fancy! In fact you can use all three approaches within the same code.

One of the biggest benefits I have found in using F# is that not only is it a strongly typed language, it also offers excellent type inference. This means that as a developer you no longer need to explicitly specify a type. The only exception to this is when the type is ambiguous. I will look at this in more depth over the next few posts.

Why should I use F# ?

F# is the only .NET language to offer a combination of scripted, functional, object orientated and imperative programming. It allows you to solve highly complex computational tasks with relative ease and its fully supported by all other .NET languages. So if your ever faced with a problem that your struggling to solve in C#, give F# a go and see how easy it can be.

Where can I get F# ?

F# is currently a CTP release and is available for Visual Studio 2008. For more information on F# visit http://research.microsoft.com/fsharp

1 comment:

James Millar said...

Unfortunalty not no!