I'm learning F#, when I type any code in Visual Studio and run them on F# Interactive it shows me things like
val foo : x:'a -> 'a
I imagine this mean that foo
is a function that receive a paramater x
of a type, and returns a value of same x's type.
But What does that '
mean? Many functions show such thing on intellisense too.
Function notation is a simpler method of describing a function without a lengthy written explanation. The most frequently used function notation is f(x) which is read as “f” of “x”. In this case, the letter x, placed within the parentheses and the entire symbol f(x), stand for the domain set and range set respectively.
f(x) is the value of the function. m is the slope of the line. b is the value of the function when x equals zero or the y-coordinate of the point where the line crosses the y-axis in the coordinate plane. x is the value of the x-coordinate.
f(x,y) is a function which takes in an ordered pair (x,y) and gives some output. It's still called a function, but if you want to be specific, you can call it a function of two variables.
A function is most often denoted by letters such as f, g and h, and the value of a function f at an element x of its domain is denoted by f(x); the numerical value resulting from the function evaluation at a particular input value is denoted by replacing x with this value; for example, the value of f at x = 4 is ...
The single quote mark ('
) means that the type of that parameter is generic. It can be inferred, like the example you gave, or it can be explicitly applied.
See here under Implicitly Generic Constructs for more information.
'a
represents a type variable, in other words a type that is not determined yet (and doesn't have to be determined yet).
Note that this is different than a'
, which is a regular variable whose name is two characters: a and '. Contrary to other languages like C#, the single quote is a permitted character in F# variable names, except as the first character in the name to disambiguate from type variables above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With