Programming in Maple
Roger Kraft Department of Mathematics, Computer Science, and Statistics Purdue University Calumet
roger@calumet.purdue.edu
3.3. Data vs. data structure vs. data type
Here is an example that shows that a data structure is more than just the data contained in it, but it also includes the way the data is organized or interpreted (which is expressed as the data structure's data type). Below are seven data structures.
All seven of these data structures contain exactly the same data.
But they all have distinct data types.
In every one of these data structures, the data in the data structure is the same and in the same order, the two integers 1 and 2 . But the fact that this data is interpreted differently is very apparent in the last four examples where 1 and 2 represent the fraction 1/2, the decimal number100 (to one decimal place), the range from 1 to 2, and the inputs in the function call h(1,2), respectively. The way to think about this is that a data structure includes not just the data, but it also includes a way of interpreting the data, a way of giving meaning, or structure, to the data.
3.4. Data types in Mathematics
In mathematics, the notion of a "data type" exits, but it is rarely ever mentioned. For example, in a mathematics book, the notation (1, 2) can have (at least) two distinct meanings: the point in the plane with coordinates 1 and 2, and the open interval in the real line between 1 and 2. Each of these meanings of (1,2) has a different "data type", but when you see the notation (a,b) in a math book, you cannot ask the book "what is the data type of (a,b)?" (that is, "what does (a,b) mean?"). Instead, you are supposed to realize from the context what the notation means. On the other hand, Maple is not smart enough to understand an implied context; Maple needs to always be told explicitly what we are talking about. So if we want to tell Maple about the point (1,2) in the plane, we would use a list data type [1,2] and if we want to tell Maple about the interval (1,2) we would use a range data type 1..2 . Notice that Maple uses syntax to distinguish different kinds of data types. Some mathematics books try to use syntax to distinguish between different data types. For example, some books use the notation <1,2> to mean an ordered pair, to distinguish it from the open interval (1,2). But these different syntaxes are not universally used, and even when used, the idea that one is trying to distinguish between data types is never mentioned.