F# in the Enterprise
Accelerated Analytical and Parallel .NET Development with F# 2.0
Version 1.0 – February 2011
Microsoft F# 2.0 is a flexible and efficient language for developing analytical, data-rich, computational and parallel software components. Backed by a professional toolset in Visual Studio 2010 and incorporating the full power of the .NET platform, the language is a perfect companion to existing professional development techniques for enterprise computing.
F# 2.0 combines functional and object-oriented programming to enable the rapid creation of simple code to solve complex problems. It 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.
This paper outlines the benefits of F# for enterprise scenarios, describes case studies and other real-world experiences with F#, and includes information on finding and developing F# programming skills for your organization.
Analytical software components form the core of many modern data-rich and computation-intensive enterprise applications, from financial risk models and energy analysis applications to business intelligence tools. By quickly developing and verifying such components, a company can deploy new computational assets to enterprise and web applications and reduce time-to-market for end products.
Microsoft F# 2.0 is an efficient and flexible language for developing analytical, data-rich computational and parallel software components. Backed by a professional toolset in Visual Studio 2010 and incorporating the full power of the .NET platform, the language is a perfect companion to existing professional development techniques for enterprise computing.
F# 2.0 components can be deployed alongside existing enterprise software assets in the same way as any other .NET code:
F# 2.0 provides a uniquely compelling combination of concise, readable code, strong static checking, integration with COM and .NET libraries, and a rich and familiar integrated development and debugging environment. F# Interactive can be used to enable domain specialists to rapidly prototype .NET components.
This paper outlines the benefits of F# for enterprise scenarios, describes case studies and other real-world experiences with F#, and includes information on adopting F# in your organization.
F# 2.0 provides important advantages for analytical component development in enterprise computing:
Lower Development and Maintenance Costs
The F# 2.0 language brings the benefits of strong typing to analytical and computational component development. The language is designed to enable rapid prototyping, reduce error rates, and increase component reliability—all of which lead to lower development and maintenance costs. Financial services and insurance firms have used F# to speed development by 50 percent or more.
Rapid prototyping. F# 2.0 includes F# Interactive, a unique tool among Visual Studio 2010 languages, which enables interactive problem exploration with smooth transitions to professional components. F# Interactive and the F# tools in the Visual Studio integrated development environment (IDE) support the read, evaluate, print, loop (REPL) experience, so that developers can rapidly build prototype functions and algorithms and verify models. These same tools enable F# to be used as a scripting language.
Fewer errors. User reports and case studies have shown that the strong typing of F# results in components with low bug rates. The combination of the F# REPL experience and the professional project system in Visual Studio helps developers transition prototypes into maintainable, high quality code. The innovative introduction of types for Units of Measure adds important semantic information to syntactically similar types, such as prices, probabilities, or derivatives. Developers can declare data not just as integers or floating-point numbers but as meters, Euros, moles, or any other such unit. Because F# enforces strong typing, the compiler catches any confusion in units, thus eliminating a common source of programming error that often is discovered only after the deployment of an application.
Greater reliability. The functional programming paradigm means that complex time and state dependencies are often eliminated from F# components. This approach helps to prevent bugs and makes unit testing simpler and more straightforward. It also promotes code reuse and compositionality.
Interoperability and Openness
F# is a fully-supported .NET programming language that works with your existing .NET applications and COM components.
Professional tools. The F# language is fully integrated with Visual Studio, so F# developers can take advantage of industry-leading professional editing, build, project management, performance, and debugging tools.
Integrated component development. F# 2.0 code integrates seamlessly with C# and Visual Basic components in Visual Studio 2010, enabling flexibility and agility in the application of techniques within a project. F# 2.0 produces standard .NET components that can be directly integrated into existing enterprise applications and workflows.
Interoperation. Because F# is a .NET language, the extensive capabilities of the .NET Framework (versions 2.0 and later) are available for use by F# code, thus enabling interoperation with a wide variety of components.
Open language. F# code can be developed with a range of professional and open-source tools and can run on a range of platforms, including .NET Compact Framework on Xbox 360, Silverlight, and Windows 7 Phone, and Mono on Mac, Linux, and other platforms.
F# 2.0 is well suited for performing heavy numeric computations across large data sets. It has been successfully used in financial, statistical, parallel, scientific, engineering, testing, and event-processing software components.
Native code execution speed. As a .NET language, F# features modern, high-performance just-in-time (JIT) compilation to native code. F# code runs unchanged on both 32-bit and 64-bit systems by using the instructions available on the target architecture. F# uses advanced .NET features such as structs to achieve best performance in critical coding regions. The resulting code runs at the same speed as Microsoft C#—in some cases faster. The performance of numerical computations typically exceeds that of other functional languages, and F# code can use the highly-optimized .NET library implementations for I/O and data.
Parallel and asynchronous programming. The F# language design supports functional, parallel, and asynchronous programming for multi-core and parallel-distributed programming. Both the F# core library and the language syntax itself include features that support asynchronous workflows. Such features enable the user interface to remain responsive while computation occurs asynchronously.
Scalability. Modern applications and services must scale not only across multiple cores but also to the cloud. By using the .NET 4.0 Task Parallel library and other F# parallel primitives, F# parallel computations can scale with the capabilities of the hardware platform, according to the number of cores available. F# asynchronous programming enables the construction of high-performance, scalable server-side systems that can serve many thousands of simultaneous requests. For massive scalability, F# code can be deployed to the cloud by using Windows Azure Worker Roles and other cloud-execution environments.
F# is currently used in numerous business areas:
The following sections provide links to case studies and user experiences in several application areas.
Risk Analysis and Valuation
A large financial services firm in Europe sought new development tools that could cut costs, boost productivity, and improve the quality of its mathematical models. To address its needs, the bank deployed Microsoft F#, the Microsoft .NET Framework, and Microsoft Visual Studio. It will soon upgrade to Visual Studio 2010 and the integrated Microsoft Visual F#. With its new tools, the bank can speed development by 50 percent or more, improve quality, and reduce costs.
To read the complete case study, see:
Banking Firm Uses Functional Language to Speed Development by 50 Percent
Insurance Rating Engine
For nearly 75 years, Grange Insurance has offered competitive products and services to policyholders in more than a dozen U.S. states. To maintain its well-earned reputation and standing, the company decided to enhance its rating engine—a software tool for rating policies and performing what-if modeling, impact analyses, and other vital activities. Working with the Sophic Group and using the Microsoft® Visual Studio® Team System development environment and Microsoft Visual F# programming language, Grange Insurance parallelized its rating engine to take better advantage of multicore server hardware, and in so doing garnered significant performance benefits. Processes that used to require hours now take just minutes, enabling the company to trim time-to-market by weeks and making it far easier for independent agents to sell and service Grange products.
To read the complete case study, see:
Insurance Company Improves Time-to-Market with Enhanced Rating Engine
Energy Trading and Energy Portfolio Optimization
F# was used for the calculation engine in an application that balances the national power generation schedule for a portfolio of power stations to a trading position for an energy company. Client and server components were written in C#. Interoperation of the F# engine with C# client and server components was seamless. Furthermore, the units of measure data type saved much time in testing and eliminated an entire class of errors common to such applications.
For details, see:
F# for Energy Trading and Energy Portfolio Optimization
Statistical Analysis and Online Services
The Applied Games Group at Microsoft Research Cambridge developed a ranking system that is used by the XBox Live team to compare players and generate TrueSkill rankings for Halo 3. This involves the analysis of multiple terabytes of log data spread over thousands of text files. The ranking calculations are performed in F# with SQL Server as a data store.
For more information, see:
F# Business Intelligence Case Study - XBox Live Trueskill
Tabbles is a new way of organizing files: it combines virtual folders and tags, and auto-organizes and tags your files in intelligent ways. Nearly all of Tabbles is written in F#, except for a few machine-generated user interface classes. In Tabbles, F# interacts with the Windows Presentation Foundation (WPF).
F# adoption in the enterprise typically begins by using F# for a core computational component, often with a C# or Visual Basic application or web front-end. Initial tasks that are well-suited to the language include algorithm development, scripting, data analysis, parallel batch processing, and rapid prototyping.
Successful introduction of F# in an organization requires the development of F# knowledge and skills among existing talented software staff. Because F# can greatly improve the productivity of domain specialists, software developers often relish the chance to use F# for their work. F# combines a functional core with the imperative and object-oriented programming techniques that most programmers already know. F# skills tend to improve and augment programming skills learned in other areas. Organizations have built teams of 100 or more F# programmers through training newcomers and developing the skills of existing programmers.
The functional core of F# has much in common with other functional and object-oriented languages. C# programmers can easily make the transition to F# coding because F# and C# use the same .NET libraries and the Visual Studio IDE. Applied mathematicians, statisticians, and data analysts generally appreciate the opportunity to work in a high-performance, strongly-typed functional language.
Functional programming is taught in many universities world-wide, and skills in Python, OCaml, and C# are immediately relevant to F# programming. Programmers who are familiar with those languages will find F# quite similar. However, functional programming experience is not a prerequisite for being an effective F# programmer, and both object-oriented programmers and domain specialists can rapidly become productive with the language.
Numerous resources are available for F# training, including sample code, online and live courses, books, and tutorials. You can find links in “Resources” at the end of this paper.
This section contains links to additional F# resources, including technical documentation, development tools, and learning materials.
Microsoft F# Developer Center
The central source for information about F# in MSDN
F# Tools and Samples
Sample code and tools that demonstrate F#, including several projects that compare solutions implemented in F# with those in other languages.
Visual Studio 2010 Gallery
Quick access to
tools, controls, and templates to help you get the most out of Visual Studio.
F# Projects on CodePlex
community and open source projects relating to F#, Visual Studio, and .NET
Math and Statistics Libraries
Many professional and open source components are available for use with F#, including the following:
In addition, thousands of other .NET, C, and C++ components can be used directly from F#.
The F# PowerPack, with F# Compiler Source Drops
A collection of libraries and tools for use with F#, including:
A collection of links to introductory books, articles, and videos
The F# Wiki Book
Expert F# 2.0
D. Syme, A. Granicz, and A. Cisternino. APress, 2007.
Foundations of F#,
R. Pickering. APress: 2007
Professional F# 2.0
T. Newman, A. Erickson, T. Crowell, and R. Minerich. Wiley: 2010
Programming F#: A comprehensive guide for writing simple code to solve complex problems
C. Smith. O’Reilly: 2009.
Real World Functional Programming: With Examples in F# and C#
T. Petricek and J. Skeet. Manning: 2009
Visual F# 2010 for Technical Computing
J. D. Harrop
Several consultancies offer F# training, including DevelopMentor, SkillsMatter, EcoLogic, and Intellifactory at the time of this document.