Redaguoti

Bendrinti naudojant


Keyword Reference

This topic contains links to information about all F# language keywords.

F# Keyword Table

The following table shows all F# keywords in alphabetical order, together with brief descriptions and links to relevant topics that contain more information.

Keyword Link Description
abstract Members

Abstract Classes
Indicates a method that either has no implementation in the type in which it is declared or that is virtual and has a default implementation.
and let Bindings

Records

Members

Constraints
Used in mutually recursive bindings and records, in property declarations, and with multiple constraints on generic parameters.
as Classes

Pattern Matching
Used to give the current class object an object name. Also used to give a name to a whole pattern within a pattern match.
assert Assertions Used to verify code during debugging.
base Classes

Inheritance
Used as the name of the base class object.
begin Verbose Syntax In verbose syntax, indicates the start of a code block.
class Classes In verbose syntax, indicates the start of a class definition.
default Members Indicates an implementation of an abstract method; used together with an abstract method declaration to create a virtual method.
delegate Delegates Used to declare a delegate.
do do Bindings

Loops: for...to Expression

Loops: for...in Expression

Loops: while...do Expression
Used in looping constructs or to execute imperative code.
done Verbose Syntax In verbose syntax, indicates the end of a block of code in a looping expression.
downcast Casting and Conversions Used to convert to a type that is lower in the inheritance chain.
downto Loops: for...to Expression In a for expression, used when counting in reverse.
elif Conditional Expressions: if...then...else Used in conditional branching. A short form of else if.
else Conditional Expressions: if...then...else Used in conditional branching.
end Structs

Discriminated Unions

Records

Type Extensions

Verbose Syntax
In type definitions and type extensions, indicates the end of a section of member definitions.

In verbose syntax, used to specify the end of a code block that starts with the begin keyword.
exception Exception Handling

Exception Types
Used to declare an exception type.
extern External Functions Indicates that a declared program element is defined in another binary or assembly.
false Primitive Types Used as a Boolean literal.
finally Exceptions: The try...finally Expression Used together with try to introduce a block of code that executes regardless of whether an exception occurs.
fixed Fixed Used to "pin" a pointer on the stack to prevent it from being garbage collected.
for Loops: for...to Expression

Loops: for...in Expression
Used in looping constructs.
fun Lambda Expressions: The fun Keyword Used in lambda expressions, also known as anonymous functions.
function Match Expressions

Lambda Expressions: The fun Keyword
Used as a shorter alternative to the fun keyword and a match expression in a lambda expression that has pattern matching on a single argument.
global Namespaces Used to reference the top-level .NET namespace.
if Conditional Expressions: if...then...else Used in conditional branching constructs.
in Loops: for...in Expression

Verbose Syntax
Used for sequence expressions and, in verbose syntax, to separate expressions from bindings.
inherit Inheritance Used to specify a base class or base interface.
inline Functions

Inline Functions
Used to indicate a function that should be integrated directly into the caller's code.
interface Interfaces Used to declare and implement interfaces.
internal Access Control Used to specify that a member is visible inside an assembly but not outside it.
lazy Lazy Expressions Used to specify an expression that is to be performed only when a result is needed.
let let Bindings Used to associate, or bind, a name to a value or function.
let! Async expressions

Task expressions

Computation Expressions
Used in async expressions to bind a name to the result of an asynchronous computation, or, in other computation expressions, used to bind a name to a result, which is of the computation type.
match Match Expressions Used to branch by comparing a value to a pattern.
match! Computation Expressions Used to inline a call to a computation expression and pattern match on its result.
member Members Used to declare a property or method in an object type.
module Modules Used to associate a name with a group of related types, values, and functions, to logically separate it from other code.
mutable let Bindings Used to declare a variable, that is, a value that can be changed.
namespace Namespaces Used to associate a name with a group of related types and modules, to logically separate it from other code.
new Constructors

Constraints
Used to declare, define, or invoke a constructor that creates or that can create an object.

Also used in generic parameter constraints to indicate that a type must have a certain constructor.
not Symbol and Operator Reference

Constraints
Not actually a keyword. However, not struct in combination is used as a generic parameter constraint.
null Null Values

Constraints
Indicates the absence of an object.

Also used in generic parameter constraints.
of Discriminated Unions

Delegates

Exception Types
Used in discriminated unions to indicate the type of categories of values, and in delegate and exception declarations.
open Import Declarations: The open Keyword Used to make the contents of a namespace or module available without qualification.
or Symbol and Operator Reference

Constraints
Used with Boolean conditions as a Boolean or operator. Equivalent to ||.

Also used in member constraints.
override Members Used to implement a version of an abstract or virtual method that differs from the base version.
private Access Control Restricts access to a member to code in the same type or module.
public Access Control Allows access to a member from outside the type.
rec Functions Used to indicate that a function is recursive.
return Computation Expressions

Async expressions

Task expressions
Used to indicate a value to provide as the result of a computation expression.
return! Computation Expressions

Async expressions

Task expressions
Used to indicate a computation expression that, when evaluated, provides the result of the containing computation expression.
select Query Expressions Used in query expressions to specify what fields or columns to extract. Note that this is a contextual keyword, which means that it is not actually a reserved word and it only acts like a keyword in appropriate context.
static Members Used to indicate a method or property that can be called without an instance of a type, or a value member that is shared among all instances of a type.
struct Structs

Tuples

Constraints
Used to declare a structure type.

Used to specify a struct tuple.

Also used in generic parameter constraints.

Used for OCaml compatibility in module definitions.
then Conditional Expressions: if...then...else

Constructors
Used in conditional expressions.

Also used to perform side effects after object construction.
to Loops: for...to Expression Used in for loops to indicate a range.
true Primitive Types Used as a Boolean literal.
try Exceptions: The try...with Expression

Exceptions: The try...finally Expression
Used to introduce a block of code that might generate an exception. Used together with with or finally.
type F# Types

Classes

Records

Structs

Enumerations

Discriminated Unions

Type Abbreviations

Units of Measure
Used to declare a class, record, structure, discriminated union, enumeration type, unit of measure, or type abbreviation.
upcast Casting and Conversions Used to convert to a type that is higher in the inheritance chain.
use Resource Management: The use Keyword Used instead of let for values that require Dispose to be called to free resources.
use! Computation Expressions

Async expressions

Task expressions
Used instead of let! in async expressions and other computation expressions for values that require Dispose to be called to free resources.
val Explicit Fields: The val Keyword

Signatures

Members
Used in a signature to indicate a value, or in a type to declare a member, in limited situations.
void Primitive Types Indicates the .NET void type. Used when interoperating with other .NET languages.
when Constraints Used for Boolean conditions (when guards) on pattern matches and to introduce a constraint clause for a generic type parameter.
while Loops: while...do Expression Introduces a looping construct.
with Match Expressions

Object Expressions

Copy and Update Record Expressions

Type Extensions

Exceptions: The try...with Expression
Used together with the match keyword in pattern matching expressions. Also used in object expressions, record copying expressions, and type extensions to introduce member definitions, and to introduce exception handlers.
yield Lists, Arrays, Sequences Used in a list, array, or sequence expression to produce a value for a sequence. Typically can be omitted, as it is implicit in most situations.
yield! Computation Expressions

Async expressions

Task expressions
Used in a computation expression to append the result of a given computation expression to a collection of results for the containing computation expression.
const Type Providers Type Providers allow the use of const as a keyword to specify a constant literal as a type parameter argument.

The following tokens are reserved in F# because they are keywords in the OCaml language:

  • asr
  • land
  • lor
  • lsl
  • lsr
  • lxor
  • mod
  • sig

If you use the --mlcompatibility compiler option, the above keywords are available for use as identifiers.

The following tokens are reserved as keywords for future expansion of F#:

  • break
  • checked
  • component
  • const
  • constraint
  • continue
  • event
  • external
  • include
  • mixin
  • parallel
  • process
  • protected
  • pure
  • sealed
  • tailcall
  • trait
  • virtual

The following tokens were once reserved as keywords but were released in F# 4.1, so now you can use them as identifiers:

Keyword Reason
method Use member to introduce methods.
constructor Use new to introduce constructors.
atomic Related to the fad for transactional memory circa 2006. This would now be a library-defined computation expression.
eager No longer needed; it was initially designed to be let eager to match a potential let lazy.
object No need to reserve this.
recursive Use rec.
functor If F# added parameterized modules, you'd use module M(args) = ....
measure The [<Measure>] attribute suffices.
volatile The [<Volatile>] attribute suffices.

See also