5 Shaping data

 

This chapter covers

  • The F# type system
  • Tuples
  • Records
  • Anonymous Records

Up until now, we’ve only dealt with primitive types, such as integers or strings, or built-in .NET types, such as System.Uri. Of course, F# needs a way to compose primitives together to make our own types: customers, orders, etc. F#’s type system has several ways to do this, and we’ll cover most of them in this chapter.

5.1 Composing types in F#

F# has a few more options and capabilities than many (although not all) languages. F# runs on the .NET platform, which means that it has to be able to understand all of the core .NET types and capabilities. This book ignores most of those features—things like classes and enums—not because you can’t use them (indeed, classes still do have an occasional part to play in certain edge cases in F#) but more because they are not typically required or used in everyday F#.

5.1.1 Data and functions in F#

5.2 Tuples

5.2.1 Tuple basics

5.2.2 More on tuples

5.2.3 Costs and benefits of tuples

5.3 Records

5.3.1 Defining, creating, and consuming records

5.3.2 More on records

5.3.3 Records and .NET

5.4 Anonymous records

5.4.1 Anonymous record tricks

5.5 Tuples or records

5.6 Exercise answers

Summary