-
Book Overview & Buying
-
Table Of Contents
F# 4.0 Design Patterns
By :
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.
This may sound complicated, but the concept is quite simple. Let's dive in.
Sum algebraic data types were introduced in F# by the native data type named discriminated union (DU). The utter flexibility of discriminated unions makes...
Change the font size
Change margin width
Change background colour