Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 IntelliSense: hints on F# operators

Is it possible to make Visual Studio to display tooltips on operators?

The following image demonstrates a tooltip hint for a function, but it does not work for operators.

a tooltip hint for a function

Operators usually have simple type specs like 'T -> 'T -> 'T, but such hints can be useful for custom ones.

like image 852
bytebuster Avatar asked Dec 21 '22 16:12

bytebuster


2 Answers

Following Daniel's suggestion, I'm posting a workaround that I've been using for myself.
The workaround is only partially helpful, and I'm still looking for any better ideas.

let (!><) a = ()
let z1 = op_BangGreaterLess 5

This code is fully valid, since an operator expression generates a function with a compiler-generated name. See this MSDN article, section "Overloaded Operator Names" for complete list of operator names.

Good news is that op_BangGreaterLess supports IntelliSense hints and it also supports "Go to Definition" (F12) command of IDE, pointing to an original operator declaration.
Bad news is that IntelliSense does not allow rapid entry of the full operator name (Ctrl+Space), so you have to type the entire name manually.

like image 192
bytebuster Avatar answered Jan 06 '23 01:01

bytebuster


I'm afraid this is not possible (and even in Visual Studio 2012, I don't get tooltips for operators).

I suppose this could be implemented, but as you say, operators usually have simple types. When using custom operators, these should be probably simple enough so that people can use them without looking at their type (or the associated XML documentation). Otherwise, it might be better to use a named function.

That said, if you're using F# Interactive, then you can easily use that to explore the operator type:

> (!><);;
val it : ('a -> unit) = <fun:clo@2>

If I cannot use F# Interactive, I usually define a simple dummy symbol to get the IntelliSense:

let dummy () = (!><)

Note that I added unit argument to define a function and avoid value restriction error.

like image 40
Tomas Petricek Avatar answered Jan 05 '23 23:01

Tomas Petricek