Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!decwrl!ucbvax!agate!ig!uwmcsd1!csd4.milw.wisc.edu!markh From: markh@csd4.milw.wisc.edu (Mark William Hopkins) Newsgroups: comp.lang.modula2 Subject: Structured Types Message-ID: <5572@uwmcsd1.UUCP> Date: 17 Apr 88 00:19:22 GMT Sender: daemon@uwmcsd1.UUCP Reply-To: markh@csd4.milw.wisc.edu (Mark William Hopkins) Organization: University of Wisconsin-Milwaukee Lines: 65 Summary: A weakness in Modula-2 and Pascal References: Consider the following two segments: A := 3; A[1] := 3; B := A; B := A; WriteCard(B) WriteCard(B[1]) They both do the same thing. In the first, we can see that 3 will be written out by performing the successive transformations (beta reductions): A := 3; B := A; WriteCard(B) --> B := 3; WriteCard(B) --> WriteCard(3) However, were we to try this with the latter segment, we would be blocked. There is nothing that explicitly says that B[1] is assigned the value of A[1]. This points out a major flaw in Modula-2 and Pascal. They totally lack FIRST-CLASS structured types. It is an inconsistency that provides major obstacles to elegant programming. On one hand assignments to structured types are allowed, on the other there are no actual VALUES to be assigned. There are two ways to go with this. Either one could eliminate assignments to structured types -- essentially B := A is just a syntatic sugaring of the corresponding for loop -- or one could include structured EXPRESSIONS and CONSTANTS. The first alternative is really a step backwards ... and it is not in line with the implicit goals of Modula-2's design. The second, I believe, COMPLETES the design of the language. We need to extend the expression syntax to include STRUCTURED EXPRESSIONS, examples: ARRAY I : 1..3 OF 1:4, 2:5, 3:8 END ARRAY I : 3..6 OF 2*I END RECORD Field : Value, Field : Value ... END and the like. Assignments to components would then be interpreted as in the following example: A[1]:= 3 becomes A := ARRAY I:Range OF 1:3 ELSE A[I] which is much like an update statement such as: X := X + 1. Evaluation takes place in the obvious manner, examples: ARRAY I:2..3 OF 2:4, 3:5 END [2] --> 4 RECORD Field1 : Val1, Field2: Val2 END . Field1 --> Val1 These ideas entail a small modification in the language. However the ramifications for implementation need to be discussed. For example, can the static type-checking scheme of the Pascal-like languages handle such an extension? The key to these observations is that Modula-2 and Pascal both lack first-class structured types. As far as they incorporate strucured types in their syntax, this represents an inconsistency that often forces the user to develop roundabout means of expressing what the language restricts.