Home United States USA — software F# 4.5 Brings Spans, Match!, and More

F# 4.5 Brings Spans, Match!, and More

326
0
SHARE

Now available as a preview, F# 4.5 introduces a number of new features, including support for. NET Core 2.1 new primitive type Span, a new Match! keyword, and more.
Now available as a preview, F# 4.5 introduces a number of new features, including support for. NET Core 2.1 new primitive type Span, a new Match! keyword, and more.
Spans aim to make low-level code in the style of pointer manipulation safe and predictable, thus improving memory-efficiency and performance by eliminating the need for memory allocation in a number of cases. To this aim a Span provides a virtual view of data that is already stored somewhere in memory. For example, if you have a 10,000 element array, you can virtually create a slice containing its first 1,000 elements and pass it to a function without making a copy of those elements:
Actually, the Span feature includes a number of sub-features, such as the voidptr type, the NativePtr.ofVoidPtr and NativePtr.toVoidPtr functions and others that bring F# 4.5 Span support on a par with C# 7.3’s, as the following correspondence table shows:
To ensure code soundness, F# imposes a number of restrictions on the use of Spans, which apply to all byref -like structs:
The Match! keyword has been long awaited by developers to simplify matching syntax inside computation expressions. In F# 4.1, you were required to use let! as an intermediate step prior to matching:
With F# 4.5, you can just write:
Other features in F# 4.5 include the following:
According to Carter, despite being a preview, F# 4.5 is very stable and will be included in the upcoming release of Visual Studio 2017 update 15.8. In the meantime, it can be obtained manually both for. NET core platforms and Windows.

Continue reading...