This chapter covers:
- User-defined operators for derived types
- Writing a minimal countdown app
- Validating user input
- Synchronization on assignment in the tsunami simulator
Almost any app working with real-world data, or any program more complex than a toy model, will use derived types (classes) to handle abstract data. Operators for arithmetic (+, -, *, /, **) and comparison (==, /=, >=, ⇐, >, <) are available out of the box for built-in numeric (integer, real, complex) but not for derived types. For example, to keep track of calendar date and time in an app, you’d need to compare, add, and subtract datetime instances (data structures that represent date and time). This is where derived types from Chapter 8 and generic procedures and custom operators from Chapter 9 come together to form a powerful feature of the language: Overloading operators for derived types. This will allow you to define what the built-in (and custom) operators mean for any derived type, and in a way extend the syntax of the language.