How to generate the F# type signature similar to FSI in my own code?

后端 未结 2 481
余生分开走
余生分开走 2021-01-02 04:26

If one uses the F# Interactive Shell (FSI), the inferred expression type (signature) is printed to the console along with its value:

val it : int * string *          


        
2条回答
  •  孤城傲影
    2021-01-02 05:07

    Using Unquote

    Unquote has a facility for getting the F# signature of a type. Simply download the latest release and add a reference through LINQPad to Unquote.dll, then you can do e.g.

    enter image description here

    If you're interested, you can peak at the source code for the implementation of the FSharpName Type extension: http://code.google.com/p/unquote/source/browse/tags/2.1.0/Unquote/ExtraReflection.fs#54.

    Using FsEye

    Another neat approach would be to use LINQPad's beta Custom Visualizer API to embed FsEye into LINQPad (FsEye uses the same F# type signature printing algorithm as Unquote). This is also very simple, all you need to do is download LINQPad beta, download and reference FsEye.dll from the latest release of FsEye, then you can do e.g.

    enter image description here

提交回复
热议问题