Purpose of tick (apostrophe) in F# value names?

喜夏-厌秋 提交于 2020-03-21 11:31:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!