Concepts of Programming Languages

(Sean Pound) #1

310 Chapter 6 Data Types


Cartesian product set has one element from each of the constituant sets. So,
S 1 *S 2 ={(x, y)  x is in S 1 and y is in S 2 }. For example, if S 1 ={1, 2} and
S 2 ={a, b}, S 1 *S 2 ={(1, a), (1, b), (2, a), (2, b)}. A Cartesian product defines
tuples in mathematics, which appear in Python, ML, and F# as a data type (see
Section 6.5). Cartesian products also model records, or structs, although not
exactly. Cartesian products do not have element names, but records require
them. For example, consider the following C struct:

struct intFloat {
int myInt;
float myFloat;
};

This struct defines the Cartesian product type int * float. The names of
the elements are myInt and myFloat.
The union of two sets, S 1 and S 2 , is defined as S 1 h S 2 ={x  x is in S 1 or x
is in S 2 }. Set union models the union data types, as described in Section 6.10.
Mathematical subsets are defined by providing a rule that elements must
follow. These sets model the subtypes of Ada, although not exactly, because
subtypes must consist of contiguous elements of their parent sets. Elements of
mathematical sets are unordered, so the model is not perfect.
Notice that pointers, defined with type operators, such as * in C, are not
defined in terms of a set operation.
This concludes our discussion of formalisms in data types, as well as our
whole discussion of data types.

SUMMARY


The data types of a language are a large part of what determines that language’s
style and usefulness. Along with control structures, they form the heart of a
language.
The primitive data types of most imperative languages include numeric,
character, and Boolean types. The numeric types are often directly supported
by hardware.
The user-defined enumeration and subrange types are convenient and add
to the readability and reliability of programs.
Arrays are part of most programming languages. The relationship between
a reference to an array element and the address of that element is given in
an access function, which is an implementation of a mapping. Arrays can be
either static, as in C++ arrays whose definition includes the static specifier;
fixed stack-dynamic, as in C functions (without the static specifier); stack-
dynamic, as in Ada blocks; fixed heap dynamic, as with Java’s objects; or heap
dynamic, as in Perl’s arrays. Most languages allow only a few operations on
complete arrays.
Free download pdf