运算符的优先顺序
参考
The F# 1.9.6 Draft Language Specification
4.4 Precedence and Operators
右侧书写的是运算符的结合方法。
%right 右结合
%left 左结合
%nonassoc 无结合
越往下优先级越高
as %right
when %right
| %left
; %right
let %nonassoc
function, fun, match, try %nonassoc
if %nonassoc
-> %right
:= %right
, %nonassoc
or || %left
& && %left
<OP >OP $OP = |OP &OP %left
^OP %right
:: %right
:?> :? %nonassoc
-OP +OP %left
*OP /OP %OP %left
**OP %right
"f x" "lazy x" "assert x" %left
!OP ?OP ~OP -OP +OP %left
. %left
f(x) %left - high precedence application
f<types> %left - type application
|
这张表中“OP标识”与某个变量表示定义自身变量时的优先顺序与结合型(由运算符的首文字决定)。
例如
用户定义的运算符的结合性
let ( <<@ ) x y = x ** y;; //x ** y 为x的y次方
let ( ^^@ ) x y = x ** y;;
> 3. <<@ 3. <<@ 3.;;
val it : float = 19683.0
> 3. ^^@ 3. ^^@ 3.;;
val it : float = 7.625597485e+12
|