Naf*_*lam 2 f# functional-programming function
In F# I can define a function like this
let (-+->) x y = x + y
Run Code Online (Sandbox Code Playgroud)
and call like this
let z = 5 -+-> 6
Run Code Online (Sandbox Code Playgroud)
I can even do something like this
let (-++->) x y z = x y z
let p = ((fun x -> fun y -> x + y) -++-> 5 ) 6
Run Code Online (Sandbox Code Playgroud)
But why can't I do this?
let (nafis) x y = x + y
let p = 5 nafis 6
Run Code Online (Sandbox Code Playgroud)
it gives me this error Unexpected identifier in binding. Expected '=' or other token
.
Are functions like let (-+->) x y = x + y
any special kind of function?
F#规范中定义了对运算符的词汇约束:
3.7符号运算符
用户定义和库定义的符号运算符是如下所示的字符序列,除非字符序列是符号关键字(第3.6节)。
regexp first-op-char= !%&*+-./<=>@^|~
regexp op-char= first-op-char | ?
token quote-op-left =
| <@ <@@
token quote-op-right =
| @> @@>
token symbolic-op=
| ?
| ?<-
| first-op-charop-char*
| quote-op-left
| quote-op-right
Run Code Online (Sandbox Code Playgroud)
如您所见,-++->
有效,而nafis
无效。
归档时间: |
|
查看次数: |
69 次 |
最近记录: |