New F# programming language in .NET framework 4.0

Image Microsoft will introduce a new language that can fully use all the features of the .NET framework. This language is called F#.

Unlike the C# programming language, which is an imperative programming language, F# is a functional programming language, based on .NET framework such as C#. F# and C# can call each other directly. As a result, F# has fully access to all the .NET Framework APIs, including LINQ and WPF.. Likewise, libraries developed in F# can be used from other .NET languages.

F# is a strongly typed language that uses type inference, so it has the ability to deduce automatically the type of a value. This means that data types need not be explicitly declared by the programmer; they will be deduced during compilation by the compiler . However, F# also allows explicit data type declaration.

The new language supports all .NET framework types and objects, and extends them, categorizing them as immutable types (they are the default ones and are used for functional programming) or mutable (used in imperative programming). For functional programming, it provides several constructs and a set of immutable types: tuples, lists, records and unions. For imperative programming, F# supports for and while loops, arrays, and the creation of object types (.NET classes).

To see the difference between a functional programming language such as F#, and a imperative programming language such as C#, take a look to the following example, where we will create an array containing the first ten even numbers.

1
2
3
int[] even = new int[10];
for (int i = 0; i < even.Length; i++)
even[i] = i * 2;

F# gives to the programmer several functional modules for handling one-dimensional arrays, two-dimensional, three-dimensional, etc. … (Array, Array2, Array3, etc. ..). We used in our case the Array module, so we can translate the above C# code in F# code as follows:

1
let even = Array.init 10 (fun i -> i * 2)

The keyword “let” is used in F# for binding type values to a variable name. As you can see from the above example, the data type of array was not declared, becouse is the compiler that according to the initialization function will be understood that is an array of integer. Using this syntax we specify the creation of an array of 10 elements, and the initialization function to use for each element.

In my opinion, F# is a very interesting programming language, since you only need to specify what you want to get and not the individual steps on how to obtain it. Anyway we will see in the coming years how this language will be adopted by .NET programmers.

2 thoughts on “New F# programming language in .NET framework 4.0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s