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 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.