问题
I'm going through a tutorial on Function Composition, and I keep seeing the ' operator used at the end of a value declaration.
I know that it means a generic when it precedes a parameter, but what does it mean when you see it like:
let add x y = x + y
let myFunc' = add 10
The only thing I can see is that the ' is just another character in the identifier. Is that right? Because if I use that same example, using myFunc gives a not defined error, where myFunc' does resolve.
回答1:
Yes, as @Lee pointed, '
is a valid identifier.
Though, the purpose of '
at the end of identifiers generally is to denote the value as something related or similar to the value named without the ending '
. This is borrowed from mathematics, F# being a functional language, for denoting something as being prime since A is pronounced aye
where A' is aye-prime
.
回答2:
Yes, ' is a valid identifier character, although it cannot be the first one. The structure of identifiers is defined in the specification:
3.4 Identifiers and Keywords
ident-text = ident-start-char ident-char*
ident-char = letter-char | digit-char | connecting-char | combining-char | formatting-char | ' | _
来源:https://stackoverflow.com/questions/23688905/purpose-of-tick-apostrophe-in-f-value-names