Sum type

November 4, 2020 ยท View on GitHub

The Concept

A sum type is a data structure which value can have several different, but fixed, types.

What to cover

  • What sum types are in your language What can they be used for? Do they have limitations? How are they different from enums?
  • How to define sum types How can they be defined?
  • How to work with sum types Can pattern matching be used? Are there built-in methods that work on sum types?

Exercises

Valentine date

This exercise chooses suitable options for a valentine's day date. The reference implementation (F#) teaches:

  • What sum types are and when to use them.
  • How sum types are different from enums.
  • How to define a sum type, with and without data.
  • How to do pattern matching on sum types.

Implementations

TrackExerciseChanges
F#stringsNone