Partager via


Symbol and Operator Reference (F#)

This topic includes a table of symbols and operators that are used in the F# language.

Table of Symbols and Operators

The following table describes symbols used in the F# language, provides links to topics that provide more information, and provides a brief description of some of the uses of the symbol. Symbols are ordered according to the ASCII character set ordering.

Symbol or operator

Links

Description

!

Reference Cells (F#)

Computation Expressions (F#)

  • Dereferences a reference cell.

  • After a keyword, indicates a modified version of the keyword's behavior as controlled by a workflow.

!=

Not applicable.

  • Not used in F#. Use <> for inequality operations.

"

Literals (F#)

Strings (F#)

  • Delimits a text string.

"""

Strings (F#)

Delimits a verbatim text string. Differs from @"..." in that a you can indicate a quotation mark character by using a single quote in the string.

#

Compiler Directives (F#)

Flexible Types (F#)

  • Prefixes a preprocessor or compiler directive, such as #light.

  • When used with a type, indicates a flexible type, which refers to a type or any one of its derived types.

$

No more information available.

  • Used internally for certain compiler-generated variable and function names.

%

Arithmetic Operators (F#)

Code Quotations (F#)

  • Computes the integer modulus.

  • Used for splicing expressions into typed code quotations.

%%

Code Quotations (F#)

  • Used for splicing expressions into untyped code quotations.

%?

Nullable Operators (F#)

  1. Computes the integer modulus, when the right side is a nullable type.

&

Match Expressions (F#)

  • Computes the address of a mutable value, for use when interoperating with other languages.

  • Used in AND patterns.

&&

Boolean Operators (F#)

  • Computes the Boolean AND operation.

&&&

Bitwise Operators (F#)

  • Computes the bitwise AND operation.

'

Literals (F#)

Automatic Generalization (F#)

  • Delimits a single-character literal.

  • Indicates a generic type parameter.

``...``

No more information available.

  • Delimits an identifier that would otherwise not be a legal identifier, such as a language keyword.

( )

Unit Type (F#)

  • Represents the single value of the unit type.

(...)

Tuples (F#)

Operator Overloading (F#)

  • Indicates the order in which expressions are evaluated.

  • Delimits a tuple.

  • Used in operator definitions.

(*...*)

  • Delimits a comment that could span multiple lines.

(|...|)

Active Patterns (F#)

  • Delimits an active pattern. Also called banana clips.

*

Arithmetic Operators (F#)

Tuples (F#)

Units of Measure (F#)

  • When used as a binary operator, multiplies the left and right sides.

  • In types, indicates pairing in a tuple.

  • Used in units of measure types.

*?

Nullable Operators (F#)

  1. Multiplies the left and right sides, when the right side is a nullable type.

**

Arithmetic Operators (F#)

  • Computes the exponentiation operation (x ** y means x to the power of y).

+

Arithmetic Operators (F#)

  • When used as a binary operator, adds the left and right sides.

  • When used as a unary operator, indicates a positive quantity. (Formally, it produces the same value with the sign unchanged.)

+?

Nullable Operators (F#)

  1. Adds the left and right sides, when the right side is a nullable type.

,

Tuples (F#)

  • Separates the elements of a tuple, or type parameters.

-

Arithmetic Operators (F#)

  • When used as a binary operator, subtracts the right side from the left side.

  • When used as a unary operator, performs a negation operation.

-

Nullable Operators (F#)

  1. Subtracts the right side from the left side, when the right side is a nullable type.

->

Functions (F#)

Match Expressions (F#)

  • In function types, delimits arguments and return values.

  • Yields an expression (in sequence expressions); equivalent to the yield keyword.

  • Used in match expressions

.

Members (F#)

Primitive Types (F#)

  • Accesses a member, and separates individual names in a fully qualified name.

  • Specifies a decimal point in floating point numbers.

..

Loops: for...in Expression (F#)

  • Specifies a range.

.. ..

Loops: for...in Expression (F#)

  • Specifies a range together with an increment.

.[...]

Arrays (F#)

  • Accesses an array element.

/

Arithmetic Operators (F#)

Units of Measure (F#)

  • Divides the left side (numerator) by the right side (denominator).

  • Used in units of measure types.

/?

Nullable Operators (F#)

  1. Divides the left side by the right side, when the right side is a nullable type.

//

  • Indicates the beginning of a single-line comment.

///

XML Documentation (F#)

  • Indicates an XML comment.

:

Functions (F#)

  • In a type annotation, separates a parameter or member name from its type.

::

Lists (F#)

Match Expressions (F#)

  • Creates a list. The element on the left side is appended to the list on the right side.

  • Used in pattern matching to separate the parts of a list.

:=

Reference Cells (F#)

  • Assigns a value to a reference cell.

:>

Casting and Conversions (F#)

  • Converts a type to type that is higher in the hierarchy.

:?

Match Expressions (F#)

  • Returns true if the value matches the specified type; otherwise, returns false (type test operator).

:?>

Casting and Conversions (F#)

  • Converts a type to a type that is lower in the hierarchy.

;

Verbose Syntax (F#)

Lists (F#)

Records (F#)

  • Separates expressions (used mostly in verbose syntax).

  • Separates elements of a list.

  • Separates fields of a record.

<

Arithmetic Operators (F#)

  • Computes the less-than operation.

<?

Nullable Operators (F#)

Computes the less than operation, when the right side is a nullable type.

<<

Functions (F#)

  • Composes two functions in reverse order; the second one is executed first (backward composition operator).

<<<

Bitwise Operators (F#)

  • Shifts bits in the quantity on the left side to the left by the number of bits specified on the right side.

<-

Values (F#)

  • Assigns a value to a variable.

<...>

Automatic Generalization (F#)

  • Delimits type parameters.

<>

Arithmetic Operators (F#)

  • Returns true if the left side is not equal to the right side; otherwise, returns false.

<>?

Nullable Operators (F#)

  1. Computes the "not equal" operation when the right side is a nullable type.

<=

Arithmetic Operators (F#)

  • Returns true if the left side is less than or equal to the right side; otherwise, returns false.

<=?

Nullable Operators (F#)

  1. Computes the "less than or equal to" operation when the right side is a nullable type.

<|

Functions (F#)

  • Passes the result of the expression on the right side to the function on left side (backward pipe operator).

<||

Operators.( <|| )<'T1,'T2,'U> Function (F#)

  • Passes the tuple of two arguments on the right side to the function on left side.

<|||

Operators.( <||| )<'T1,'T2,'T3,'U> Function (F#)

  • Passes the tuple of three arguments on the right side to the function on left side.

<@...@>

Code Quotations (F#)

  • Delimits a typed code quotation.

<@@...@@>

Code Quotations (F#)

  • Delimits an untyped code quotation.

=

Arithmetic Operators (F#)

  • Returns true if the left side is equal to the right side; otherwise, returns false.

=?

Nullable Operators (F#)

  1. Computes the "equal" operation when the right side is a nullable type.

==

Not applicable.

  • Not used in F#. Use = for equality operations.

>

Arithmetic Operators (F#)

  • Returns true if the left side is greater than the right side; otherwise, returns false.

>?

Nullable Operators (F#)

  1. Computes the "greather than" operation when the right side is a nullable type.

>>

Functions (F#)

  • Composes two functions (forward composition operator).

>>>

Bitwise Operators (F#)

  • Shifts bits in the quantity on the left side to the right by the number of places specified on the right side.

>=

Arithmetic Operators (F#)

  • Returns true if the right side is greater than or equal to the left side; otherwise, returns false.

>=?

Nullable Operators (F#)

  1. Computes the "greater than or equal" operation when the right side is a nullable type.

?

Parameters and Arguments (F#)

  • Specifies an optional argument.

  • Used as an operator for dynamic method and property calls. You must provide your own implementation.

? ... <- ...

No more information available.

  • Used as an operator for setting dynamic properties. You must provide your own implementation.

?>=, ?>, ?<=, ?<, ?=, ?<>, ?+, ?-, ?*, ?/

Nullable Operators (F#)

  1. Equivalent to the corresponding operators without the ? prefix, where a nullable type is on the left.

>=?, >?, <=?, <?, =?, <>?, +?, -?, *?, /?

Nullable Operators (F#)

  1. Equivalent to the corresponding operators without the ? suffix, where a nullable type is on the right.

?>=?, ?>?, ?<=?, ?<?, ?=?, ?<>?, ?+?, ?-?, ?*?, ?/?

Nullable Operators (F#)

  1. Equivalent to the corresponding operators without the surrounding question marks, where both sides are nullable types.

@

Lists (F#)

Strings (F#)

  • Concatenates two lists.

  • When placed before a string literal, indicates that the string is to be interpreted verbatim, with no interpretation of escape characters.

[...]

Lists (F#)

  • Delimits the elements of a list.

[|...|]

Arrays (F#)

  • Delimits the elements of an array.

[<...>]

Attributes (F#)

  • Delimits an attribute.

\

Strings (F#)

  • Escapes the next character; used in character and string literals.

^

Statically Resolved Type Parameters (F#)

Strings (F#)

  • Specifies type parameters that must be resolved at compile time, not at runtime.

  • Concatenates strings.

^^^

Bitwise Operators (F#)

  • Computes the bitwise exclusive OR operation.

_

Match Expressions (F#)

Generics (F#)

  • Indicates a wildcard pattern.

  • Specifies an anonymous generic parameter.

`

Automatic Generalization (F#)

  • Used internally to indicate a generic type parameter.

{...}

Sequences (F#)

Records (F#)

  • Delimits sequence expressions and computation expressions.

  • Used in record definitions.

|

Match Expressions (F#)

  • Delimits individual match cases, individual discriminated union cases, and enumeration values.

||

Boolean Operators (F#)

  • Computes the Boolean OR operation.

|||

Bitwise Operators (F#)

  • Computes the bitwise OR operation.

|>

Functions (F#)

  • Passes the result of the left side to the function on the right side (forward pipe operator).

||>

Operators.( ||> )<'T1,'T2,'U> Function (F#)

  • Passes the tuple of two arguments on the left side to the function on the right side.

|||>

Operators.( |||> )<'T1,'T2,'T3,'U> Function (F#)

  1. Passes the tuple of three arguments on the left side to the function on the right side.

~~

Operator Overloading (F#)

  • Used to declare an overload for the unary negation operator.

~~~

Bitwise Operators (F#)

  • Computes the bitwise NOT operation.

~-

Operator Overloading (F#)

  • Used to declare an overload for the unary minus operator.

~+

Operator Overloading (F#)

  • Used to declare an overload for the unary plus operator.

Operator Precedence

The following table shows the order of precedence of operators and other expression keywords in the F# language, in order from lowest precedence to the highest precedence. Also listed is the associativity, if applicable.

Operator

Associativity

as

Right

when

Right

| (pipe)

Left

;

Right

let

Nonassociative

function, fun, match, try

Nonassociative

if

Nonassociative

->

Right

:=

Right

,

Nonassociative

or, ||

Left

&, &&

Left

<op, >op, =, |op, &op

Left

&&&, |||, ^^^, ~~~, <<<, >>>

Left

^op

Right

::

Right

:?>, :?

Nonassociative

-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

F# supports custom operator overloading. This means that you can define your own operators. In the previous table, op can be any valid (possibly empty) sequence of operator characters, either built-in or user-defined. Thus, you can use this table to determine what sequence of characters to use for a custom operator to achieve the desired level of precedence. Leading . characters are ignored when the compiler determines precedence.

See Also

Reference

Operator Overloading (F#)

Other Resources

F# Language Reference