Microsoft’s F# 6 boosts performance, ease
F# 6, an upgrade to Microsoft’s open source, multi-paradigm, programming language, is now officially available as part of .NET 6. The new version promises to make it easier to write succinct, performant code, Microsoft said.
.NET 6 was formally unveiled on November 8. F# 6 also was previewed with .NET 6 Release Candidate 2 and Visual Studio 2022 RC2. F# supports multiple programming models including functional, object-oriented, and imperative.
With F# 6, project developers aimed to make the language simpler and more performant in areas including language design, library, and tools. A goal of the long-term evolution of the language is to remove corner-cases that surprise users or are unnecessary hurdles to adoption.
Speed and interoperability in F# 6 are being addressed with a task …
capability to create a task and await it. One of the most requested features for F#, and the most significant technical feature in F# 6, has been to make authoring asynchronous tasks simpler, more performant, and more interoperable with other .NET languages such as C#.
Prior to this release, creating .NET tasks required using async …
to create a task and then invoking Async.AwaitTask
. Now task …
can be used directly to build a task. Built-in support for task …
is available in F# code with no need to open namespaces. Task support had been available for F# 5 through the TaskBuilder.fs and Ply libraries. These guided the design of task support in F# 6.
Elsewhere in F# 6:
- The console template for F# 6 has been simplified. The new template is two lines:
// For more information see https://aka.ms/fsharp-console-apps
printfn "Hello from F#"
- For uniformity, F# 6 allows
_
to be used in ause
binding. - To make F# simpler to learn, the project is allowing the syntax ex
pr[idx]
to mimic indexer/slicing syntax. - To make the language faster, F# 6 supports Struct representations for active patterns, allowing developers to use an attribute to constrain a partial active pattern to return a value option.
- For speed, F# 6 offers improved performance for debugging for list and array expressions. Also for speed, a new declarative feature has been added that allows code to optionally indicate that lambda arguments should be inlined at callsites.
- “First-class” support is offered for .NET-style implicit conversions. in F# 6,
op_Implicit
conversions are applied automatically for argument expressions when they are available and the types are known for the source expression and target type. - Pipeline debugging has been added in the F# toolchain.
- For uniformity, F# 6 activates the “overloaded custom operations in computation expressions” feature, allowing for simpler DSLs in F#, including for validation and web programming. Also for uniformity, the right-hand side of an “as” pattern now itself can be a pattern, and a number of inconsistencies and limitations have been removed in F#’s use of indentation-aware syntax. Uniformity also has been enhanced with additional numeric types with unit annotations.
- For performance and scalability, improvements have been made in areas such as the compiler, which now performs the parsing stage in parallel, and in analysis results, which are now performed concurrently.
- F# developers will benefit from .NET 6 improvements such as source build, to satisfy packaging rules of commonly used Linux distributions, and profile-guided optimization, which can compile startup code at higher quality, reduce binary size, and rearrange application binaries so code used at startup is collocated near the start of the file.
- In-memory cross-project referencing simplifies working between F# and C# projects. With this capability, C# projects now are reflected immediately in an F# project without having to recompile the C# project on disk.
- If developers open an F# Script
(.fsx
) in Visual Studio, by default the script will be executed using .NET Core with 64-bit execution. - Use of rarely used symbolic operators has been reduced. Long-deprecated features have been removed, such as multiple generic parameters using a postfix type name.
Copyright © 2021 IDG Communications, Inc.