RDN Directions

F# Is for Functional

Microsoft Research develops F# to become a full-fledged member of the Visual Studio family.

Writing about a company like Microsoft carries an occupational hazard-the instant you finish writing about a topic, Microsoft can make an announcement that either confirms your conclusions or tears them to shreds.

Luckily for me, shortly after I wrote a column describing the explosion of new languages targeting the .NET Framework, Microsoft made me look prescient by announcing that F# -- a programming language developed by Microsoft Research -- will become a full-fledged member of the Visual Studio family. (At this juncture, my wife would point out that even a stopped clock is right twice a day.)

F# is particularly interesting because it's a hybrid of functional programming languages often used in academic environments and the traditional imperative programming languages used in commercial and corporate development.


A Different World
Interest in functional languages has grown dramatically in the past few years, driven by the need to build applications that can divide their workload across multiple processors, either in the form of a desktop app that runs well on a multi-core system or a server app that runs across an entire farm of systems.

Although no precise definition for functional programming exists, according to the newsgroup comp.lang.functional, functional programming "is a style of programming that emphasizes the evaluation of expressions, rather than execution of commands."

With imperative (or procedural) languages such as C++ and C#, developers specify a program as a series of statements that alter the global state of the program as it runs. This arrangement makes it very difficult to run different portions of the program in parallel, because while one portion of the program is reading a piece of state information, another portion might be modifying the same information.

Functional programming languages, like F#, seek to reduce the problem by restructuring the way developers create programs. Programs are composed of functions that take a set of inputs and return a set of outputs, and reduce or eliminate the ability of a function to have "side effects" -- that is, to modify the global state of the program. By doing this, functional languages make it much easier to distribute a program's workload across multiple processing units. In fact, these exact same techniques are at the heart of Google's massively parallel search engine.

Scientific and engineering problems are a good example of disciplines that are well-suited to the unique strength of functional programming in general, and F# in particular.

Why Now?
If functional programming languages are really all that, why haven't they taken over the world already? Nearly a decade ago, in August 1998 to be precise, Bell Labs researcher Philip Wadler laid out some reasons in a paper published in SIGPLAN, the special interest group on programming languages of the Association for Computing Machinery (ACM). His list includes the lack of portability, quality code libraries, tools and developers trained in the functional model.

By producing a version of F# for the .NET Framework and building support for it in Visual Studio, Microsoft is tackling many of these issues head-on. Building on the .NET Framework provides access to a large and growing set of code libraries that span a large range of domains, from user interface to database access and just about everything in between. It also provides a degree of portability-Microsoft provides a version of the .NET Framework for Windows and, sometime next year, will add support for the Mac OS via Silverlight. Meanwhile, the open source Mono project continues to develop a Linux implementation.

By including F# in the box, Microsoft will raise the visibility of the language and make it something that millions of developers, who would never consider writing their next application in Scheme or CAML, will at least consider.

But the biggest hurdle remains: helping developers make the mental shift from traditional, imperative languages to the world of functional programming. Newly minted computer science (CS) graduates are likely to have seen other functional languages during their college years (a functional language, Scheme, is used as the first programming language in the computer science departments of a number of universities, including UC Berkeley). But just as the introduction of object-oriented programming in the 1980s caused a generation of programmers skilled in the art of COBOL to go back and refresh their skills, so too will a generation of programmers adept in the art of C++ and Java need to hit the books if they want to stay on the leading edge.

Functional programming and F# aren't going to replace imperative programming altogether. In fact, with features like LINQ and lambda expressions, the latest version of C# includes little nuggets of functional programming in an otherwise imperative world. But by adding F# to Visual Studio, Microsoft is making a statement: functional programming is an important tool and will only become more important over the next few years.

About the Author

Greg DeMichillie analyzes and writes about Microsoft's development platform and tools for Directions on Microsoft, a research firm dedicated to tracking Microsoft. He was previously the group program manager at Microsoft responsible for the overall design and feature set for Visual C# and C++. A founding member of the C# language team, DeMichillie was a key contributor to the initial design and development of .NET.

Reader Comments:

Add Your Comment:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above