BT

InfoQ Homepage News F# 4.7 Enables Preview of New Language Features and Relaxes Syntax

F# 4.7 Enables Preview of New Language Features and Relaxes Syntax

Bookmarks

The latest release of F# introduces a new LangVersion configuration option which makes it possible to choose which language version you would like the F# compiler to target. Additionally, it introduces a number of syntax relaxations that are aimed to remove a few idiosyncrasies of the language.

Starting with F# 4.7, developers can specify which language version they would like to use by including the LangVersion property in their projects. Most interestingly, this enables the possibility of working with preview versions of the language that are still considered experimental or have not reached yet their final design, which makes it easier for developers to play with them and provide feedback.

As a first iteration of this model of delivery of new features, F# 4.7 includes preview support for nameof and the ability to open static classes, which were among the features developers requested the most. nameof is a convenience function aimed to improve the logging of entity names such as parameters, functions, modules, etc. It enables using the actual name of the entity it is applied to without requiring to manually update it after a refactoring. The possibility of opening static classes aims to make static classes more flexible and brings their support in F# on a par with C#. Thanks to this feature, DSLs may benefit from a shortened syntax. For example, if you have a DSL implemented through a MyDSL static class or type provider exporting a static class, you can use unqualified names, e.g. feature instead of MyDSL.feature, by first opening the static class, just as you do with modules.

Still on the front of tooling, F# 4.7 enables F# Interactive from the .NET command line using dotnet fsi, although with some quirks related to package importing, and improves integration with Visual Studio 2019.

Speaking of syntax, as mentioned, F# 4.7 introduces a couple of syntax relaxations aimed at making the language friendlier. When specifying member declarations, previous versions of F# allowed you to omit this and replace it with a double underscore. F# 4.7 enables the use of a single underscore instead. Furthermore, parameters to constructors or static methods can be now freely indented, whereas previous versions of the compiler required them to be indented more deeply than the first parameter. Finally, for lists, arrays, sequences, and computations that define Yield, Combine, Delay, and Zero members, it is not required anymore to specify yield, so you can simply write the following:

let nums =
    seq {
        1    // implicitly assumes yield 1
        2    // implicitly assumes yield 2
        3    // implicitly assumes yield 3
    }

let f' includeWeekend =
    [ 
        "Monday"
        "Tuesday"
        "Wednesday"
        "Thursday"
        "Friday"
        if includeWeekend then  // conditional values required yield even in arrays - not anymore
            "Saturday"
            "Sunday"
    ] 

F# 4.7 extends its support for parallel and asynchronous programming by adding a maxDegreesOfParallelism parameter to Async.Parallel and Async.Sequential to enable sequential execution of async computations.

Last but not least, F# 4.7 bumps up its support for .NET Standard to version 2.0. Thanks to this , F# 4.7 simplifies dependency management and supports a number of new APIs, including a few methods meant to simplify the handling of function values through FSharpFunc<'T, 'TResult> and Converter; and access to the MatchFailureException type and to the WebExtensions namespace.

To use F# 4.7, you need .NET Core 3.0and Visual Studio Code with Ionide or alternatively the latest Visual Studio.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.