New in Visual Studio F# Tooling: .NET 5 Scripting and F# Interactive

Visual Studio 2019 v16.9 recently shipped with a bunch of new goodies for coders of all kinds, including functional programmers using F#, who likely will be interested in new tooling including .NET 5 scripting and F# Interactive.

Those two related items are among a bevy of other new functionality, tweaks and fixes that came with the debut of VS 2019 v16.9, a servicing baseline release guaranteed to be supported until a year after the next such release.

They are related in that they are both enabled by .NET 5, yet another huge milestone release from Microsoft, this one arriving last November to replace the old, proprietary, Windows-only .NET Framework with a modern substitute featuring cross-platform functionality and open source development. It also began a unification effort to consolidate all the disparate .NET components, frameworks, tooling and so on, which will be completed in November with .NET 6.

In a recent blog post, Microsoft highlighted what's new for F# in the new Visual Studio release, which includes the ability to turn on .NET 5 scripting and the .NET 5-based F# Interactive (executed from the command line with dotnet fsi), which can run F# code interactively at the console or execute F# scripts. "In other words, F# interactive executes a REPL (Read, Evaluate, Print Loop) for the F# language," Microsoft says.

Turning On F# Interactive
[Click on image for larger view.] Turning On F# Interactive (source: Microsoft).

The menu commands Tools > Options > F# Tools > F# Interactive > Use .NET Core Scripting will light it up: F# Interactive's dotnet fsi will process F# code, with all F# scripts behaving like they're running on .NET Core.

That results in this:

  • Packages that require netstandard2.1, netcoreapp3.1, or net5.0 will now work with #r "nuget:..." in F# Interactive from Visual Studio
  • The default set of libraries available to scripts will be .NET 5-based, not .NET Framework-based
  • Any scripts that require .NET Framework to run (e.g., depend on AppDomains) may not work when this is used

As far as the .NET 5 scripting, Microsoft's documentation for F# Interactive says:

Evaluating code interactively in F# Interactive can be a great learning tool, but you'll quickly find that it's not as productive as writing code in a normal editor. To support normal code editing, you can write F# scripts.

Scripts use the file extension .fsx. Instead of compiling source code and then later running the compiled assembly, you can just run dotnet fsi and specify the filename of the script of F# source code, and F# interactive reads the code and executes it in real time.

In the F# productivity department, the dev team highlighted improved Signature Help, an IntelliSense feature. As its name suggests, it displays the signature of a method in a tooltip when a developer types the character that precedes a parameter list, usually an opening parenthesis character. An F# method is a function that is associated with a type. Now Signature Help works with functions in addition to working with methods.

Signature Help for Function Calls
[Click on image for larger view.] Signature Help for Function Calls (source: Microsoft).

"Now, Signature Help can trigger when you're calling an F# function!" said Phillip Carter, program manager, .NET and Languages. "This is a long-requested feature by F# developers. F# function parameters are separated by spaces, so to trigger Signature Help, press the space key. Then you'll see a similar tooltip, but this time for the F# function signature."

Carter also detailed core compiler improvements, more performant and responsive tooling and a whole bunch of code fixes (also enacted in VS Code):

  • Add missing rec keyword
  • Convert C# lambda to F# lambda
  • Add missing fun keyword in F# lambda
  • Remove incorrect use of return keyword
  • Convert record expression to anonymous record
  • Use mutation syntax when a value is mutable
  • Make a declaration mutable
  • Use upcast instead of downcast
  • Add missing = to record, union, or type alias definition
  • Use single = for equality check
  • Use not to negate an expression
  • Wrap expression in parentheses
  • Fix ambiguity between subtraction and negation

Going forward, Carter said the team is looking into:

  • Showing decompiled sources when you invoke Go to Definition on a construct not in your codebase
  • Support for Inline Type Hints when pressing a key command
  • Support for Inline Parameter Name Hints when pressing a key command
  • Improved F# Signature File generation from within Visual Studio
  • Support loading packages that depend on framework references in F# Interactive

"We're also planning out what the next version of the F# language will include to coincide with the .NET 6 release. We hope to have some exciting things to share in the coming months," Carter said.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus


Subscribe on YouTube