Explain the ' notation in F#

前端 未结 2 707
[愿得一人]
[愿得一人] 2021-01-17 16:14

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


        
相关标签:
2条回答
  • 2021-01-17 16:46

    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.

    0 讨论(0)
  • 2021-01-17 17:02

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

    0 讨论(0)
提交回复
热议问题