Basic F# Operators. This module is automatically opened in all F# code.
Modules | Description |
Function or value | Description |
Full Usage:
x ** y
Parameters:
^T
-
The input base.
y : ^U
-
The input exponent.
Returns: ^T
The base raised to the exponent.
Modifiers: inline Type parameters: ^T, ^U |
Example
|
Example
let count = ref 12 // Creates a reference cell object with a mutable Value property count.Value // Evaluates to 12 !count // Also evaluates to 12 (with shorter syntax) |
|
Full Usage:
x % y
Parameters:
^T1
-
The first parameter.
y : ^T2
-
The second parameter.
Returns: ^T3
The result of the operation.
Modifiers: inline Type parameters: ^T1, ^T2, ^T3 |
Example
29 % 5 // Evaluates to 4 |
Full Usage:
x &&& y
Parameters:
^T
-
The first parameter.
y : ^T
-
The second parameter.
Returns: ^T
The result of the operation.
Modifiers: inline Type parameters: ^T |
Example
let a = 13 // 00000000000000000000000000001101 let b = 11 // 00000000000000000000000000001011 let c = a &&& b // 00000000000000000000000000001001Evaluates to 9 |
Full Usage:
x * y
Parameters:
^T1
-
The first parameter.
y : ^T2
-
The second parameter.
Returns: ^T3
The result of the operation.
Modifiers: inline Type parameters: ^T1, ^T2, ^T3 |
Example
8 * 6 // Evaluates to 48 |
Full Usage:
x + y
Parameters:
^T1
-
The first parameter.
y : ^T2
-
The second parameter.
Returns: ^T3
The result of the operation.
Modifiers: inline Type parameters: ^T1, ^T2, ^T3 |
Example
2 + 2 // Evaluates to 4 "Hello " + "Word" // Evaluates to "Hello World" |
Full Usage:
x - y
Parameters:
^T1
-
The first parameter.
y : ^T2
-
The second parameter.
Returns: ^T3
The result of the operation.
Modifiers: inline Type parameters: ^T1, ^T2, ^T3 |
Example
10 - 2 // Evaluates to 8 |
Full Usage:
(....) start step finish
Parameters:
^T
-
The start value of the range.
step : ^Step
-
The step value of the range.
finish : ^T
-
The end value of the range.
Returns: seq<^T>
The sequence spanning the range using the specified step size.
Modifiers: inline Type parameters: ^T, ^Step |
![]() ![]() ![]() ![]() ![]() ![]()
The standard overloaded skip range operator, e.g.
Example
[1..2..6] // Evaluates to [1; 3; 5] [1.1..0.2..1.5] // Evaluates to [1.1; 1.3; 1.5] ['a'..'e'] // Evaluates to ['a'; 'b'; 'c'; 'd'; 'e'] |
Full Usage:
start .. finish
Parameters:
^T
-
The start value of the range.
finish : ^T
-
The end value of the range.
Returns: seq<^T>
The sequence spanning the range.
Modifiers: inline Type parameters: ^T |
Example
[1..4] // Evaluates to [1; 2; 3; 4] [1.5..4.4] // Evaluates to [1.5; 2.5; 3.5] ['a'..'d'] // Evaluates to ['a'; 'b'; 'c'; 'd'] [|1..4|] // Evaluates to an array [|1; 2; 3; 4|] { 1..4 } // Evaluates to a sequence [1; 2; 3; 4]) |
Full Usage:
x / y
Parameters:
^T1
-
The first parameter.
y : ^T2
-
The second parameter.
Returns: ^T3
The result of the operation.
Modifiers: inline Type parameters: ^T1, ^T2, ^T3 |
Example
16 / 2 // Evaluates to 8 |
Full Usage:
cell := value
Parameters:
'T ref
-
The cell to mutate.
value : 'T
-
The value to set inside the cell.
|
Example
let count = ref 0 // Creates a reference cell object with a mutable Value property count.Value <- 1 // Updates the value count := 2 // Also updates the value, but with shorter syntax count.Value // Evaluates to 2 |
Example
1 < 5 // Evaluates to true 5 < 5 // Evaluates to false (1, "a") < (1, "z") // Evaluates to true |
|
Full Usage:
func2 << func1
Parameters:
'T2 -> 'T3
-
The second function to apply.
func1 : 'T1 -> 'T2
-
The first function to apply.
Returns: 'T1 -> 'T3
The composition of the input functions.
Modifiers: inline Type parameters: 'T2, 'T3, 'T1 |
Example
let addOne x = x + 1 let doubleIt x = x * 2 let doubleThenAdd = addOne << doubleIt doubleThenAdd 3 |
Full Usage:
value <<< shift
Parameters:
^T
-
The input value.
shift : int32
-
The amount to shift.
Returns: ^T
The result of the operation.
Modifiers: inline Type parameters: ^T |
Example
let a = 13 // 00000000000000000000000000001101 let c = a <<< 4 // 00000000000000000000000011010000Evaluates to 208 |
Example
5 <= 1 // Evaluates to false 5 <= 5 // Evaluates to true [1; 5] <= [1; 6] // Evaluates to true |
|
Example
5 <> 5 // Evaluates to false 5 <> 6 // Evaluates to true [1; 2] <> [1; 2] // Evaluates to false |
|
Full Usage:
func <| arg1
Parameters:
'T -> 'U
-
The function.
arg1 : 'T
-
The argument.
Returns: 'U
The function result.
Modifiers: inline Type parameters: 'T, 'U |
Example
let doubleIt x = x * 2 doubleIt <| 3 // Evaluates to 6 |
Full Usage:
func <|| (arg1, arg2)
Parameters:
'T1 -> 'T2 -> 'U
-
The function.
arg1 : 'T1
-
The first argument.
arg2 : 'T2
-
The second argument.
Returns: 'U
The function result.
Modifiers: inline Type parameters: 'T1, 'T2, 'U |
Example
let sum x y = x + y sum <|| (3, 4) // Evaluates to 7 |
Full Usage:
func <||| (arg1, arg2, arg3)
Parameters:
'T1 -> 'T2 -> 'T3 -> 'U
-
The function.
arg1 : 'T1
-
The first argument.
arg2 : 'T2
-
The second argument.
arg3 : 'T3
-
The third argument.
Returns: 'U
The function result.
Modifiers: inline Type parameters: 'T1, 'T2, 'T3, 'U |
Example
let sum3 x y z = x + y + z sum3 <||| (3, 4, 5) // Evaluates to 12 |
Example
5 = 5 // Evaluates to true 5 = 6 // Evaluates to false [1; 2] = [1; 2] // Evaluates to true (1, 5) = (1, 6) // Evaluates to false |
|
Example
5 > 1 // Evaluates to true 5 > 5 // Evaluates to false (1, "a") > (1, "z") // Evaluates to false |
|
Example
5 >= 1 // Evaluates to true 5 >= 5 // Evaluates to true [1; 5] >= [1; 6] // Evaluates to false |
|
Full Usage:
func1 >> func2
Parameters:
'T1 -> 'T2
-
The first function to apply.
func2 : 'T2 -> 'T3
-
The second function to apply.
Returns: 'T1 -> 'T3
The composition of the input functions.
Modifiers: inline Type parameters: 'T1, 'T2, 'T3 |
Example
let addOne x = x + 1 let doubleIt x = x * 2 let addThenDouble = addOne >> doubleIt addThenDouble 3 // Evaluates to 8 |
Full Usage:
value >>> shift
Parameters:
^T
-
The input value.
shift : int32
-
The amount to shift.
Returns: ^T
The result of the operation.
Modifiers: inline Type parameters: ^T |
Example
let a = 206 // 00000000000000000000000011010000 let c1 = a >>> 2 // 00000000000000000000000000110100 // Evaluates to 51 let c2 = a >>> 6 // 00000000000000000000000000000011 Evaluates to 3 |
|
Example
let l1 = ['a'; 'b'; 'c'] let l2 = ['d'; 'e'; 'f'] l1 @ l2 // Evalulates to ['a'; 'b'; 'c'; 'd'; 'e'; 'f'] |
|
|
Full Usage:
x ^^^ y
Parameters:
^T
-
The first parameter.
y : ^T
-
The second parameter.
Returns: ^T
The result of the operation.
Modifiers: inline Type parameters: ^T |
Example
let a = 13 // 00000000000000000000000000001101 let b = 11 // 00000000000000000000000000001011 let c = a ^^^ b // 00000000000000000000000000000110Evaluates to 6 |
Full Usage:
arg |> func
Parameters:
'T1
-
The argument.
func : 'T1 -> 'U
-
The function.
Returns: 'U
The function result.
Modifiers: inline Type parameters: 'T1, 'U |
Example
let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6 |
Full Usage:
(arg1, arg2) ||> func
Parameters:
'T1
-
The first argument.
arg2 : 'T2
-
The second argument.
func : 'T1 -> 'T2 -> 'U
-
The function.
Returns: 'U
The function result.
Modifiers: inline Type parameters: 'T1, 'T2, 'U |
Example
let sum x y = x + y (3, 4) ||> sum // Evaluates to 7 |
Full Usage:
x ||| y
Parameters:
^T
-
The first parameter.
y : ^T
-
The second parameter.
Returns: ^T
The result of the operation.
Modifiers: inline Type parameters: ^T |
Example
let a = 13 // 00000000000000000000000000001101 let b = 11 // 00000000000000000000000000001011 let c = a ||| b // 00000000000000000000000000001111Evaluates to 15 |
Full Usage:
(arg1, arg2, arg3) |||> func
Parameters:
'T1
-
The first argument.
arg2 : 'T2
-
The second argument.
arg3 : 'T3
-
The third argument.
func : 'T1 -> 'T2 -> 'T3 -> 'U
-
The function.
Returns: 'U
The function result.
Modifiers: inline Type parameters: 'T1, 'T2, 'T3, 'U |
Example
let sum3 x y z = x + y + z (3, 4, 5) |||> sum3 // Evaluates to 12 |
Full Usage:
~+value
Parameters:
^T
-
The input value.
Returns: ^T
The result of the operation.
Modifiers: inline Type parameters: ^T |
|
Full Usage:
~-n
Parameters:
^T
-
The value to negate.
Returns: ^T
The result of the operation.
Modifiers: inline Type parameters: ^T |
|
Full Usage:
~~~value
Parameters:
^T
-
The input value.
Returns: ^T
The result of the operation.
Modifiers: inline Type parameters: ^T |
Example
let byte1 = 60uy // 00111100 let byte2 = ~~~b1 // 11000011Evaluates to 195 |
|
Example
let throwException() = raise(Failure("Oh no!!!")) true // Never gets here throwException() // Throws a generic Exception class |
|
Example
not (2 + 2 = 5) // Evaluates to true // not is a function that can be compose with other functions let fileDoesNotExist = System.IO.File.Exists >> not |
Full Usage:
abs value
Parameters:
^T
-
The input value.
Returns: ^T
The absolute value of the input.
Modifiers: inline Type parameters: ^T |
Example
abs -12 // Evaluates to 12 abs -15.0 // Evaluates to 15.0 |
Full Usage:
acos value
Parameters:
^T
-
The input value.
Returns: ^T
The inverse cosine of the input.
Modifiers: inline Type parameters: ^T |
Example
let angleFromAdjacent adjacent hypotenuse = acos(adjacent / hypotenuse) angleFromAdjacent 8.0 10.0 // Evaluates to 0.6435011088 |
Full Usage:
asin value
Parameters:
^T
-
The input value.
Returns: ^T
The inverse sine of the input.
Modifiers: inline Type parameters: ^T |
Example
let angleFromOpposite opposite hypotenuse = asin(opposite / hypotenuse) angleFromOpposite 6.0 10.0 // Evaluates to 0.6435011088 angleFromOpposite 5.0 3.0 // Evaluates to nan |
Full Usage:
atan value
Parameters:
^T
-
The input value.
Returns: ^T
The inverse tangent of the input.
Modifiers: inline Type parameters: ^T |
Example
let angleFrom opposite adjacent = atan(opposite / adjacent) angleFrom 5.0 5.0 // Evaluates to 0.7853981634 |
Full Usage:
atan2 y x
Parameters:
^T1
-
The y input value.
x : ^T1
-
The x input value.
Returns: 'T2
The inverse tangent of the input ratio.
Modifiers: inline Type parameters: ^T1, 'T2 |
Example
let angleFromPlaneAtXY x y = atan2 y x * 180.0 / System.Math.PI angleFromPlaneAtXY 0.0 -1.0 // Evaluates to -90.0 angleFromPlaneAtXY 1.0 1.0 // Evaluates to 45.0 angleFromPlaneAtXY -1.0 1.0 // Evaluates to 135.0 |
Example
let x: int = 123 let obj1 = box x // obj1 is a generic object type unbox<int> obj1 // Evaluates to 123 (int) unbox<double> obj1 // Throws System.InvalidCastException |
|
Full Usage:
byte value
Parameters:
^T
-
The input value.
Returns: byte
The converted byte
Modifiers: inline Type parameters: ^T |
![]() ![]() ![]() ![]() ![]() ![]()
Converts the argument to byte. This is a direct conversion for all
primitive numeric types. For strings, the input is converted using
Example
|
Full Usage:
ceil value
Parameters:
^T
-
The input value.
Returns: ^T
The ceiling of the input.
Modifiers: inline Type parameters: ^T |
Example
ceil 12.1 // Evaluates to 13.0 ceil -1.9 // Evaluates to -1.0 |
Full Usage:
char value
Parameters:
^T
-
The input value.
Returns: char
The converted char.
Modifiers: inline Type parameters: ^T |
![]() ![]() ![]() ![]() ![]() ![]() Converts the argument to character. Numeric inputs are converted according to the UTF-16 encoding for characters. String inputs must be exactly one character long. For other input types the operation requires an appropriate static conversion method on the input type.
Example
|
Full Usage:
compare e1 e2
Parameters:
'T
-
The first value.
e2 : 'T
-
The second value.
Returns: int
The result of the comparison.
Modifiers: inline Type parameters: 'T |
Example
compare 1 2 // Evaluates to -1 compare [1;2;3] [1;2;4] // Evaluates to -1 compare 2 2 // Evaluates to 0 compare [1;2;3] [1;2;3] // Evaluates to 0 compare 2 1 // Evaluates to 1 compare [1;2;4] [1;2;3] // Evaluates to 1 |
Full Usage:
cos value
Parameters:
^T
-
The input value.
Returns: ^T
The cosine of the input.
Modifiers: inline Type parameters: ^T |
Example
|
Full Usage:
cosh value
Parameters:
^T
-
The input value.
Returns: ^T
The hyperbolic cosine of the input.
Modifiers: inline Type parameters: ^T |
Example
|
Full Usage:
decimal value
Parameters:
^T
-
The input value.
Returns: decimal
The converted decimal.
Modifiers: inline Type parameters: ^T |
![]() ![]() ![]() ![]() ![]() ![]()
Converts the argument to System.Decimal using a direct conversion for all
primitive numeric types. For strings, the input is converted using
Example
|
Example
let count = ref 99 // Creates a reference cell object with a mutable Value property decr count // Decrements our counter count.Value // Evaluates to 98 |
|
Full Usage:
defaultArg arg defaultValue
Parameters:
'T option
-
An option representing the argument.
defaultValue : 'T
-
The default value of the argument.
Returns: 'T
The argument value. If it is None, the defaultValue is returned.
|
Example
type Vector(x: double, y: double, ?z: double) = let z = defaultArg z 0.0 member this.X = x member this.Y = y member this.Z = z let v1 = Vector(1.0, 2.0) v1.Z // Evaluates to 0. let v2 = Vector(1.0, 2.0, 3.0) v2.Z // Evaluates to 3.0 |
Full Usage:
defaultValueArg arg defaultValue
Parameters:
'T voption
-
A value option representing the argument.
defaultValue : 'T
-
The default value of the argument.
Returns: 'T
The argument value. If it is None, the defaultValue is returned.
|
Example
let arg1 = ValueSome(5) defaultValueArg arg1 6 // Evaluates to 5 defaultValueArg ValueNone 6 // Evaluates to 6 |
Full Usage:
enum value
Parameters:
int32
-
The input value.
Returns: ^U
The converted enum type.
Modifiers: inline Type parameters: ^U |
Example
|
Full Usage:
exit exitcode
Parameters:
int
-
The exit code to use.
Returns: 'T
Never returns.
|
![]() ![]() ![]() ![]() ![]() ![]() Exit the current hardware isolated process, if security settings permit, otherwise raise an exception. Calls Environment.Exit.
Example
[<EntryPoint>] let main argv = if argv.Length = 0 then eprintfn "You must provide arguments" exit(-1) // Causes program to quit with an error code printfn "Argument count: %i" argv.Length 0 |
Full Usage:
exp value
Parameters:
^T
-
The input value.
Returns: ^T
The exponential of the input.
Modifiers: inline Type parameters: ^T |
Example
exp 0.0 // Evaluates to 1.0 exp 1.0 // Evaluates to 2.718281828 exp -1.0 // Evaluates to 0.3678794412 exp 2.0 // Evaluates to 7.389056099 |
Full Usage:
failwith message
Parameters:
string
-
The exception message.
Returns: 'T
Never returns.
Modifiers: inline Type parameters: 'T |
Example
let failingFunction() = failwith "Oh no" // Throws an exception true // Never reaches this failingFunction() // Throws a System.Exception |
Full Usage:
float value
Parameters:
^T
-
The input value.
Returns: float
The converted float
Modifiers: inline Type parameters: ^T |
![]() ![]() ![]() ![]() ![]() ![]()
Converts the argument to 64-bit float. This is a direct conversion for all
primitive numeric types. For strings, the input is converted using
Example
|
Full Usage:
float32 value
Parameters:
^T
-
The input value.
Returns: float32
The converted float32
Modifiers: inline Type parameters: ^T |
![]() ![]() ![]() ![]() ![]() ![]()
Converts the argument to 32-bit float. This is a direct conversion for all
primitive numeric types. For strings, the input is converted using
Example
|
Full Usage:
floor value
Parameters:
^T
-
The input value.
Returns: ^T
The floor of the input.
Modifiers: inline Type parameters: ^T |
Example
floor 12.1 // Evaluates to 12.0 floor -1.9 // Evaluates to -2.0 |
Full Usage:
fst tuple
Parameters:
'T1 * 'T2
-
The input tuple.
Returns: 'T1
The first value.
Modifiers: inline Type parameters: 'T1, 'T2 |
Example
fst ("first", 2) // Evaluates to "first" |
![]() ![]() ![]() ![]() ![]() ![]() A generic hash function, designed to return equal hash values for items that are equal according to the "=" operator. By default it will use structural hashing for F# union, record and tuple types, hashing the complete contents of the type. The exact behaviour of the function can be adjusted on a type-by-type basis by implementing GetHashCode for each type.
Example
hash "Bob Jones" // Evaluates to -325251320 |
|
Full Usage:
id x
Parameters:
'T
-
The input value.
Returns: 'T
The same value.
|
Example
id 12 // Evaulates to 12 id "abc" // Evaulates to "abc" |
Full Usage:
ignore value
Parameters:
'T
-
The value to ignore.
Modifiers: inline Type parameters: 'T |
Example
ignore 55555 // Evaluates to () |
Example
let count = ref 99 // Creates a reference cell object with a mutable Value property incr count // Increments our counter count.Value // Evaluates to 100 |
|
|
|
|
|
![]() ![]() ![]() ![]() ![]() ![]()
Converts the argument to signed 32-bit integer. This is a direct conversion for all
primitive numeric types. For strings, the input is converted using
Example
|
|
Full Usage:
int16 value
Parameters:
^T
-
The input value.
Returns: int16
The converted int16
Modifiers: inline Type parameters: ^T |
![]() ![]() ![]() ![]() ![]() ![]()
Converts the argument to signed 16-bit integer. This is a direct conversion for all
primitive numeric types. For strings, the input is converted using
Example
|
Full Usage:
int32 value
Parameters:
^T
-
The input value.
Returns: int32
The converted int32
Modifiers: inline Type parameters: ^T |
![]() ![]() ![]() ![]() ![]() ![]()
Converts the argument to signed 32-bit integer. This is a direct conversion for all
primitive numeric types. For strings, the input is converted using
Example
|
Full Usage:
int64 value
Parameters:
^T
-
The input value.
Returns: int64
The converted int64
Modifiers: inline Type parameters: ^T |
![]() ![]() ![]() ![]() ![]() ![]()
Converts the argument to signed 64-bit integer. This is a direct conversion for all
primitive numeric types. For strings, the input is converted using
Example
|
|
Example
let fullName firstName lastName = if String.IsNullOrWhiteSpace(firstName) then invalidArg (nameof(firstName)) "First name can't be null or blank" if String.IsNullOrWhiteSpace(lastName) then invalidArg (nameof(lastName)) "Last name can't be null or blank" firstName + " " + lastName fullName null "Jones"Throws System.ArgumentException: First name can't be null or blank (Parameter 'firstName')
|
Full Usage:
invalidOp message
Parameters:
string
-
The exception message.
Returns: 'T
The result value.
Modifiers: inline Type parameters: 'T |
Example
type FileReader(fileName: string) = let mutable isOpen = false member this.Open() = if isOpen then invalidOp "File is already open" // ... Here we may open the file ... isOpen <- true let reader = FileReader("journal.txt") reader.Open() // Executes fine reader.Open() // Throws System.InvalidOperationException: File is already open |
Full Usage:
isNull value
Parameters:
'T
-
The value to check.
Returns: bool
True when value is null, false otherwise.
Modifiers: inline Type parameters: 'T |
Example
isNull null // Evaluates to true isNull "Not null" // Evaluates to false |
|
![]() ![]() ![]() ![]() ![]() ![]() A generic hash function. This function has the same behaviour as 'hash', however the default structural hashing for F# union, record and tuple types stops when the given limit of nodes is reached. The exact behaviour of the function can be adjusted on a type-by-type basis by implementing GetHashCode for each type.
|
Full Usage:
lock lockObject action
Parameters:
'Lock
-
The object to be locked.
action : unit -> 'T
-
The action to perform during the lock.
Returns: 'T
The resulting value.
Modifiers: inline Type parameters: 'Lock, 'T |
Example
open System.Linq /// A counter object, supporting unlocked and locked increment type TestCounter () = let mutable count = 0 /// Increment the counter, unlocked member this.IncrementWithoutLock() = count <- count + 1 /// Increment the counter, locked member this.IncrementWithLock() = lock this (fun () -> count <- count + 1) /// Get the count member this.Count = count let counter = TestCounter() // Create a parallel sequence to that uses all our CPUs (seq {1..100000}).AsParallel() .ForAll(fun _ -> counter.IncrementWithoutLock()) // Evaluates to a number between 1-100000, non-deterministically because there is no locking counter.Count let counter2 = TestCounter() // Create a parallel sequence to that uses all our CPUs (seq {1..100000}).AsParallel() .ForAll(fun _ -> counter2.IncrementWithLock()) // Evaluates to 100000 deterministically because the increment to the counter object is locked counter2.Count |
Full Usage:
log value
Parameters:
^T
-
The input value.
Returns: ^T
The natural logarithm of the input.
Modifiers: inline Type parameters: ^T |
Example
let logBase baseNumber value = (log value) / (log baseNumber) logBase 2.0 32.0 // Evaluates to 5.0 logBase 10.0 1000.0 // Evaluates to 3.0 |
Full Usage:
log10 value
Parameters:
^T
-
The input value.
Returns: ^T
The logarithm to base 10 of the input.
Modifiers: inline Type parameters: ^T |
Example
log10 1000.0 // Evaluates to 3.0 log10 100000.0 // Evaluates to 5.0 log10 0.0001 // Evaluates to -4.0 log10 -20.0 // Evaluates to nan |
Full Usage:
max e1 e2
Parameters:
'T
-
The first value.
e2 : 'T
-
The second value.
Returns: 'T
The maximum value.
Modifiers: inline Type parameters: 'T |
Example
max 1 2 // Evaluates to 2 max [1;2;3] [1;2;4] // Evaluates to [1;2;4] max "zoo" "alpha" // Evaluates to "zoo" |
|
|
Full Usage:
min e1 e2
Parameters:
'T
-
The first value.
e2 : 'T
-
The second value.
Returns: 'T
The minimum value.
Modifiers: inline Type parameters: 'T |
Example
min 1 2 // Evaluates to 1 min [1;2;3] [1;2;4] // Evaluates to [1;2;3] min "zoo" "alpha" // Evaluates to "alpha" |
|
Example
let myVariableName = "This value doesn't matter" nameof(myVariableName) // Evaluates to "myVariableName" |
|
|
|
|
Full Usage:
nativeint value
Parameters:
^T
-
The input value.
Returns: nativeint
The converted nativeint
Modifiers: inline Type parameters: ^T |
![]() ![]() ![]() ![]() ![]() ![]() Converts the argument to signed native integer. This is a direct conversion for all primitive numeric types. Otherwise the operation requires an appropriate static conversion method on the input type.
Example
|
Full Usage:
nullArg argumentName
Parameters:
string
-
The argument name.
Returns: 'T
Never returns.
Modifiers: inline Type parameters: 'T |
Example
let fullName firstName lastName = nullArg (nameof(firstName)) nullArg (nameof(lastName)) firstName + " " + lastName fullName null "Jones" // Throws System.ArgumentNullException: Value cannot be null. (Parameter 'firstName') |
Example
|
|
Example
open System.IO exception FileNotFoundException of string let readFile (fileName: string) = if not (File.Exists(fileName)) then raise(FileNotFoundException(fileName)) File.ReadAllText(fileName) readFile "/this-file-doest-exist"When executed, raises a FileNotFoundException .
|
|
Example
let count = ref 0 // Creates a reference cell object with a mutable Value property count.Value // Evaluates to 0 count.Value <- 1 // Updates the value count.Value // Evaluates to 1 |
|
Full Usage:
reraise ()
Parameters:
unit
Returns: 'T
The result value.
Modifiers: inline Type parameters: 'T |
Example
let readFile (fileName: string) = try File.ReadAllText(fileName) with ex -> eprintfn "Couldn't read %s" fileName reraise() readFile "/this-file-doest-exist" // Prints the message to stderr // Throws a System.IO.FileNotFoundException |
Full Usage:
round value
Parameters:
^T
-
The input value.
Returns: ^T
The nearest integer to the input value.
Modifiers: inline Type parameters: ^T |
Example
round 3.49 // Evaluates to 3.0 round -3.49 // Evaluates to -3.0 round 3.5 // Evaluates to 4.0 round -3.5 // Evaluates to -4.0 |
Full Usage:
sbyte value
Parameters:
^T
-
The input value.
Returns: sbyte
The converted sbyte
Modifiers: inline Type parameters: ^T |
![]() ![]() ![]() ![]() ![]() ![]()
Converts the argument to signed byte. This is a direct conversion for all
primitive numeric types. For strings, the input is converted using
Example
|
|
Example
seq { for i in 0..10 do yield (i, i*i) } |
Full Usage:
sign value
Parameters:
^T
-
The input value.
Returns: int
-1, 0, or 1 depending on the sign of the input.
Modifiers: inline Type parameters: ^T |
Example
sign -12.0 // Evaluates to -1 sign 43 // Evaluates to 1 |
Full Usage:
sin value
Parameters:
^T
-
The input value.
Returns: ^T
The sine of the input.
Modifiers: inline Type parameters: ^T |
Example
|
Full Usage:
sinh value
Parameters:
^T
-
The input value.
Returns: ^T
The hyperbolic sine of the input.
Modifiers: inline Type parameters: ^T |
Example
|
Example
sizeof<bool> // Evaluates to 1 sizeof<byte> // Evaluates to 1 sizeof<int> // Evaluates to 4 sizeof<double> // Evaluates to 8 sizeof<struct(byte * byte)> // Evaluates to 2 sizeof<nativeint> // Evaluates to 4 or 8 (32-bit or 64-bit) depending on your platform |
|
Full Usage:
snd tuple
Parameters:
'T1 * 'T2
-
The input tuple.
Returns: 'T2
The second value.
Modifiers: inline Type parameters: 'T1, 'T2 |
Example
snd ("first", 2) // Evaluates to 2 |
Full Usage:
sqrt value
Parameters:
^T
-
The input value.
Returns: ^U
The square root of the input.
Modifiers: inline Type parameters: ^T, ^U |
Example
sqrt 2.0 // Evaluates to 1.414213562 sqrt 100.0 // Evaluates to 10.0 |
|
|
|
|
|
|
Full Usage:
string value
Parameters:
'T
-
The input value.
Returns: string
The converted string.
Modifiers: inline Type parameters: 'T |
For standard integer and floating point values the and any type that implements
Example
|
Full Usage:
tan value
Parameters:
^T
-
The input value.
Returns: ^T
The tangent of the input.
Modifiers: inline Type parameters: ^T |
Example
|
Full Usage:
tanh value
Parameters:
^T
-
The input value.
Returns: ^T
The hyperbolic tangent of the input.
Modifiers: inline Type parameters: ^T |
Example
|
Full Usage:
truncate value
Parameters:
^T
-
The input value.
Returns: ^T
The truncated value.
Modifiers: inline Type parameters: ^T |
Example
|
|
Example
let x: int = 123 let obj1 = box x // obj1 is a generic object type tryUnbox<int> obj1 // Evaluates to Some(123) tryUnbox<double> obj1 // Evaluates to None |
![]() ![]() ![]() ![]() ![]() ![]() Generate a System.Type representation for a type definition. If the input type is a generic type instantiation then return the generic type definition associated with all such instantiations.
Example
typeof<int list;> // Evaluates to Microsoft.FSharp.Collections.FSharpList`1[System.Int32] typedefof<int list;> // Evaluates to Microsoft.FSharp.Collections.FSharpList`1[T] /// |
|
Example
let t = typeof<int> // Gets the System.Type t.FullName // Evaluates to "System.Int32" |
|
Full Usage:
uint value
Parameters:
^T
-
The input value.
Returns: uint
The converted int
Modifiers: inline Type parameters: ^T |
![]() ![]() ![]() ![]() ![]() ![]()
Converts the argument to an unsigned 32-bit integer. This is a direct conversion for all
primitive numeric types. For strings, the input is converted using
Example
|
Full Usage:
uint16 value
Parameters:
^T
-
The input value.
Returns: uint16
The converted uint16
Modifiers: inline Type parameters: ^T |
![]() ![]() ![]() ![]() ![]() ![]()
Converts the argument to unsigned 16-bit integer. This is a direct conversion for all
primitive numeric types. For strings, the input is converted using
Example
|
Full Usage:
uint32 value
Parameters:
^T
-
The input value.
Returns: uint32
The converted uint32
Modifiers: inline Type parameters: ^T |
![]() ![]() ![]() ![]() ![]() ![]()
Converts the argument to unsigned 32-bit integer. This is a direct conversion for all
primitive numeric types. For strings, the input is converted using
Example
|
Full Usage:
uint64 value
Parameters:
^T
-
The input value.
Returns: uint64
The converted uint64
Modifiers: inline Type parameters: ^T |
![]() ![]() ![]() ![]() ![]() ![]()
Converts the argument to unsigned 64-bit integer. This is a direct conversion for all
primitive numeric types. For strings, the input is converted using
Example
|
Full Usage:
unativeint value
Parameters:
^T
-
The input value.
Returns: unativeint
The converted unativeint
Modifiers: inline Type parameters: ^T |
![]() ![]() ![]() ![]() ![]() ![]() Converts the argument to unsigned native integer using a direct conversion for all primitive numeric types. Otherwise the operation requires an appropriate static conversion method on the input type.
Example
|
Full Usage:
unbox value
Parameters:
obj
-
The boxed value.
Returns: 'T
The unboxed result.
Modifiers: inline Type parameters: 'T |
Example
let x: int = 123 let obj1 = box x // obj1 is a generic object type unbox<int> obj1 // Evaluates to 123 (int) unbox<double> obj1 // Throws System.InvalidCastException |
Full Usage:
using resource action
Parameters:
'T
-
The resource to be disposed after action is called.
action : 'T -> 'U
-
The action that accepts the resource.
Returns: 'U
The resulting value.
|
![]() ![]() ![]() ![]() ![]() ![]() Clean up resources associated with the input object after the completion of the given function. Cleanup occurs even when an exception is raised by the protected code.
ExampleThe following code appends 10 lines to test.txt, then closes the StreamWriter when finished. open System.IO using (File.AppendText "test.txt") (fun writer -> for i in 1 .. 10 do writer.WriteLine("Hello World {0}", i)) |
Active pattern | Description |
|
|
Full Usage:
(|KeyValue|) keyValuePair
Parameters:
KeyValuePair<'Key, 'Value>
-
The input key/value pair.
Returns: 'Key * 'Value
A tuple containing the key and value.
|
Example
|