Skip to main content

Introducing F# Inline Type & Parameter Name Hints in Visual Studio

We are constantly working on improving the F# editor experience in the Visual Studio and now we are launching a highly requested features, Hinting. Hints for F# mean that you will no longer have to hover to get information when coding, check it out:

Code

type Song = {
    Artist: string
    Title: string
}

let whoSings song = song.Artist

let artist = whoSings { Artist = "Arcade Fire"; Title = "Wake up" }

Overview

We currently support two kinds of hints: inline type hints and inline parameter name hints. Both are useful when the names of identifiers in code aren’t intuitive. With hints, you won’t need to hover over them and will see the necessary info right away.

Hints are available for the majority of the F# features, including tuples and type constructors:

Image with hints for different language elements

Code

type Song = {
    Artist: string
    Title: string
}

type Playlist(songs) =
    member this.Add(artist, title) = 
        { Artist = artist; Title = title } :: songs

let song1 = { Artist = "London Grammar"; Title = "Lose Your Head" }
let song2 = { Artist = "Blur"; Title = "Song 2" }

let playlist = Playlist([ song1; song2 ])
let _ = playlist.Add("The Big Moon", "Your Light")

Here are the hints in action for discriminated unions:

Image with hints for discriminated unions

Code

type Genre = 
    | Rock of subgenre : string
    | Pop of subgenre : string

let genre = Rock "psychedelic"

let printFullGenre = function
    | Genre.Rock subgenre -> $"{subgenre} rock"
    | Genre.Pop subgenre -> $"{subgenre} pop"

Note that to reduce information noise in the editor, we don’t show type hints when types are explicitly specified and we don’t show parameter name hints when argument names coincide with parameter names: Image demonstrating removed hints when they are considered redundant

Code

type Song = {
    Artist: string
    Title: string
}

let whoSings song = song.Artist

let song: Song = { Artist = "London Grammar"; Title = "Lose Your Head" }
let song2 = { Artist = "Blur"; Title = "Song 2" }

let artist1 = whoSings song
let artist2 = whoSings song2

Comparison to C# Inline Hints

C# has Inline Hints for a while now. F# Hints share the same concept yet the implementation is a bit different. For example, C# type hints are displayed to the left of variables whereas F# type hints are displayed to the right of values, to follow the syntax rules in each language.

Image with equivalent C# and F# code with hints

Enable F# Hints

Sounds interesting? You can turn the hints on in the Advanced section of the F# options in Visual Studio Preview:

Image with Visual Studio settings for F# Hints

We are still doing some bughunting so the feature is off by default.

Call for contributors

There is much more to be done in this area! You can find the roadmap for hints in this issue or see all open tickets using this query. Among other things, we plan to bring signature hints, implement click-to-show behavior, and reduce the number of hints in obvious cases.

We would welcome your help, many of the open tickets are good first issues and we also have a testing framework for hints so that you can easily verify the behavior.

For the current implementation, big thanks go to our external contributors @kerams and @rosskuehl.

The post Introducing F# Inline Type & Parameter Name Hints in Visual Studio appeared first on .NET Blog.



Comments

Popular posts from this blog

Fake CVR Generator Denmark

What Is Danish CVR The Central Business Register (CVR) is the central register of the state with information on all Danish companies. Since 1999, the Central Business Register has been the authoritative register for current and historical basic data on all registered companies in Denmark. Data comes from the companies' own registrations on Virk Report. There is also information on associations and public authorities in the CVR. As of 2018, CVR also contains information on Greenlandic companies, associations and authorities. In CVR at Virk you can do single lookups, filtered searches, create extracts and subscriptions, and retrieve a wide range of company documents and transcripts. Generate Danish CVR For Test (Fake) Click the button below to generate the valid CVR number for Denmark. You can click multiple times to generate several numbers. These numbers can be used to Test your sofware application that uses CVR, or Testing CVR APIs that Danish Govt provide. Generate

How To Iterate Dictionary Object

Dictionary is a object that can store values in Key-Value pair. its just like a list, the only difference is: List can be iterate using index(0-n) but not the Dictionary . Generally when we try to iterate the dictionary we get below error: " Collection was modified; enumeration operation may not execute. " So How to parse a dictionary and modify its values?? To iterate dictionary we must loop through it's keys or key - value pair. Using keys

How To Append Data to HTML5 localStorage or sessionStorage?

The localStorage property allows you to access a local Storage object. localStorage is similar to sessionStorage. The only difference is that, while data stored in localStorage has no expiration time untill unless user deletes his cache, data stored in sessionStorage gets cleared when the originating window or tab get closed. These are new HTML5 objects and provide these methods to deal with it: The following snippet accesses the current domain's local Storage object and adds a data item to it using Storage.setItem() . localStorage.setItem('myFav', 'Taylor Swift'); or you can use the keyname directly as : localStorage.myFav = 'Taylor Swift'; To grab the value set in localStorage or sessionStorage, we can use localStorage.getItem("myFav"); or localStorage.myFav There's no append function for localStorage or sessionStorage objects. It's not hard to write one though.The simplest solution goes here: But we can kee