Fsharp-operators-precedence
提供:Dev Guides
F#-演算子の優先順位
次の表に、F#言語の演算子およびその他の式キーワードの優先順位を、優先順位の低いものから高いものへと示します。
| Operator | Associativity |
|---|---|
| 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, &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 (PLUSop, -op, %, %%, &, &&, !op, ~op) | Left |
| . | Left |
| f(x) | Left |
| f<types> | Left |
例
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