8 Patterns and unions

This chapter covers

  • Conditional logic with pattern matching
  • Discriminated unions
  • Summarizing the F# type system

This chapter finishes our look at the core F# language! It deals with two things: first, how we perform conditional logic, such as if/then and, second, the final kind of type supported in F#—the discriminated union—which provides a solution to parts of domain modeling that records and tuples can’t really address. When you finish this, you’ll have a rounded appreciation of the F# type system and understand when to use which component.

8.1 Introducing pattern matching

We’ve already seen if/then expressions in F#. As it turns out, in everyday F#, they are used only in a couple of specific scenarios because F# has ...

Get F# in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.