Tech Brief

Microsoft's F# Functional Language

A functional programming language built for the .NET Framework

Functional programming is a coding style that emphasizes ideas such as composition from simple building blocks, immutability of data structures and the use of functions as data. In recent years, ideas from functional languages have been incorporated into many parts of Microsoft's developer tools, from generics in .NET Framework 2.0 to lambdas in C# 3.0. In addition, technologies such as Language Integrated Query (LINQ) and Parallel Extensions for the .NET Framework have applied functional programming techniques toward key software development challenges.

Last October, Microsoft announced the F# programming language will join the collection of .NET languages delivered by its Developer Division. F# is a functional programming language that also embraces imperative and object-oriented programming (OOP) concepts. Originally designed and developed by Don Syme in Microsoft Research's labs in Cambridge, England, F# draws from other functional languages, notably LISP, Haskell and ML-derivative OCaml.

F# as a Language
As a typed functional programming language for the .NET Framework, F# combines the succinctness, expressivity and compositionality of typed functional programming with the runtime support, libraries, interoperability, tools and object model of .NET. F# stems from the ML family of functional languages and has a core language compatible with that of OCaml, though it also draws from other languages such as C#. F# was designed by Syme from the ground up to be a first-class citizen on .NET, giving it smooth interoperability with other .NET languages. For example, C# and F# can call each other directly. This means that F# has immediate access to all the .NET Framework APIs. Similarly, libraries developed in F# may be used from other .NET languages.

One of F#'s most striking features -- inherited from the ML family of languages -- is its powerful type inference. This allows F# code to contain few type annotations, making it concise like code in dynamic languages such as Python and Ruby, while maintaining the same type-correctness guarantees and performance provided by languages like C# and Java.

Programming in F#
[click image for larger view]
Programming in F#

For more advanced developers, F# includes some powerful functional language constructs such as Active Patterns, Workflows and Quotations.

Interest in F# has come from a few different areas of the software development spectrum. The increasing awareness of functional programming beyond academia has fueled a particular interest in F#. The .NET language provides an easy introduction to functional programming techniques, without losing access to the imperative and OOP features familiar to many developers. Microsoft is also seeing a strong interest in F# from the financial, scientific and technical computing sectors. The language has syntax and primitives that are more natural to these domains, and it offers a focus on experimentation and data-manipulation through an interactive environment.

Many computer science departments teach functional programming languages in their curriculums. F# provides an attractive option for these courses and offers an easy transition to or from other courses that use languages like C#.

A Taste of F#
[click image for larger view]
A Taste of F#

Learning More About F#
Releases of F# from Microsoft Research are available at http://research.microsoft.com/fsharp. These releases include a plug-in for Visual Studio 2005 and VS 2008 that provides syntax highlighting and background error reporting for F# code. Expect to see future releases of F# from the Microsoft Developer Division with improved VS integration and bug fixes.

For more info about F#, visit the F# community forums at http://cs.hubfs.net, and Don Syme's blog at http://blogs.msdn.com/dsyme.

About the Author

Luke Hoban is the program manager for F# at Microsoft.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube