Show Example
优质
小牛编辑
132浏览
2023-12-01
下表显示了F#语言中运算符和其他表达式关键字的优先顺序,从最低优先级到最高优先级。
操作者 | 关联性 |
---|---|
as | Right |
when | Right |
| (pipe) | Left |
; | Right |
let | Non associative |
function, fun, match, try | Non associative |
if | Non associative |
→ | Right |
:= | Right |
, | Non associative |
or, || | Left |
&, && | Left |
op,=,| op,&op | Left |
&&&,|||,^^^,~~~,<<>> | Left |
^ op | Right |
:: | Right |
:?>, :? | Non associative |
- op, +op, (binary) | Left |
* op,/ op,%op | Left |
** op | Right |
f x (function application) | Left |
| (pattern match) | Right |
prefix operators (+op, -op, %, %%, &, &&, !op, ~op) | Left |
. | Left |
f(x) | Left |
f<types> | Left |
例子 (Example)
let a : int32 = 20
let b : int32 = 10
let c : int32 = 15
let d : int32 = 5
let mutable e : int32 = 0
e <- (a + b) * c/d // ( 30 * 15 )/5
printfn "Value of (a + b) * c/d is : %d" e
e <- ((a + b) * c)/d // (30 * 15 )/5
printfn "Value of ((a + b) * c)/d is : %d" e
e <- (a + b) * (c/d) // (30) * (15/5)
printfn "Value of (a + b) * (c/d) is : %d" e
e <- a + (b * c)/d // 20 + (150/5)
printfn "Value of a + (b * c)/d is : %d" e
编译并执行程序时,它会产生以下输出 -
Value of (a + b) * c/d is : 90
Value of ((a + b) * c)/d is : 90
Value of (a + b) * (c/d) is : 90
Value of a + (b * c)/d is : 50