- F# - Home
- F# - Overview
- F# - Environment Setup
- F# - Program Structure
- F# - Basic Syntax
- F# - Data Types
- F# - Variables
- F# - Operators
- F# - Decision Making
- F# - Loops
- F# - Functions
- F# - Strings
- F# - Options
- F# - Tuples
- F# - Records
- F# - Lists
- F# - Sequences
- F# - Sets
- F# - Maps
- F# - Discriminated Unions
- F# - Mutable Data
- F# - Arrays
- F# - Mutable Lists
- F# - Mutable Dictionary
- F# - Basic I/O
- F# - Generics
- F# - Delegates
- F# - Enumerations
- F# - Pattern Matching
- F# - Exception Handling
- F# - Classes
- F# - Structures
- F# - Operator Overloading
- F# - Inheritance
- F# - Interfaces
- F# - Events
- F# - Modules
- F# - Namespaces
F# - Operators Precedence
The following table shows the order of precedence of operators and other expression keywords in the F# language, from lowest precedence to the highest precedence.
| 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 (+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
When you compile and execute the program, it yields the following output −
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
fsharp_operators.htm
Advertisements