F# I want to look at the type of declaration specified in Interactive

Asked 2 months ago, Updated 2 months ago, 1 views

F#Interactive displays the type along with the value.

value : int = 1
value:(Printf.TextWriterFormat<'a>->'a) =<fun:[email protected]>

Then, is there a way to specify a type and check the declaration of that type?

Simply specifying the type name will display the type of constructor.

value: arg00:string->PrintfFormat<'a, System.IO.TextWriter, unit, unit>=
  <fun:[email protected]>


stdin(7,1): error FS0039: no value or constructor 'Option' defined

Instead, I'd like to see a declaration of the type itself written in a .fsi file.

When you define a type on F#Interactive, you see something similar, so can you apply it to an existing type?

>type Foo=A of int|B with
-     member self.Hoge(x) = 1;

type Foo=
  | A of int
  | B
    member Hoge:x:'a->int

As you can see by typing in F#Interactive when you're curious about the type of function, if you look at the type declaration in the same way, you don't have to open a browser...


2022-09-30 11:46

2 Answers

I don't know if it's an answer, but if it's an F# project instead of an F# interactive, F12 Go To Definition opens documents in a browser, but if it's an Alt+F12 Peek Definition, it shows the type definition on the editor.

2022-09-30 11:46

It may be a little different (I think you need to look at the source for definitions),
I think you mean typeof.


Example: typeof<Option<_>>;;

2022-09-30 11:46

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.