Click here to Skip to main content
15,896,201 members
Articles / Programming Languages / XML

TIOBE Index: F# enters the top 20 for the first time

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
13 Aug 2011CC (ASA 3U)4 min read 12.7K  
TIOBE Index

I have never been so curious about Microsoft technologies (especially the .NET platform) until I read the TIOBE programming community index for August 2011. A new functional programming language has hit the top 20 and it appears to be Microsoft language F#. With curiosity of this multi-paradigm language, I walked through some F# basics with the text written by Tomas Petricek.

Petricek’s text writes,

In one of the papers about F#, the F# designers gave the following description:

F# is a multi-paradigm .NET language explicitly designed to be an ML suited to the .NET environment. It is rooted in the Core ML design and in particular has a core language largely compatible with OCaml.

In other words, this means that the syntax of the F# language is similar to ML or OCaml, but the F# language targets .NET Framework, which means that it can natively work with other .NET components and also that it contains several language extensions to allow smooth integration with the .NET object system.

In my view, the recent rise in popularity of F# comes from its multiple paradigms and its seamless integration with .NET components. I will skip the latter one since it is mainly because of the popularity of .NET technologies and Visual Studio 2010.

F# supports three paradigms: functional programming (influenced by ML and OCaml), object-oriented programming, and language-oriented programming.

This article from MSDN states that the combination of functional and object-oriented programming enables the rapid creation of simple code to solve complex problems. It also states that F# is well suited for performing heavy numeric computations across large data sets and has been successfully applied in financial, statistical, parallel, scientific, engineering, testing, event-processing, tool-development, and general-purpose software components.

In my view, functional programming makes F# a flexible and efficient language for developing analytical, data-rich, computational and parallel software components.

F# is a typed functional language, by which it means that types of values are determined at compile-time. F# also makes use of type inference to deduce the type from the code so the types are explicitly specified in the code very rarely.

Asynchronous workflow is a remarkable feature in F#, which supports performing computations asynchronously, that is, without blocking execution of other work. For example, asynchronous computations can be used to write applications that UIs remain responsive to users as the application performs other work. There are a variety of ways of programming asynchronously, and the Async class provides methods that support several scenarios. The following code snippet is copied from Wikipedia.

C#
// Async workflows sample (parallel CPU and I/O tasks)

// A very naive prime number detector
let isPrime (n:int) =
    let bound = int (System.Math.Sqrt(float n))
    seq {2 .. bound}
        |> Seq.exists (fun x -> n % x = 0)
        |> not

// We are using async workflows
let primeAsync n =
    async { return (n, isPrime n) }

// Return primes between m and n using multiple threads
let primes m n =
    seq {m .. n}
        |> Seq.map primeAsync
        |> Async.Parallel
        |> Async.RunSynchronously
        |> Array.filter snd
        |> Array.map fst

// Run a test
primes 1000000 1002000
    |> Array.iter (printfn "%d")

In this example, some language constructs have to be explained first.

Anonymous functions defined using fun use a different separator –> other than the separator = used with let.

|> is the pipelining operator. For example, if we want to filter out all the odd numbers in a list, we can use the following code.

C#
let nums = [1; 2; 3; 4; 5]
// val nums : list<int>

let odds_in_nums = nums |> List.filter (fun n -> n % 2 <> 0)
// val odds_in_nums : list<int> = [1; 3; 5]

Asynchronous workflows follow the syntax async { expression }. Async.Parallel creates an asynchronous computation that executes all the given asynchronous computations, initially queueing each as work items and using a fork/join pattern. Async.RunSynchronously runs the asynchronous computation and awaits its result.

The function fst takes a tuple (containing two elements) and returns the first element in the tuple. The function snd returns the second one.

So I think the functional paradigm is very well suited for data-rich applications, and the object-oriented paradigm is possibly just a work-around for people who are not familiar with functional programming or for integrating with existing .NET components.

F# also supports language-oriented programming in which, rather than solving problems in general-purpose programming languages, the programmer creates one or more domain-specific languages for the problem first, and solves the problem in those languages. The concept of language-oriented programming takes the approach to capture requirements in the user’s terms, and then to try to create an implementation language as isomorphic as possible to the user’s descriptions, so that the mapping between requirements and implementation is as direct as possible.

In conclusion, F# is very promising but is still expensive for small projects. Its integration with the .NET platform will possibly bring up the language to a new level in the near future. Language-oriented features will possibly be the future direction of the development of F#.

P.S. For non-Windows readers, this project in CodePlex will help a lot.

License

This article, along with any associated source code and files, is licensed under The Creative Commons Attribution-Share Alike 3.0 Unported License


Written By
Student Shanghai Jiao Tong University
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --