|F# 4.5 Adds Span Support|
|Written by Kay Ewbank|
|Thursday, 16 August 2018|
There's an update to F#. While Microsoft remains the main driver behind the language, the F# team at Microsoft says Version 4.5 has been developed entirely via an open RFC process, with significant contributions from the community, especially in feature discussions and demonstrating use cases.
F# provides support for functional programming in addition to traditional object-oriented and imperative (procedural) programming. F# runs on Linux, Mac OS X, Android, iOS, Windows, GPUs, and browsers. Microsoft includes Visual F# in Visual Studio, and the language is also open source under an OSS-approved license and is available across multiple platforms through the F# Open Source Group.
The main change to the updated release is a set of features designed to work with the new Span feature in .NET Core 2.1.The Span feature is specific to .NET. System.Span<T> is a new value type that can be used to represent 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.
The F# feature set for span consists of a voidptr type, and functions in FSharp.Core to work with the type. You can also produce span structures, work with them, and write extension methods on them. The Microsoft F# team says the main goals for this feature set are:
Discussing the new feature, Phillip Carter of the F# team at Microsoft said:
"In practical terms, what all this means is that F# now has a feature set that allows for safe use of performance-oriented constructs in a very restrictive manner."
It is true that the span features are very restrictive. For example, you can't 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. Fortunately, the compiler checks for safe use of span.
Other changes in this version include support for the match! keyword in computation expressions to simplify boilerplate code; and better async stack traces so that the reported line numbers now correspond to the failing user code, and non-user code is no longer emitted.
F# 4.5 is available via the latest .NET SDK, or in Visual Studio 2017 update 15.8. Non-Windows users working in Visual Studio for Mac or Visual Studio Code with Ionide get support F# 4.5 so long as the .NET SDK is installed.
or email your comment to: email@example.com