Fabricio
Fabricio

Reputation: 7935

Explain the ' notation in 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.

Upvotes: 15

Views: 2103

Answers (2)

N_A
N_A

Reputation: 19897

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.

Upvotes: 20

DuckMaestro
DuckMaestro

Reputation: 15885

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

Upvotes: 17

Related Questions