News

What's New in Microsoft's F# Language for Functional-First Programming

C# and TypeScript get a lot more attention, but Microsoft has also been steadily working to improve its F# programming language.

The open source and cross-platform F# is officially described as a "universal programming language," but it's primarily used in functional programming, which is centered around pure functions and immutable data, whereas the more often-used object-oriented programming (OOP) approach organizes code around objects that contain both data and methods.

It has lately been developed in lock-step with .NET, so the latest version of the language, F# 7, debuted with .NET 7 in November 2022.

That means you can expect to see F# 8 next week with the general availability of .NET 8.

Here's a sneak peek at what's new, culled from recent Microsoft announcements from the F# team. Most new features and functionality seem to come from external community contributors, which is by design (see Microsoft's F# strategy below).

Overhauled F# Code Fixes in Visual Studio
Last month Microsoft detailed work done to improve code fixes, those familiar suggestions marked by squiggly lines that appear when IDE diagnostics detects a problem and displays an error, warning or informational message. Code fixes were designed to automatically fix problems.

For F# in Visual Studio, there are more than 30 code fixes available for tasks including removing redundant code, converting C# constructs to F#m adding missing import directives or inserting a missing keyword, the latter shown in this video:

"Challenges emerge when a code fix is suitable for certain instances but might lead to undesirable source modifications in others," the dev team said last month. "Our primary objective has been to ensure code fixes are precise and don't mislead developers."

Code fix performance improvements were also made, such as a community-contributed library to help reduce memory consumption and improve the management of canceled user actions.

The team also switched from unsustainable manual testing of code fixes to unit testing with a new framework tailored just for that purpose.

Graph-Based Type Checking
Just this week, the team published a guest post about a new F# compiler feature: graph-based type checking, which allows in-parallel checking of files via signature files and a dependency graph.

The post explains that type checking is typically one of the most time consuming phases of the compilation, in part because this has been done via the sequential checking of each individual file of a project.

"Introducing some parallelization could significantly speed things up," said guest blogger Florian Verdonck, a member of the G-Research team for open source contributions. "Accelerating large data processing jobs is something of great interest to the G-Research OSS team."

He discussed a new feature flag --test:GraphBasedChecking, which will try to type-check any file in parallel on multiple threads, regardless if it is backed by a signature file. However, to determine which files can be processed in parallel, the relationship between each file in a project must be known. The current relationship is determined by the file order in the project, with each file holding the type-checked information of all the files ordered before it.

Which is where the dependency graph comes in, providing a better way to discover file relationships by working in esoteric ways fully detailed in the post for those interested in the nitty-gritty bits.

Simplifying F# Computations with the New "while!" Keyword
That title for September post pretty much says it all in describing this new feature, also a community contribution.

Basically, the introduction of the while! keyword in F# 8 allows for loops with asynchronous conditions in computation expressions. "With the advent of the while! keyword, specifying an asynchronous condition in loops becomes feasible," the team said, noting that is simplifies projects by reducing boilerplate code while also increasing code clarity.

Much More
Other posts detailing new F# features that are sure to be fleshed out next week with the debut of .NET 8 include:

Microsoft F# Strategy: Provide Leadership/Governance, Rely on Community Contributors
Early this year Microsoft published an Annotated F# strategy guide, which details the company's reliance on community contributors to improve F#: "We will drive F# evolution and support the F# ecosystem with language leadership and governance. We will encourage community contributions to improve the F# language and developer experience. We will continue to rely on the community to provide important libraries, developer tools and workload support. As the language evolves, F# will support .NET platform improvements and maintain interoperability with new C# features. We will work across language, tooling, and documentation to lower the barrier to entry into F# for new developers and organizations as well as broadening its reach into new domains."

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

Subscribe on YouTube