Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain the ' notation in F#

Tags:

f#

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.

like image 615
Fabricio Avatar asked Jul 28 '13 19:07

Fabricio


People also ask

What notation is f?

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.

What does f mean in an equation?

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.

What does the notation f/x y mean?

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.

What does f mean in geometry?

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 ...


2 Answers

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.

like image 185
N_A Avatar answered Sep 18 '22 15:09

N_A


'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.

like image 21
DuckMaestro Avatar answered Sep 18 '22 15:09

DuckMaestro