2.1. Data Types and Structured Data Types
Let
me begin the course by giving definitions for the terms data type and structured data type.
A data type consists of
- a domain (= a set of values)
- a set of operations.
Example 1: boolean or logical data type provided by
most programming languages.
- two values: true, false.
- many operations, including: AND, OR, NOT, etc.
Example 2: As a second example, consider the datatype fraction. How can we specify the domain and operations that define
fractions? It seems straightforward to name the operations; fractions are
numbers so all the normal arithmetic operations apply, such as addition,
multiplication, comparison. In addition there might be some fraction-specific
operations such as normalizing a fraction by removing common terms from its numerator and
denominator - for example, if we normalized 6/9 we'd get 2/3.
But how do we specify
the domain for fractions, i.e. the set of possible values for a fraction?