Visual Studio 2010 IntelliSense: hints on F# operators

杀马特。学长 韩版系。学妹 提交于 2019-12-06 05:51:15

问题


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.

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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/12169031/visual-studio-2010-intellisense-hints-on-f-operators

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!