News

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 at Converge 360.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube