Symbol and Operator Reference

Note

The API reference links in this article will take you to MSDN. The docs.microsoft.com API reference is not complete.

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

Computation Expressions
  • 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

Strings
  • Delimits a text string.
""" Strings 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

Flexible Types
  • 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

Code Quotations
  • Computes the integer remainder.
  • Used for splicing expressions into typed code quotations.
%% Code Quotations
  • Used for splicing expressions into untyped code quotations.
%? Nullable Operators
  • Computes the integer remainder, when the right side is a nullable type.
& Match Expressions
  • Computes the address of a mutable value, for use when interoperating with other languages.
  • Used in AND patterns.
&& Boolean Operators
  • Computes the Boolean AND operation.
&&& Bitwise Operators
  • Computes the bitwise AND operation.
' Literals

Automatic Generalization
  • 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
  • Represents the single value of the unit type.
(...) Tuples

Operator Overloading
  • 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
  • Delimits an active pattern. Also called banana clips.
* Arithmetic Operators

Tuples

Units of Measure
  • 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
  • Multiplies the left and right sides, when the right side is a nullable type.
** Arithmetic Operators
  • Computes the exponentiation operation (x ** y means x to the power of y).
+ Arithmetic Operators
  • 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
  • Adds the left and right sides, when the right side is a nullable type.
, Tuples
  • Separates the elements of a tuple, or type parameters.
- Arithmetic Operators
  • 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
  • Subtracts the right side from the left side, when the right side is a nullable type.
-> Functions

Match Expressions
  • In function types, delimits arguments and return values.
  • Yields an expression (in sequence expressions); equivalent to the yield keyword.
  • Used in match expressions
. Members

Primitive Types
  • Accesses a member, and separates individual names in a fully qualified name.
  • Specifies a decimal point in floating point numbers.
.. Loops: for...in Expression
  • Specifies a range.
.. .. Loops: for...in Expression
  • Specifies a range together with an increment.
.[...] Arrays
  • Accesses an array element.
/ Arithmetic Operators

Units of Measure
  • Divides the left side (numerator) by the right side (denominator).
  • Used in units of measure types.
/? Nullable Operators
  • 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
  • Indicates an XML comment.
: Functions
  • In a type annotation, separates a parameter or member name from its type.
:: Lists

Match Expressions
  • Creates a list. The element on the left side is prepended to the list on the right side.
  • Used in pattern matching to separate the parts of a list.
:= Reference Cells
  • Assigns a value to a reference cell.
:> Casting and Conversions
  • Converts a type to type that is higher in the hierarchy.
:? Match Expressions
  • Returns true if the value matches the specified type (including if it is a subtype); otherwise, returns false (type test operator).
:?> Casting and Conversions
  • Converts a type to a type that is lower in the hierarchy.
; Verbose Syntax

Lists

Records
  • Separates expressions (used mostly in verbose syntax).
  • Separates elements of a list.
  • Separates fields of a record.
< Arithmetic Operators
  • Computes the less-than operation.
<? Nullable Operators Computes the less than operation, when the right side is a nullable type.
<< Functions
  • Composes two functions in reverse order; the second one is executed first (backward composition operator).
<<< Bitwise Operators
  • Shifts bits in the quantity on the left side to the left by the number of bits specified on the right side.
<- Values
  • Assigns a value to a variable.
<...> Automatic Generalization
  • Delimits type parameters.
<> Arithmetic Operators
  • Returns true if the left side is not equal to the right side; otherwise, returns false.
<>? Nullable Operators
  • Computes the "not equal" operation when the right side is a nullable type.
<= Arithmetic Operators
  • Returns true if the left side is less than or equal to the right side; otherwise, returns false.
<=? Nullable Operators
  • Computes the "less than or equal to" operation when the right side is a nullable type.
<| Functions
  • Passes the result of the expression on the right side to the function on left side (backward pipe operator).
<|| Operators.( <|| )<'T1,'T2,'U> Function
  • Passes the tuple of two arguments on the right side to the function on left side.
<||| Operators.( <||| )<'T1,'T2,'T3,'U> Function
  • Passes the tuple of three arguments on the right side to the function on left side.
<@...@> Code Quotations
  • Delimits a typed code quotation.
<@@...@@> Code Quotations
  • Delimits an untyped code quotation.
= Arithmetic Operators
  • Returns true if the left side is equal to the right side; otherwise, returns false.
=? Nullable Operators
  • Computes the "equal" operation when the right side is a nullable type.
== Not applicable.
  • Not used in F#. Use = for equality operations.
> Arithmetic Operators
  • Returns true if the left side is greater than the right side; otherwise, returns false.
>? Nullable Operators
  • Computes the "greater than" operation when the right side is a nullable type.
>> Functions
  • Composes two functions (forward composition operator).
>>> Bitwise Operators
  • Shifts bits in the quantity on the left side to the right by the number of places specified on the right side.
>= Arithmetic Operators
  • Returns true if the left side is greater than or equal to the right side; otherwise, returns false.
>=? Nullable Operators
  • Computes the "greater than or equal" operation when the right side is a nullable type.
? Parameters and Arguments
  • 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
  • Equivalent to the corresponding operators without the ? prefix, where a nullable type is on the left.
>=?, >?, <=?, <?, =?, <>?, +?, -?, *?, /? Nullable Operators
  • Equivalent to the corresponding operators without the ? suffix, where a nullable type is on the right.
?>=?, ?>?, ?<=?, ?<?, ?=?, ?<>?, ?+?, ?-?, ?*?, ?/? Nullable Operators
  • Equivalent to the corresponding operators without the surrounding question marks, where both sides are nullable types.
@ Lists

Strings
  • 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
  • Delimits the elements of a list.
[|...|] Arrays
  • Delimits the elements of an array.
[<...>] Attributes
  • Delimits an attribute.
\ Strings
  • Escapes the next character; used in character and string literals.
^ Statically Resolved Type Parameters

Strings
  • Specifies type parameters that must be resolved at compile time, not at runtime.
  • Concatenates strings.
^^^ Bitwise Operators
  • Computes the bitwise exclusive OR operation.
_ Match Expressions

Generics
  • Indicates a wildcard pattern.
  • Specifies an anonymous generic parameter.
` Automatic Generalization
  • Used internally to indicate a generic type parameter.
{...} Sequences

Records
  • Delimits sequence expressions and computation expressions.
  • Used in record definitions.
| Match Expressions
  • Delimits individual match cases, individual discriminated union cases, and enumeration values.
|| Boolean Operators
  • Computes the Boolean OR operation.
||| Bitwise Operators
  • Computes the bitwise OR operation.
|> Functions
  • Passes the result of the left side to the function on the right side (forward pipe operator).
||> Operators.( ||> )<'T1,'T2,'U> Function
  • Passes the tuple of two arguments on the left side to the function on the right side.
|||> Operators.( |||> )<'T1,'T2,'T3,'U> Function
  • Passes the tuple of three arguments on the left side to the function on the right side.
~~ Operator Overloading
  • Used to declare an overload for the unary negation operator.
~~~ Bitwise Operators
  • Computes the bitwise NOT operation.
~- Operator Overloading
  • Used to declare an overload for the unary minus operator.
~+ Operator Overloading
  • 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
:>, :?> Right
!=op, <op, >op, =, |op, &op, &

(including <<<, >>>, |||, &&&)
Left
^op

(including ^^^)
Right
:: Right
:? Not associative
-op, +op Applies to infix uses of these symbols
*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