Explain the notation in F #

I am learning F # when I type code in Visual Studio and run them in F # Interactive, it shows me things like

val foo : x:'a -> 'a 

I assume this means that foo is a function that receives paramate x type and returns a value of the same type x.

But what does this mean? Many functions also show such a thing in intellisense.

+4
source share
2 answers

The single quotation mark ( ' ) means that the type of this parameter is common. This can be done as shown in the example, or it can be explicitly applied.

For more information, see the section "Implicitly General Constructs" here.

+9
source

'a is a type variable, in other words, a type that has not yet been defined (and should not yet be defined).

Note that this is different from a' , which is a regular variable whose name is equal to two characters: a and. Unlike other languages, such as C #, a single quote is a valid character in F # variable names, except that the first character in the name may be ambiguous from the variables of the type above.

+6
source

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


All Articles