F# 9, the latest version of Microsoft’s open source functional language, has been released with support for nullable reference types and empty-bodied computation expressions. Standard library improvements also are featured, including random sampling functions.
F# 9 was released in conjunction with the .NET 9 software platform on November 12. Instructions on getting started with F# can be found at dotnet.microsoft.com.
With nullable reference types in F# 9, F# now has a type-safe way to deal with reference types that can have null
as a valid value. While F# was designed to avoid null
, it nevertheless can creep in with .NET libraries written in C#. F# 9 also introduces support for empty computation expressions. Writing an empty computation expression will result in a call to the computation expression builder’s Zero
method. This is a more natural syntax compared to the previously available builder { () }
, Microsoft said.
In the FSharp.Core standard library in F# 9, the List
, Array
, and Seq
modules have new functions for random sampling and shuffling, making F# easier to use for common data science, machine learning, and other scenarios where randomness is needed. Also with the standard library, Shuffle
functions return a new collection of the same type and size, with each item in a randomly mixed position. In another standard library improvement, developers now can use C# collection expressions to initialize F# lists and sets from C#.
F# also brings performance improvements. Equality checks now are faster and allocate less memory, and the compiler now generates optimized code for more instances of start..finish
and start..step..finish
expressions.
Other new features and improvements in F# 9:
#help
directive in F# Interactive now shows documentation for a given object or function, which now can be passed without quotes.