Share via

F# Language Reference

This section is a reference to the F# language, a multi-paradigm programming language targeting the .NET platform. The F# language supports functional, object-oriented and imperative programming models.

F# Tokens

The following table shows reference topics that provide tables of keywords, symbols and literals used as tokens in F#.



Keyword Reference (F#)

Contains links to information about all F# language keywords.

Symbol and Operator Reference (F#)

Contains a table of symbols and operators that are used in the F# language.

Literals (F#)

Describes the syntax for literal values in F# and how to specify type information for F# literals.

F# Language Concepts

The following table shows reference topics available that describe language concepts.



Functions (F#)

Functions are the fundamental unit of program execution in any programming language. As in other languages, an F# function has a name, can have parameters and take arguments, and has a body. F# also supports functional programming constructs such as treating functions as values, using unnamed functions in expressions, composition of functions to form new functions, curried functions, and the implicit definition of functions by way of the partial application of function arguments.

F# Types

Describes the types that are used in F# and how F# types are named and described.

Type Inference (F#)

Describes how the F# compiler infers the types of values, variables, parameters and return values.

Automatic Generalization (F#)

Describes generic constructs in F#.

Inheritance (F#)

Describes inheritance, which is used to model the "is-a" relationship, or subtyping, in object-oriented programming.

Members (F#)

Describes members of F# object types.

Parameters and Arguments (F#)

Describes language support for defining parameters and passing arguments to functions, methods, and properties. It includes information about how to pass by reference.

Operator Overloading (F#)

Describes how to overload arithmetic operators in a class or record type, and at the global level.

Casting and Conversions (F#)

Describes support for type conversions in F#.

Access Control (F#)

Describes access control in F#. Access control means declaring what clients are able to use certain program elements, such as types, methods, functions and so on.

Pattern Matching (F#)

Describes patterns, which are rules for transforming input data that are used throughout the F# language to extract compare data with a pattern, decompose data into constituent parts, or extract information from data in various ways.

Active Patterns (F#)

Describes active patterns. Active patterns enable you to define named partitions that subdivide input data. You can use active patterns to decompose data in a customized manner for each partition.

Assertions (F#)

Describes the assert expression, which is a debugging feature that you can use to test an expression. Upon failure in Debug mode, an assertion generates a system error dialog box.

Exception Handling (F#)

Contains information about exception handling support in the F# language.

Attributes (F#)

Describes attributes, which enable metadata to be applied to a programming construct.

Resource Management: The use Keyword (F#)

Describes the keywords use and using, which can control the initialization and release of resources

Namespaces (F#)

Describes namespace support in F#. A namespace lets you organize code into areas of related functionality by enabling you to attach a name to a grouping of program elements.

Modules (F#)

Describes modules. An F# module is a grouping of F# code, such as values, types, and function values, in an F# program. Grouping code in modules helps keep related code together and helps avoid name conflicts in your program.

Import Declarations: The open Keyword (F#)

Describes how open works. An import declaration specifies a module or namespace whose elements you can reference without using a fully qualified name.

Signatures (F#)

Describes signatures and signature files. A signature file contains information about the public signatures of a set of F# program elements, such as types, namespaces, and modules. It can be used to specify the accessibility of these program elements.

XML Documentation (F#)

Describes support for generating documentation files for XML doc comments, also known as triple slash comments. You can produce documentation from code comments in F# just as in other .NET languages.

Verbose Syntax (F#)

Describes the syntax for F# constructs when lightweight syntax is not enabled. Verbose syntax is indicated by the #light "off" directive at the top of the code file.

F# Types

The following table shows reference topics available that describe types supported by the F# language.



Values (F#)

Describes values, which are immutable quantities that have a specific type; values can be integral or floating point numbers, characters or text, lists, sequences, arrays, tuples, discriminated unions, records, class types, or function values.

Primitive Types (F#)

Describes the fundamental primitive types that are used in the F# language. It also provides the corresponding .NET types and the minimum and maximum values for each type.

Unit Type (F#)

Describes the unit type, which is a type that indicates the absence of a specific value; the unit type has only a single value, which acts as a placeholder when no other value exists or is needed.

Strings (F#)

Describes strings in F#. The string type represents immutable text, as a sequence of Unicode characters. string is an alias for String in the .NET Framework.

Tuples (F#)

Describes tuples, which are groupings of unnamed but ordered values of possibly different types.

F# Collection Types

An overview of the F# functional collection types, including types for arrays, lists, sequences (seq), maps, and sets.

Lists (F#)

Describes lists. A list in F# is an ordered, immutable series of elements all of the same type.

Options (F#)

Describes the option type. An option in F# is used when a value may or may not exist. An option has an underlying type and may either hold a value of that type or it may not have a value.

Sequences (F#)

Describes sequences. A sequence is a logical series of elements all of one type. Individual sequence elements are only computed if required, so the representation may be smaller than a literal element count indicates.

Arrays (F#)

Describes arrays. Arrays are fixed-size, zero-based, mutable sequences of consecutive data elements, all of the same type.

Records (F#)

Describes records. Records represent simple aggregates of named values, optionally with members.

Discriminated Unions (F#)

Describes discriminated unions, which provides support for values which may be one of a variety of named cases, each with possibly different values and types.

Enumerations (F#)

Describes enumerations are types that have a defined set of named values. You can use them in place of literals to make code more readable and maintainable.

Reference Cells (F#)

Describes reference cells, which are storage locations that enable you to create mutable variables with reference semantics.

Type Abbreviations (F#)

Describes type abbreviations, which are alternate names for types.

Classes (F#)

Describes classes, which are types that represent objects that can have properties, methods, and events.

Structures (F#)

Describes structures, which are compact object types that can be more efficient than a class for types that have a small amount of data and simple behavior.

Interfaces (F#)

Describes interfaces, which specify sets of related members that other classes implement.

Abstract Classes (F#)

Describes abstract classes, which are classes that leave some or all members unimplemented, so that implementations can be provided by derived classes.

Type Extensions (F#)

Describes type extensions, which let you add new members to a previously defined object type.

Flexible Types (F#)

Describes flexible types. A flexible type annotation is an indication that a parameter, variable or value has a type that is compatible with type specified, where compatibility is determined by position in an object-oriented hierarchy of classes or interfaces.

Delegates (F#)

Describes delegates, which represent a function call as an object.

Units of Measure (F#)

Describes units of measure. Floating point values in F# can have associated units of measure, which are typically used to indicate length, volume, mass, and so on.

Type Providers

Describes type provides and provides links to walkthroughs on using the built-in type providers to access databases and web services.

F# Expressions

The following table lists topics that describe F# expressions.



Conditional Expressions: if... then...else (F#)

Describes the if...then...else expression, which runs different branches of code and also evaluates to a different value depending on the Boolean expression given.

Match Expressions (F#)

Describes the match expression, which provides branching control that is based on the comparison of an expression with a set of patterns.

Loops: Expression (F#)

Describes the expression, which is used to iterate in a loop over a range of values of a loop variable.

Loops: Expression (F#)

Describes the expression, a looping construct that is used to iterate over the matches of a pattern in an enumerable collection such as a range expression, sequence, list, array, or other construct that supports enumeration.

Loops: Expression (F#)

Describes the expression, which is used to perform iterative execution (looping) while a specified test condition is true.

Object Expressions (F#)

Describes object expressions, which are expressions that create new instances of a dynamically created, anonymous object type that is based on an existing base type, interface, or set of interfaces.

Lazy Computations (F#)

Describes lazy computations, which are computations that are not evaluated immediately, but are instead evaluated when the result is actually needed.

Computation Expressions (F#)

Describes computation expressions in F#, which provide a convenient syntax for writing computations that can be sequenced and combined using control flow constructs and bindings. They can be used to provide a convenient syntax for monads, a functional programming feature that can be used to manage data, control and side effects in functional programs. One type of computation expression, the asynchronous workflow, provides support for asynchronous and parallel computations. For more information, see Asynchronous Workflows (F#).

Asynchronous Workflows (F#)

Describes asynchronous workflows, a language feature that lets you write asynchronous code in a way that is very close to the way you would naturally write synchronous code.

Code Quotations (F#)

Describes code quotations, a language feature that enables you to generate and work with F# code expressions programmatically.

Query Expressions (F#)

Describes query expressions, a language feature that implements LINQ for F# and enables you to write queries against a data source or enumerable collection.

Compiler-supported Constructs

The following table lists topics that describe special compiler-supported constructs.



Compiler Directives (F#)

Describes processor directives and compiler directives.

Source Line, File, and Path Identifiers (F#)

Describes the identifiers __LINE__, __SOURCE_DIRECTORY__ and __SOURCE_FILE__, which are built-in values that enable you to access the source line number, directory and file name in your code.

See Also

Other Resources

Visual F#

F# Compiler (fsc.exe) Reference