Lesson 21. Modeling relationships in F#

Although you’ve looked at different ways of storing data in F# (tuples, records, and so forth), one thing you haven’t looked at much is how to model relationships of data together—for example, different types of motor vehicles such as cars, motorbikes, and vans. In this lesson, you’ll look at a way of doing this in F#, using a flexible and powerful modeling tool called discriminated unions. You’ll do the following:

  • Briefly review inheritance in the OO world
  • Learn what discriminated unions are, and how to use them
  • Compare and contrast inheritance and discriminated unions

You’re probably familiar with modeling relationships in C# already, through one of two mechanisms: composition and inheritance. The ...

Get Get Programming with F# 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.