Skip to Main Content
Professional F# 2.0
book

Professional F# 2.0

by Ted Neward, Aaron C. Erickson, Talbott Crowell, Richard Minerich
June 2010
Intermediate to advanced content levelIntermediate to advanced
432 pages
10h 44m
English
Wrox
Content preview from Professional F# 2.0

Chapter 3. Primitive Types

WHAT'S IN THIS CHAPTER?

  • Understanding primitive types

  • Declaring primitive type instances

  • Applying operators

Like all languages that run on top of the CLR, the F# language provides a core set of primitive types that offer basic integer and floating-point arithmetic capabilities, character string support, Boolean types, and so on. In general, these map to the corresponding CLS types (System.Int16, System.Int32, and so on), as described next, but a few types are new to F# and come from the F# libraries. These types are fully accessible to other languages, such as C# and Visual Basic but obviously have no native language support there and need to be used as any other .NET type is (that is, via fully qualified type names).

BOOLEAN

Probably the simplest primitive type in F# is the bool type, which corresponds to the CLR's underlying System.Boolean type, and has two possible values, true and false.

Booleans support the usual range of logical operations, including && (logical AND) and || (logical OR), and otherwise behave just as Boolean values do in any other .NET language.

NUMERIC TYPES

F# supports a wide range of numeric types, 8 bits in size to 64, in both signed and unsigned versions, as shown here:

TYPE

DESCRIPTION

.NET NAME

LITERALS

Byte

8-bit unsigned integer

System.Byte

3uy, 0xFuy

Sbyte

8-bit signed integer

System.SByte

3y, 0xFy

int16

16-bit signed integer

System.Int16

3s, 0xFs

uint16

16-bi unsigned integer

System.UInt16

3us, 0xFus

int, int32

32-bit signed integer

System.Int32

3, 0xF ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Book of F#

The Book of F#

Dave Fancher
Beginning F# 4.0

Beginning F# 4.0

Robert Pickering, Kit Eason

Publisher Resources

ISBN: 9780470528013Purchase book