News

F# 4.5 Arrives with Span Support, Aligning with .NET Core 2.1

Microsoft shipped an update to its functional programming language, incorporating Span support in the new F# 4.5.

Described as "the largest piece of F# 4.5," Span support aligns the open source language with the Span feature in .NET Core 2.1, which shipped in May.

That System.Span<T> feature, Microsoft explained, "is a new value type at the heart of .NET. It enables the representation of contiguous regions of arbitrary memory, regardless of whether that memory is associated with a managed object, is provided by native code via interop, or is on the stack. And it does so while still providing safe access with performance characteristics like that of arrays."

In announcing F# 4.5 this week, Microsoft said the main goals of the new Span feature set are:

  • Offer ways to interoperate with and produce high-performance code in F#.
  • Full parity with .NET Core performance innovations.
  • Better code generation, especially for byref-like constructs.

"What this boils down into is a feature set that allows for safe use of performance-oriented constructs in a very restrictive manner," said Microsoft's Phillip Carter. "When programming with these features, you will find that they are far more restrictive than you might initially anticipate. For example, you cannot define an F# record type that has a Span inside of it. This is because a Span is a 'byref-like' type, and byref-like types can only contained in other byref-like types. Allowing such a thing would result in unsound F# code that would fail at runtime! Because of this, we implement strict safety checks in the F# compiler to prevent you from writing code that is unsound."

Another new feature in F# 4.5 is the new match! keyword that Carter says somewhat shortens a lot of common boilerplate code. That, Carter said, comes entirely from John Wostenberg, one of the many developers in the open source community who helps shape F#.

In fact, all F# development is based on an open RFC (requests for comments) process, and developers can inspect all those RFCs for F# 4.5 and FSharp.Core 4.5.0.

Other new features highlighted by Carter include:

  • Relaxed upcast requirements with yield in F# sequence, list and array expressions
  • Relaxed indentation rules for list and array expressions
  • F# enumeration cases emitted as public
  • Better async stack traces
  • Additional FSharp.Core improvements
  • F# tools updates
  • New Visual Studio features

The Microsoft team has recently been focused on shipping F# 4.5 and related tooling for Visual Studio 2017 15.8 (which was just released this week), but it has also been planning future work on the functional programming language.

Developers interested in seeing in what directions the community will be driving the language going forward can check out the F# Suggestions site on GitHub.

However, note that there is currently a backlog of approved ideas, and the top five suggestions that boast the most "thumbs up" reactions all stem from 2016.

As far as a roadmap for the language going forward, Microsoft says the closest approximation is the list of approved-in-principle items.

One primary area of focus for the F# team, Carter said, is better positioning in the machine learning space.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

Subscribe on YouTube