Biz & IT —

Microsoft to push functional programming into the mainstream with F#

Microsoft's recent decision to productize the F# functional programming …

Microsoft has announced that support for the F# functional programming language will be fully integrated into Visual Studio. This marks a bold new commitment to facilitating functional programming on the .NET platform and could potentially help legitimize functional programming in enterprise environments. Microsoft's promotion of F# to a fully-supported language in Visual Studio is also indicative of the extreme versatility of the .NET platform and Microsoft's Common Language Runtime.

F# began its life as a Microsoft Research project to demonstrate the efficacy of .NET as a platform for mixing multiple distinct programming paradigms. F# is heavily inspired by the OCaml programming language, and a subset of F# and OCaml are largely compatible. F# offers developers many valuable and compelling features without sacrificing much runtime efficiency. F# supports type inference, pattern matching, high-order functions, and currying. F# also supports interactive execution, which means that F# programs can be run like scripts or inputted in an interactive top-level environment similar to the Python shell or Ruby's IRB. F# also has full access to the .NET APIs and components written in other .NET languages.

The advantages of functional programming

Unlike imperative or procedural programming languages, in which computation is typically performed by altering program state, functional programming languages operate on the principles of mathematical evaluation and reduction. Such programming languages are deeply rooted in formal mathematical logic and computational theory. Functional programming languages are largely based on the system of lambda calculus devised by Alonzo Church, in which numerical values, sequences, data structures, basic mathematical computations, and even recursion can be expressed entirely with nested functions.

The close association with lambda calculus and category theory makes functional languages a powerful tool for understanding and programmatically modeling concepts like catamorphisms and recursion. For some programmers, learning to see the ineffable theoretical perfection of functional programming languages is a profoundly illuminating experience that opens the mind to a completely new way of perceiving and understanding computer programming. In some cases, certain functional programming languages are also valued because functional purity is highly conducive to referential transparency and minimizes the potential for side effects.

Outside of the academic world, functional programming idioms are valued because they are often far more expressive than imperative or procedural equivalents. Modern dynamic scripting languages like Python and Ruby, for instance, offer first-class functions in order to boost developer productivity. Even C# offers some features—like LINQ—that are heavily based on functional programming concepts. The ability to mix F# and C# in .NET applications makes it far easier for software developers to use the programming paradigms that are best suited for each individual task.

Functional programming on .NET

Microsoft's decision to productize F# represents a particularly significant step forward for the .NET platform. Microsoft took an equally significant step when it unveiled the Dynamic Language Runtime earlier this year. The .NET platform now fully, officially, and equally supports functional, dynamic, and conventional imperative programming paradigms in an interoperable manner all with a single runtime. This is a tremendous accomplishment and strong evidence of the .NET platform's success and long-term viability.

"[W]e aim to continue the flow of good ideas from functional programming world into mainstream development," wrote Microsoft developer division vice president S. Somasegar in a blog entry. "Furthermore, the somewhat mathematical slant of functional programming just seems naturally appealing to professionals whose primary domain is described with mathematical notation—domains such as financial, scientific and technical computing. On top of the syntactic appeal, the strong type system yields the sort of guarantees which are often crucial in these domains, and enables a superb tooling experience through Visual Studio."

Although this is the first time that Microsoft has treated functional programming on .NET as a product instead of an experiment, many independent developers have long used functional programming languages on top of .NET. The open-source Nemerle programming language, for instance, supports extremely impressive features like macros and is preferred over F# by some programmers in the Ars community. There are also several Standard ML and Lisp implementations for .NET.

As the C# programming language and .NET continue to evolve, developers can undoubtedly look forward to seeing more dynamic and functional programming concepts move out of scripting and academia to augment and complement more conventional programming techniques. Microsoft's efforts to push dynamic and functional programming into the mainstream are one of many signs that the art of software development is enjoying a profound renaissance.

Channel Ars Technica