FSharp.Core


ExtraTopLevelOperators Module

A set of extra operators and functions. This module is automatically opened in all F# code.

Nested modules

Modules Description

Checked

Functions and values

Function or value Description

(~%) expression

Full Usage: (~%) expression

Parameters:
    expression : Expr<'T>

Returns: 'T

Special prefix operator for splicing typed expressions into quotation holes.

expression : Expr<'T>
Returns: 'T
Example

 let f v = <@ %v + %v @>

 f <@ 5 + 5 @>;;
Evaluates to a quotation equivalent to <@ (5 + 5) + (5 + 5) @>

(~%%) expression

Full Usage: (~%%) expression

Parameters:
Returns: 'T

Special prefix operator for splicing untyped expressions into quotation holes.

expression : Expr
Returns: 'T
Example

 let f v = <@@ (%%v: int) + (%%v: int) @@>

 f <@@ 5 + 5 @@>;;
Evaluates to an untyped quotation equivalent to <@@ (5 + 5) + (5 + 5) @@>

array2D rows

Full Usage: array2D rows

Parameters:
    rows : seq<'a>

Returns: 'T[,]

Builds a 2D array from a sequence of sequences of elements.

rows : seq<'a>
Returns: 'T[,]
Example

 array2D [ [ 1.0; 2.0 ]; [ 3.0; 4.0 ] ]
Evaluates to a 2x2 zero-based array with contents [[1.0; 2.0]; [3.0; 4.0]]

async

Full Usage: async

Returns: AsyncBuilder

Builds an asynchronous workflow using computation expression syntax.

Returns: AsyncBuilder
Example

 let sleepExample() =
     async {
         printfn "sleeping"
         do! Async.Sleep 10
         printfn "waking up"
         return 6
      }

 sleepExample() |> Async.RunSynchronously

dict keyValuePairs

Full Usage: dict keyValuePairs

Parameters:
    keyValuePairs : seq<'Key * 'Value>

Returns: IDictionary<'Key, 'Value>

Builds a read-only lookup table from a sequence of key/value pairs. The key objects are indexed using generic hashing and equality.

keyValuePairs : seq<'Key * 'Value>
Returns: IDictionary<'Key, 'Value>
Example

 let table = dict [ (1, 100); (2, 200) ]

 table[1]
Evaluates to 100.

Example

 let table = dict [ (1, 100); (2, 200) ]

 table[3]
Throws System.Collections.Generic.KeyNotFoundException.

double value

Full Usage: double value

Parameters:
    value : ^T

Returns: double
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 Double.Parse() with InvariantCulture settings. Otherwise the operation requires and invokes a ToDouble method on the input type.

value : ^T
Returns: double
Example

 double 45
Evaluates to 45.0.

Example

 double 12.3f
Evaluates to 12.30000019.

eprintf format

Full Usage: eprintf format

Parameters:
Returns: 'T The formatted result.

Print to stderr using the given format.

format : TextWriterFormat<'T>

The formatter.

Returns: 'T

The formatted result.

Example

See Printf.eprintf (link: Printf.PrintFormatToError) for examples.

eprintfn format

Full Usage: eprintfn format

Parameters:
Returns: 'T The formatted result.

Print to stderr using the given format, and add a newline.

format : TextWriterFormat<'T>

The formatter.

Returns: 'T

The formatted result.

Example

See Printf.eprintfn (link: Printf.PrintFormatLineToError) for examples.

failwithf format

Full Usage: failwithf format

Parameters:
Returns: 'T The formatted result.

Print to a string buffer and raise an exception with the given result. Helper printers must return strings.

format : StringFormat<'T, 'Result>

The formatter.

Returns: 'T

The formatted result.

Example

See Printf.failwithf (link: Printf.PrintFormatToStringThenFail) for examples.

fprintf textWriter format

Full Usage: fprintf textWriter format

Parameters:
Returns: 'T The formatted result.

Print to a file using the given format.

textWriter : TextWriter

The file TextWriter.

format : TextWriterFormat<'T>

The formatter.

Returns: 'T

The formatted result.

Example

See Printf.fprintf (link: Printf.PrintFormatToTextWriter) for examples.

fprintfn textWriter format

Full Usage: fprintfn textWriter format

Parameters:
Returns: 'T The formatted result.

Print to a file using the given format, and add a newline.

textWriter : TextWriter

The file TextWriter.

format : TextWriterFormat<'T>

The formatter.

Returns: 'T

The formatted result.

Example

See Printf.fprintfn (link: Printf.PrintFormatLineToTextWriter) for examples.

int8 value

Full Usage: int8 value

Parameters:
    value : ^T

Returns: int8
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 SByte.Parse() with InvariantCulture settings. Otherwise the operation requires and invokes a ToSByte method on the input type.

value : ^T
Returns: int8
Example

 int8 -12
Evaluates to -12y.

Example

 int8 "3"
Evaluates to 3y.

printf format

Full Usage: printf format

Parameters:
Returns: 'T The formatted result.

Print to stdout using the given format.

format : TextWriterFormat<'T>

The formatter.

Returns: 'T

The formatted result.

Example

See Printf.printf (link: Printf.PrintFormat) for examples.

printfn format

Full Usage: printfn format

Parameters:
Returns: 'T The formatted result.

Print to stdout using the given format, and add a newline.

format : TextWriterFormat<'T>

The formatter.

Returns: 'T

The formatted result.

Example

See Printf.printfn (link: Printf.PrintFormatLine) for examples.

query

Full Usage: query

Returns: QueryBuilder

Builds a query using query syntax and operators.

Returns: QueryBuilder
Example

 let findEvensAndSortAndDouble(xs: System.Linq.IQueryable<int>) =
     query {
         for x in xs do
         where (x % 2 = 0)
         sortBy x
         select (x+x)
      }

 let data = [1; 2; 6; 7; 3; 6; 2; 1]

 findEvensAndSortAndDouble (data.AsQueryable()) |> Seq.toList
Evaluates to [4; 4; 12; 12].

readOnlyDict keyValuePairs

Full Usage: readOnlyDict keyValuePairs

Parameters:
    keyValuePairs : seq<'Key * 'Value>

Returns: IReadOnlyDictionary<'Key, 'Value>

Builds a read-only lookup table from a sequence of key/value pairs. The key objects are indexed using generic hashing and equality.

keyValuePairs : seq<'Key * 'Value>
Returns: IReadOnlyDictionary<'Key, 'Value>
Example

 let table = readOnlyDict [ (1, 100); (2, 200) ]

 table[1]
Evaluates to 100.

Example

 let table = readOnlyDict [ (1, 100); (2, 200) ]

 table[3]
Throws System.Collections.Generic.KeyNotFoundException.

set elements

Full Usage: set elements

Parameters:
    elements : seq<'T> - The input sequence of elements.

Returns: Set<'T> The created set.

Builds a set from a sequence of objects. The objects are indexed using generic comparison.

elements : seq<'T>

The input sequence of elements.

Returns: Set<'T>

The created set.

Example

 let values = set [ 1; 2; 3; 5; 7; 11 ]
Evaluates to a set containing the given numbers.

single value

Full Usage: single value

Parameters:
    value : ^T

Returns: single
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 Single.Parse() with InvariantCulture settings. Otherwise the operation requires and invokes a ToSingle method on the input type.

value : ^T
Returns: single
Example

 single 45
Evaluates to 45.0f.

sprintf format

Full Usage: sprintf format

Parameters:
Returns: 'T The formatted result.

Print to a string using the given format.

format : StringFormat<'T>

The formatter.

Returns: 'T

The formatted result.

Example

See Printf.sprintf (link: Printf.PrintFormatToStringThen) for examples.

uint8 value

Full Usage: uint8 value

Parameters:
    value : ^T

Returns: uint8
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 Byte.Parse() on strings and otherwise requires a ToByte method on the input type.

value : ^T
Returns: uint8
Example

 uint8 12
Evaluates to 12uy.

Active patterns

Active pattern Description

(|Lazy|) input

Full Usage: (|Lazy|) input

Parameters:
Returns: 'T

An active pattern to force the execution of values of type Lazy<_>.

input : Lazy<'T>
Returns: 'T
Example

 let f (Lazy v) = v + v

 let v = lazy (printf "eval!"; 5+5)

 f v
 f v
Evaluates to 10. The text eval! is printed once on the first invocation of f.