The API reference links in this article will take you to MSDN (for now).
This topic provides a table that shows how to specify the type of a literal in F#.
The following table shows the literal types in F#. Characters that represent digits in hexadecimal notation are not case-sensitive; characters that identify the type are case-sensitive.
|Type||Description||Suffix or prefix||Examples|
|sbyte||signed 8-bit integer||y||
|byte||unsigned 8-bit natural number||uy||
|int16||signed 16-bit integer||s||
|uint16||unsigned 16-bit natural number||us||
|signed 32-bit integer||l or none||
|unsigned 32-bit natural number||u or ul||
|unativeint||native pointer as an unsigned natural number||un||
|int64||signed 64-bit integer||L||
|uint64||unsigned 64-bit natural number||UL||
|single, float32||32-bit floating point number||F or f||
|float; double||64-bit floating point number||none||
|bigint||integer not limited to 64-bit representation||I||
|decimal||fractional number represented as a fixed point or rational number||M or m||
See also Strings.
|String or byte||verbatim string||@ prefix||
Unicode strings can contain explicit encodings that you can specify by using
\u followed by a 16-bit hexadecimal code or UTF-32 encodings that you can specify by using
\U followed by a 32-bit hexadecimal code that represents a Unicode surrogate pair.
As of F# 3.1, you can use the
+ sign to combine string literals. You can also use the bitwise or (
|||) operator to combine enum flags. For example, the following code is legal in F# 3.1:
[<Literal>] let Literal1 = "a" + "b" [<Literal>] let FileLocation = __SOURCE_DIRECTORY__ + "/" + __SOURCE_FILE__ [<Literal>] let Literal2 = 1 ||| 64 [<Literal>] let Literal3 = System.IO.FileAccess.Read ||| System.IO.FileAccess.Write
The use of other bitwise operators isn't allowed.
Values that are intended to be constants can be marked with the Literal attribute. This attribute has the effect of causing a value to be compiled as a constant.
In pattern matching expressions, identifiers that begin with lowercase characters are always treated as variables to be bound, rather than as literals, so you should generally use initial capitals when you define literals.
Integers In Other Bases
Signed 32-bit integers can also be specified in hexadecimal, octal, or binary using a
0b prefix respectively.
let Numbers = (0x9F, 0o77, 0b1010) // Result: Numbers : int * int * int = (159, 63, 10)
Underscores in Numeric Literals
Starting with F# 4.1, you can separate digits with the underscore character (
let DeadBeef = 0xDEAD_BEEF let DeadBeefAsBits = 0b1101_1110_1010_1101_1011_1110_1110_1111 let ExampleSSN = 123_456_7890