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 5. Composite Types

WHAT'S IN THIS CHAPTER?

  • Understanding option types

  • Working with tuples

  • Using arrays, lists and sequences

  • Creating and using maps and sets

Like many other .NET languages, F# provides not only a set of primitive types for describing the basic atoms of data (strings, integers, and so on), but also a set of types for gathering those atoms into larger structures. These composite types are also built into the language, and in some cases directly mirror capabilities found within the .NET Base Class Library or the CLR.

In many cases, F# developers will find that these composite types can serve where normally developers in other languages would have to create a complete class type. For example, as with many functional languages, F# developers can find that a collection of functions plus a tuple type instance or list instance can be sufficient to model the problem domain, without having to create a standalone class to represent the data. Much of the F# library is built in precisely this manner, wrapped into a module (see Chapter 11 for lexical scoping).

OPTION TYPES

The simplest composite type to understand is the option type, which is effectively an either/or type similar in some ways to the Boolean data type, but with an entirely different purpose and use.

Options are similar to Booleans in that there are only two acceptable values for a given option, None, indicating an absence of value, and Some, which indicates a value. As can be easily inferred from the description ...

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