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

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube