F# 4.0 New Language Capabilities

Constructors as first-class functions

As a functional-first language, F# has always provided rich support for processing and manipulating function values, both curried-style functions and traditional .NET methods.  One longstanding gap in that support was for constructors – there was no way to treat a type constructor as an isolated function that could be passed around and composed with other functions.  This limitation was one of the few sources of boilerplate in F# code, mandating the use of small lambda functions in order to invoke constructors.

This is now resolved – constructors are now treated as first-class functions, with the same treatment as other traditional .NET methods.

So, as an example, instead of writing this:


You can now write this:


Simplified use of mutable values

Mutable values are permitted in F#, though immutability is the default.  In the past, the ‘mutable’ keyword was used to designate a stack-based mutable value, and that value could be mutated using the <- operator.  If the mutable value happened to be captured by a closure and a heap-based value was required, the ‘ref’ syntax was needed instead, and mutation was done via the := operator.

These distinct syntaxes led to some code inelegance and developer confusion, as it was often difficult to reason ahead of time about which approach was going to be required.

With F# 4.0, developers can now just use the ‘mutable’ keyword for all mutable values, and the compiler will take care of the rest, creating a stack-based value if possible, otherwise implicitly converting to a ref cell.

So whereas you previously needed a ‘ref’ value for ‘total’ here:


You can now use ‘mutable’ and it “just works”:


Advanced users who prefer to have explicit knowledge of the stack/heap semantics can enable warning 3180 (--warnon:3180 for fsc.exe or fsi.exe) and will be notified when a ‘mutable’ declaration has been implicitly converted to ‘ref’.

Support for high-dimensional arrays

The .NET framework supports up to 32-dimensional arrays, but in the past F# only supported use of up to rank-4 arrays.  Not only were arrays of rank 5+ not possible to create and manipulate from F# code, the compiler could sometimes fail to consume external libraries which relied on high-dimensional arrays.

This is now fixed.  Although there is not yet support for creating and manipulating high-rank arrays, the compiler will now properly handle these types up to rank-32.

Support for static parameters to provided methods

F# type providers were previously limited to accepting static parameters only on the top-level provided type. From there, all other provided types, methods, and properties needed to be generated based on this single set of parameters.

With F# 4.0, the type provider mechanism has been expanded to allow for static parameters on provided methods, as well.

With this change, instead of requiring users to declare multiple top-level types, each with distinct parameters, there is now an option to use a single type declaration along with parameterized usage of methods.  For certain kinds of type providers, this can greatly streamline the developer experience.

A simple example is a provided “safe string” type which enforces that the number of slots in a String.Format format string matches the number of arguments passed.  This can now be done with a single type declaration, and a parameterized Format method:


Slicing syntax support for F# lists

F# linked lists now support the familiar “slicing” syntax, long present for arrays, for reading elements and creating sub-lists.


Simplified usage of units of measure with printf-family functions

printf-family functions previously required developers to explicitly strip off any measure information before values could be formatted.

This requirement has been relaxed – values with measure information are now handled seamlessly.


Modified GC settings on the compiler for better performance

Not a language feature, but surely of interest to F# language developers, is a change to the GC mode used by the F# compiler.  fsc.exe now uses GCLatencyMode.Batch, which gives a noticeable improvement in overall throughput, something that any F# developer will welcome.

Our testing indicates that this setting alone can provide upwards of 10% better compile performance. Click the chart below for a full-size plot of the performance data.

fsc.exe performance data, click for full size

What is F#

F# (pronounced eff sharp) is a strongly typedmulti-paradigm programming language that encompasses functionalimperative, and object-orientedprogramming techniques. F# is most often used as a cross-platform CLI language, but can also be used to generate JavaScript[4] and GPU[5] code.

F# is developed by the F# Software Foundation,[6] Microsoft and open contributors. An open source, cross-platform compiler for F# is available from the F# Software Foundation.[7] F# is also a fully supported language in Visual Studio[8] and Xamarin Studio.[9] Other tools supporting F# development include Mono,MonoDevelopSharpDevelop and WebSharper.[10]

Functional programming[edit]

F# is a strongly typed functional-first language that uses type inference. The programmer does not need to declare types—the compiler deduces types during compilation. F# also allows explicit type annotations, and requires them in some situations.

F# is an expression-based language using eager evaluation. Every statement in F#, including if expressions, try expressions and loops, is a composable expression with a static type.[19] Functions and expressions that do not return any value have a return type of unit. F# uses the let keyword for binding values to a name.[19] For example:

let x = 3 + 4

binds the value 7 to the name x.

New types are defined using the type keyword. For functional programming, F# provides tuplerecorddiscriminated unionlist and option types.[19] A tuple represents a collection of n values, where n≥ 0. The value n is called the arity of the tuple. A 3-tuple would be represented as (A, B, C), where A, B and C are values of possibly different types. A tuple can be used to store values only when the number of values is known at design-time and stays constant throughout execution.

record is a type where the data members are named, as in { Name:string; Age:int }. Records can be created as { Name="AB"; Age=42 }. The with keyword is used to create a copy of a record, as in { r with Name="CD" }, which creates a new record by copying r and changing the value of the Name field (assuming the record created in the last example was named r).

discriminated union type is a type-safe version of C unions. For example,

 type A = 
    | UnionCaseX of string
    | UnionCaseY of int

Values of the union type can correspond to either union case. The types of the values carried by each union case is included in the definition of each case.

The list type is an immutable linked list represented either using a head::tail notation (:: is the cons operator) or a shorthand as [item1; item2; item3]. An empty list is written []. The optiontype is a discriminated union type with choices Some(x) or None. F# types may be generic, implemented as generic .NET types.

F# supports lambda functions and closures.[19] All functions in F# are first class values and are immutable.[19] Functions can be curried. Being first-class values, functions can be passed as arguments to other functions. Like other functional programming languages, F# allows function composition using the >> and << operators.

F# provides sequence expressions[20] that define a sequence seq { ... }, list [ ... ] or array [| ... |] through code that generates values. For example,

 seq { for b in 0 .. 25 do
           if b < 15 then
               yield b*b }

forms a sequence of squares of numbers from 0 to 14 by filtering out numbers from the range of numbers from 0 to 25. Sequences are generators – values are generated on-demand (i.e. are lazily evaluated) – while lists and arrays are evaluated eagerly.

F# uses pattern matching to bind values to names. Pattern matching is also used when accessing discriminated unions - the union is value matched against pattern rules and a rule is selected when a match succeeds. F# also supports Active Patterns as a form of extensible pattern matching.[21] It is used, for example, when multiple ways of matching on a type exist.[19]

F# supports a general syntax for defining compositional computations called computation expressions. Sequence expressions, asynchronous computations and queries are particular kinds of computation expressions. Computation expressions are an implementation of the monad pattern.[20]

Imperative programming[edit]

F# support for imperative programming includes

  • for loops
  • while loops
  • arrays, created with the [| ... |] syntax
  • hash table, created with the dict [ ... ] syntax or System.Collections.Generic.Dictionary<_,_> type).

Values and record fields can also be labelled as mutable. For example:

// Define 'x' with initial value '1'
let mutable x = 1
// Change the value of 'x' to '3'
x <- 3

In addition, F# supports access to all CLI types and objects such as those defined in the System.Collections.Generic namespace defining imperative data structures.

.Net and C# release history

.Net Version Release history
.Net VersionRelease DateToolFeature
1.02002Visual Studio .NetFirst release of .net
1.12003Visual Studio 2003Support for ASP.Net mobile controls
Supports side-by-side execution
Security Changes
2.02005Visual Studio 2005Generics (with generic collection)
Nullable Types
Support of IPv6 addresses in .net remoting
Common Language Runtime 2.0
3.02006WCF (Communication framework)
WPF (Presentation framework)
WF (Workflow Foundation)
3.52008Visual Studio 2008LINQ
Addin / Plugin Model (System.AddIn.Contract.dll)
4.02010Visual Studio 2010Parallel Computing
Code Contracts
Lazy Initialization
Dynamic Language Runtime
In-process side-by-side hosting
Background garbage collection
Covariance and Contravariance
Common Language Runtime 4.0
4.52012Visual Studio 2012Enhanced regular expression support
Default culture for application domain
Zip compression
Support of array with size more than 2GB
Asynchronous file operation
Improvement in parallel computing
4.5.12013Visual Studio 2013Ability to collect diagnostics information
Ability to explicitly compact the large object heap (LOH) during garbage collection
Additional performance improvements such as ASP.NET app suspension
Multi-core JIT improvements

MVP (Microsoft Most Valuable Professionals)

According to Microsoft, Microsoft Most Valuable Professional (MVP) award is given to "exceptional, independent community leaders who share their passion, technical expertise, and real-world knowledge of Microsoft products with others."[1] The awarded are people who "actively share their ... technical expertise with the different technology communities related directly or indirectly to Microsoft". An MVP is awarded for contributions over the previous year.[2] The MVP program grew out of the software developer community, as the initial MVPs were some of the most active on the online peer support communities such as Usenet and CompuServe. It has since grown to include other types of products, and other avenues of contribution. Steve Ballmer spoke to a group of Microsoft MVPs about Windows XP and Windows Vista.[3][4] A posting from Tamar Granor on the Universal Thread web site gives this account of the origin of the MVP program. “ Way back in the dark ages, Microsoft provided a great deal of technical support on CompuServe. The CompuServe FoxPro forum was extremely busy and Calvin Hsia, then an independent developer, now Developer Lead on the Fox team, created what we called "Calvin's List." It was a listing of the number of postings by person, including info on both messages sent and received. Being in the top 10 on Calvin's List any month was an accomplishment, though we discussed whether it was a good thing or a bad thing." As the story goes, some of the Microsoft people jumped on Calvin's List as a way to identify high contributors, and thus was born the MVP program.[5]