Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 * float = (42, "Hello F#", 42.0)

How can I mimick the same behaviour in my own code, e.g. to get the inferred types as string for a F# expression?

I don't need to dynamically evaluate any F# expressions, the expressions are known in compile time and are part of my (static) F# code. I need this feature to be able to mimick the FSI output in LINQPad for my F# demos.

like image 977
Alexander Galkin Avatar asked Mar 28 '12 13:03

Alexander Galkin


People also ask

What is the F probability?

The p value is a probability, while the f ratio is a test statistic, calculated as: F value = variance of the group means (Mean Square Between) / mean of the within group variances (Mean Squared Error)

How do you find F in regression?

f-statistics can be calculated as MSR/MSE where MSR represents the mean sum of squares regression and MSE represents the mean sum of squares error. MSR can be calculated as SSR/DFssr where SSR is the sum of squares regression and DFssr represents the degree of freedom for the regression model.

How do you write the F ratio?

The F ratio statistic has a numerator and denominator degrees of freedom. Thus, you report: F (numerator_df, denominator_df) = F_value, p = ..., effect size = ...


2 Answers

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: https://github.com/SwensenSoftware/unquote/blob/2.1.0/Unquote/ExtraReflection.fs#L54

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

like image 180
Stephen Swensen Avatar answered Nov 13 '22 06:11

Stephen Swensen


If you look at the F# compiler code and see how the --sig option is handled by the compiler I think that will get you what you're looking for. More about the --sig option and signatures here:

Signatures (F#)

like image 26
Onorio Catenacci Avatar answered Nov 13 '22 08:11

Onorio Catenacci