当前位置: 首页 > 文档资料 > F# 中文教程 >

Show Example

优质
小牛编辑
132浏览
2023-12-01

下表显示了F#语言中运算符和其他表达式关键字的优先顺序,从最低优先级到最高优先级。

操作者关联性
asRight
whenRight
| (pipe)Left
;Right
letNon associative
function, fun, match, tryNon associative
ifNon associative
Right
:=Right
,Non associative
or, ||Left
&, &&Left
op,=,| op,&opLeft
&&&,|||,^^^,~~~,<<>>Left
^ opRight
::Right
:?>, :?Non associative
- op, +op, (binary)Left
* op,/ op,%opLeft
** opRight
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