How to see type for statements in F # interactive?

I am trying to learn the type of operators like :: in F # interactive.

But I get the following messages:

 Unexpected symbol '::' in expression. Expected ')' or other token. 

even if I surround it with (::) .

+4
source share
3 answers

I do it like this:

 > let inline showmecons ab = a :: b;; val inline showmecons : 'a -> 'a list -> 'a list 

or

 > let inline showmepow ab = a ** b;; val inline showmepow : ^a -> ^b -> ^a when ^a : (static member Pow : ^a * ^b -> ^a) 
+8
source

You will see the type of regular operators if you surround them with parentheses:

 > (+);; val it : (int -> int -> int) = <fun: it@4-5 > 

Unfortunately, this limits the type of operator to one specific type - F # Interactive does not print a polymorphic definition (with restrictions). You can use the workaround suggested by Stephen (and define a new inline function) to see this.

The reason it does not work for :: is because :: is actually a special syntax construct (defined directly in the F # specification).

+4
source

This is pretty old, but I am learning F # and also want to understand this.

Looking at the F # specification on page 32, we see that symbolic keywords also have a compiled name in F #. The equivalent compiled name for :: is op_ColonColon , which actually accepts tuples:

 > op_ColonColon;; val it : arg0:'a * arg1:'a list -> 'a list = <fun: clo@22-5 >` 

Using :: to define an inline function will give us the curries cons function, which I assume is misleading.

0
source

Source: https://habr.com/ru/post/1344032/


All Articles