Share via


Literals (F#)

This topic provides a table that shows how to specify the type of a literal in F#.

Literal Types

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. All integral literals may be specified in decimal, hexadecimal, and binary formats. The default is decimal. To specify a hexadecimal number, use the prefix 0x. To specify a number in binary, use the prefix 0b. Examples of hexadecimal and binary formats only appear for a few of the integral types in the following table, but they are valid for all integral types.

Type

Description

Suffix or prefix

Examples

sbyte

signed 8-bit integer

y

86y

0b00000101y

byte

unsigned 8-bit natural number

uy

86uy

0b00000101uy

int16

signed 16-bit integer

s

86s

uint16

unsigned 16-bit natural number

us

86us

int

int32

signed 32-bit integer

lor none

86

86l

uint

uint32

unsigned 32-bit natural number

u or ul

86u

86ul

nativeint

native pointer as an integer value

n

0x00002D3Fn

unativeint

native pointer as an unsigned natural number

un

0x00002D3Fun

int64

signed 64-bit integer

L

86L

uint64

unsigned 64-bit natural number

UL

86UL

single, float32

32-bit floating point number

F or f

4.14F or 4.14f

lf

0x00000000lf

float; double

64-bit floating point number

none

4.14 or 2.3E+32 or 2.3e+32

LF

0x0000000000000000LF

bigint

integer not limited to 64-bit representation

I

9999999999999999999999999999I

decimal

fractional number represented as a fixed point or rational number

M or m

0.7833M or 0.7833m

Char

Unicode character

none

'a'

String

Unicode string

none

"text\n" or @"c:\filename"

byte

ASCII character

B

'a'B

byte[]

ASCII string

B

"text"B

String or byte[]

verbatim string

@ prefix

@"\\server\share" (Unicode)

@"\\server\share"B (ASCII)

Remarks

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.

Named Literals

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.

See Also

Reference

Literals (F#)

Core.LiteralAttribute Class (F#)

Change History

Date

History

Reason

April 2011

Added byte syntax and information for int, int32, uint, uint32.

Customer feedback.

July 2011

Clarified support for binary and hexadecimal formats.

Content bug fix.