Paul Krill
Editor at Large

Microsoft’s F# refines loops in computation expressions

news
Sep 29, 20232 mins

The while! keyword is geared for clarity and expressiveness and will appear in F# 8.

binary laptop display against a binary background
Credit: Gerd Altmann

Microsoft has introduced a while! keyword in its open source F# language, providing a refined approach to loops in computation expressions.

This keyword, spoken as “while bang,” is intended to minimize boilerplate, boost clarity, and enhance expressiveness, Microsoft said in a blog post on September 20. With while!, specifying an asynchronous condition in loops now is feasible. Microsoft cites the elimination of a mutant variable, a reduction in total lines of code, and a decrease in overall cyclomatic complexity as a result of while!. The while! construct does not require a builder method but instead invokes .Bind in the same manner as <a href="https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/computation-expressions#let" rel="nofollow">let!</a> does; so there is no additional work needed when authoring new computation expressions.  Constructs are composable and can be nested.

The while! feature is to be incorporated into F# 8, which is likely to officially arrive this November with the .NET 8 software development platform. Developers can experiment with the capability now using this flag: --langversion:preview. The flag can be passed to the dotnet fsi invocation or inserted into an .fsproj file.

The new keyword was added by an external contributor to the language outside of Microsoft. F# is positioned as a language for writing “performant” code, offering first-class functions, type inference, pattern matching, and object support.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author