Sum algebraic data types

In contrast to the product algebraic data types covered earlier, sum algebraic data types use the set sum operation for the composition of new types. The easiest case for this type is an enumeration composed of just a bunch of individual values. A more generic case is a type that groups a bunch of different types called variants. Each variant contributes a set of its possible values, which are created with the help of the variant constructor. All possible values of all variants combined with a set sum (union) constitute the sum type.

Another contrast with product types is that of all possible variants, only a single one can be a value for an instance of the sum type, while all fields constitute the value of a product type. ...

Get F# 4.0 Design Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.