How to determine a type in F#?

  • A+

In Python, I could see the variable's type by typing:

>>> i = 123 >>> type(i) <type 'int'> 

Is there a way to do this in F#?


If you're wanting to do this in F# Interactive, you just need to evaluate the variable by typing its name (followed by ;; as with any other expression at the F# Interactive prompt). I.e., if you've already executed let num = 123, then you just type num;; at the F# Interactive prompt and you'll see the following printed out:

val it : int = 123 

The word val means that F# Interactive is describing a value. The name it is a special name in F# Interactive, assigned to the last value that was evaluated. Then comes a colon, the value's type (in this case, int), then an equals sign, and then the value is printed out.

So all you have to do to see the value and type of a variable in F# Interactive is to just type that variable followed by ;;. Simple.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: