There has been considerable chatter about F# for some time. The programming language began its life at Microsoft Research and recently progressed to the mainstream with the release of the September 2008 Community Technology Preview.
I’ve read a lot of good things about F# (which is a close cousin to the Objective Caml language), and since I need to keep up with the .NET world, it was time for me to take a quick tour of the language.
The September CTP is available as a free download. It runs on Windows XP and Windows Vista and requires .NET Framework 2.0. Installation is as simple as downloading and running the install file. It provides Visual Studio 2008 integration, but it is not required. You may utilize the command-line tools to play with your F# code.
The Visual Studio 2008 install provides an interactive session that allows you to enter and run F# code on the fly without compilation. This interactive session window is at the bottom of the IDE interface (when working with F#). You can type in F# code and hit [Alt][Enter] to run it on the fly. It is a great way to get your feet wet with the language.
Microsoft describes F# as a functional, object-oriented, imperative, and explorative programming language for .NET. While the description says object-oriented, the more important term is functional. That is, you don’t have to write object-oriented code with F#; you can think in more procedural terms to solve a problem.
F# boasts the following features:
- Strongly typed: Each data type is predefined, and all constants and variables use one of these types.
- Succinct: You can accomplish a lot in a small amount of code. You are not burdened with a lot of the overhead of C#/VB.NET with creating classes and such.
- Libraries: F# is .NET, so the Framework is there for you.
- Scalable: Once again, it is .NET under the hood, so it has a scalable architecture.
- Efficient: Microsoft proclaims it is an efficient language, but I will wait and see.
You can get F# to do what you want, but it seems to be more relevant for number crunching activities like financial/data analysis, modeling, and academic work — at least, this is what Microsoft is saying. (I can’t help but think of playing with Fortran in my college days when I read such things. Of course, there is a project for a .NET version of Fortran.)
One of the first things I noticed is the use of the let keyword to assign variables — this took me back to my days programming with BASIC. The following F# statements assign values:
let firstname = "Tony"
let a = 12let b = 1.5
The data assigned to the variables sets their type. Once these values have been assigned, they may not be changed — they are immutable. So, the following lines are invalid:
let a = 12 a <- 13
The last line attempts to store the new value in the variable called a, but this is not allowed since it has already been set up with another value. Now you can use the mutable keyword to change this behavior, as this snippet demonstrates:
let mutable a = 12
let fname = "Tony"
a <- 13printfn "My first name is '%s'" fname;;
The previous sample demonstrates output via the printfn function. Also, you may notice there are no end-of-line delimiters. You can also define types, modules, enums, and so forth. F# offers great support for pattern matching, which lends itself to data analysis.
I love the abundant amount of free resources available on the Web about Microsoft development (as well as other languages). F# is no different, as the following brief list demonstrates:
- Microsoft F# Developer Center
- F# on CodePlex
- How do I… Get started using the F# programming language
- F#, Indian math education, and good programming
F# has potential, but I wonder how long it will take to enter the mainstream (if ever)? After all, I can’t force the language on a client unless there is a situation where F# is more useful. With that said, I’ll play the waiting game with F# and its future.
Do you plan on taking F# for a test drive? Do you think another .NET language is actually necessary? Share your thoughts with the Web Developer community.
Tony Patton began his professional career as an application developer earning Java, VB, Lotus, and XML certifications to bolster his knowledge.
Get weekly development tips in your inbox
Keep your developer skills sharp by signing up for TechRepublic’s free Web Developer newsletter, delivered each Tuesday. Automatically subscribe today!