What’s new in the F# programming language

The main behavioral change makes F# tuple types and System.Tuple types completely synonymous, while the Version 4.5 beta brings in Span

What’s new in the F# programming language
Rob Swystun (CC BY 2.0)

In mid-August 2018, Microsoft released the production Version 4.5 of F#, which supports the Span value type from .Net Core to improve code.

Current version: What’s new in F# 4.5

Span, aka Span<T>, enables the representation of contiguous regions in arbitrary memory. With Span, Microsoft wants F# to have better code generation particularly for byref-like constructions and full parity with .Net Core performance innovations. Interoperability with high-performance code also is a goal.

Span allows for safe use of performance-oriented constructs in a restrictive manner. For example, a developer cannot define an F# record type with a Span inside it, because Span is a byref-like type and thus can only be contained in other byref types.

The Span feature set in F# 4.5 includes:

  • The voidptr type.
  • Comprehensive safety checks to prevent unsound code.
  • The ability to produce IsReadOnly structs.
  • The ability to produce IsByRefLike structs.
  • inref<’T> and outref<’T> types, which are read- and write-only versions of byref<’T>.
  • The ability to write extension methods on byref<'T>inref<'T>, and outref<'T>.

F# also features better stack traces for asynccomputation expressions, in which reported line numbers now correspond to the failing user code and nonuser code is no longer emitted. Other features of F# 4.5 include:

  • Implicit dereference of byref-like return values, allowing for assignment to byref returns from F# functions, methods, and properties similar to what is done in C#.
  • Better async stack traces for async computation expressions, in which reported line numbers correspond to the failing user code and nonuser code is no longer emitted.
  • Support for the match! keyword in computation expressions, thus shortening common boilerplate code.
  • Relaxed upcast requirements when using yield in sequence, list, and array expressions.
  • Relaxed indentation rules for list and array expressions.
  • Enumeration cases are now emitted as public in all circumstances. This helps with profiling tools, making it easier to analyze tools performance.

Where to download F# 4.5

You can download F# 4.5 by downloading the .Net SDK (2.1.400 or higher) or the Visual Studio 2017 Update 15.8.

Previous version: New features in F# 4.1

With the March 2018 release of Visual Studio 2017 15.6, Microsoft has made foundational changes to the F# language and core library. F# is a Microsoft-developed, strongly typed language positioned as being “functional-first.”

The main behavioral change makes F# tuple types and System.Tuple types completely synonymous. As a result, a warning is presented when developers acces .Item and .Rest properties from a system tuple. This changes fixes inconsistencies in how the two types interact and repairs a regression that was introduced in Visual Studio 2017 15.4.

Other changes include:

  • F# project support for .Net Core SDK-based projects now have full file-ordering and folder support.
  • The F# library, FSharpCore, has the IsSerializable property on F# types for the .Net Standard version of the library. The library also supports the Async.StartImmediateAsTask function.
  • A change in versioning enables tools to align with multiple release trains for different products, rather than artificially aligning with an F# language version. The language, the FSharpCore binary, and the FSharpCore package will use the same versioning scheme. To enable this alignment, the F# language version will jump from 4.1 to 4.5 when Visual Studio 2017 15.7 ships.

Copyright © 2018 IDG Communications, Inc.