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

  • 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