Paul Krill
Editor at Large

Microsoft previews new F# syntax for string interpolation

news
Aug 8, 20232 mins

Improved syntax makes it easier to work with text like CSS that contains many curly braces, while maintaining backwards compatibility with F#’s triple-quoted strings.

Microsoft is previewing new syntax for string interpolation in F#, an improvement intended to make it easier to work with interpolated strings.

Interpolated strings allow developers to embed F# expressions into string literals. But they can become cumbersome when dealing with text that contains many curly braces. The F# interpolation syntax addresses this. Announced July 27 and modeled after how interpolation works in C# raw strings, the new syntax maintains backward compatibility with F#’s triple-quoted strings.

The new syntax is an extension of the existing F# syntax for interpolated strings. Developers can use multiple $ characters and corresponding numbers of opening and closing curly braces for interpolation. The same rules apply to % characters, which have special meaning in F# interpolated strings as format specifiers.

An example of where this new syntax can be useful is when working with CSS literals in a front-end F# application, such as with the Fable F# compiler for JavaScript. The new syntax lets developers write CSS without having to worry about escaping curly braces. Instead, developers can focus on the interpolation expressions. To try out this new feature, developers must use the flag --langversion:preview.

F# is a language that offers first-class functions, lightweight syntax, pattern matching, and async programming, according to Microsoft. It is immutable by default. Other recent improvements for F# developers include a preview of F# type and parameter hints in Visual Studio. Installation instructions for the language can be found on learn.microsoft.com.

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