concept DU in category f#

appears as: DU, DU
Get Programming with F#: A guide for .NET developers

This is an excerpt from Manning's book Get Programming with F#: A guide for .NET developers.

We haven’t yet looked at how to share common fields across a DU—for example, the manufacturer name of a hard disk or the size. This isn’t supported with DUs; you can’t put common fields on the base of the DU (for example, the Disk type). The best way to achieve this is by using a combination of a record and a discriminated union, as shown in figure 21.4. You create a wrapper record to hold any common fields, plus one more field that contains the discriminated union—the varying data.

Figure 21.4. Composing shared fields with varying custom data through a record and DU

For DUs with a large number of cases (hundreds) that change quickly, also think carefully. Every time you add a new case, your pattern matches over the DU will need to be updated to handle the new subtype (although the compiler will at least tell you where you need to update your code!). In such a case, either a record or raw functions might be a better fit, or falling back to a class-based inheritance model.

But if you have a fixed (or slowly changing) set of cases—which in my experience is appropriate the vast majority of the time—then a DU is a much better fit. DUs are lightweight, easy to work with, and very flexible, as you can add new behaviors extremely quickly without affecting the rest of your code base and get the benefit of pattern matching. They’re also generally much easier to reason about; having all implementations in a single place leads to much-easier-to-understand code.

Which language feature in F# do you use to test which case of a DU a value is?