为什么允许$,但$$,或<$>作为运算符(FS0035)不允许以及什么使$特殊?

Abe*_*bel 6 f# operator-overloading dollar-sign

$允许在自定义运算符中使用,但如果您尝试使用$$,<$>或者例如~$%作为运算符名称,您将收到以下错误:

错误FS0035:不推荐使用此结构:'$'不允许作为运算符名称中的字符,并保留供将来使用

$显然也有名字中的'$',但有效,为什么?即:

let inline ( $ ) f y = f y

// using it works just fine:
let test = 
    let add x = x + 1
    add $ 12
Run Code Online (Sandbox Code Playgroud)

$在网上的例子中看到了很多,显然是一种特殊的运营商.什么是这种特殊处理或角色$(即在Haskell或OCaml中)以及<$>如果允许(编辑)该怎么办?

试图通过创建一个类似的功能来欺骗系统op_DollarDollar,但不会飞,语法检查也在呼叫站点上完成.虽然作为一个例子,这个技巧确实适用于其他(合法)运营商:

// works
let inline op_BarQmark f y = f y
let test = 
    let add x = x + 1
    add |? 12

// also works:
let inline op_Dollar f y = f y
let test = 
    let add x = seq { yield x + 1 }
    add $ 12
Run Code Online (Sandbox Code Playgroud)

kvb*_*kvb 5

F# 规范在这一点上存在一些不一致。F# 规范第 3.7 节将符号运算符定义为

\n\n
\n
regexp first-op-char = !%&*+-./<=>@^|~ \nregexp op-char       = first-op-char | ? \n\ntoken quote-op-left  =\n    |  <@ <@@  \n\ntoken quote-op-right  =\n    |  @> @@>  \n\ntoken symbolic-op  =\n    | ?\n    | ?<-\n    | first-op-char op-char*\n    | quote-op-left\n    | quote-op-right\n
Run Code Online (Sandbox Code Playgroud)\n
\n\n

(并且$在第 3.6 节中也没有作为符号关键字出现),这表明编译器接受作为( $ )运算符是错误的。

\n\n

然而,第 4.4 节(涵盖运算符优先级)包含以下定义:

\n\n
\n
infix-or-prefix-op :=\n    +,  -, +., -., %, &, && \n\nprefix-op :=\n    infix-or-prefix-op\n    ~ ~~ ~~~             (and any repetitions of ~)\n    !OP                  (except !=) \n\ninfix-op :=\n    infix-or-prefix-op  \n    -OP +OP || <OP >OP = |OP &OP ^OP *OP /OP %OP !=  \n                         (or any of these preceded by one or more \xe2\x80\x98.\xe2\x80\x99) \n    := \n    :: \n    $ \n    or \n    ?\n
Run Code Online (Sandbox Code Playgroud)\n
\n\n

并且下面的优先级和结合性表确实包含$(但没有任何指示$可以在任何更长的符号运算符中显示为一个字符)。考虑提交一个错误,以便可以以某种方式使规范保持一致。

\n