Thibodaux, LA 70310. 2 EECS Department, Tulane University, New Orleans, LA 70118. Abstract. Internal dependencies among object components character-.
Integrating Object Interdependency Information into Object Types Cong-cong Xing and Boumediene Belkhouche 1
Department of Mathematics and Computer Science, Nicholls State University, Thibodaux, LA 70310 2 EECS Department, Tulane University, New Orleans, LA 70118
Abstract. Internal dependencies among object components characterize the behaviors of objects and differentiate objects from records. Fundamental typing/subtyping shortcomings and loopholes still persist in current object type systems due to the overlook of such object component interdependencies. Object type graphs (OTG), which capture these interdependencies of objects and integrate them into object types, was proposed in [21, 20]. In this paper, we review the basic features of OTG, formalize the notion of object interdependencies within the framework of Abadi-Cardelli’s ς-calculus [1], provide an algorithm for computing interdependencies, and prove that the OTG type system is sound.
1
Introduction
Type is a central issue in the formal study of object-oriented languages. Without typing, objects could be satisfactorily interpreted as the self application of record-like or vector-like constructs (e.g. [12, 1, 14]). Within the framework of theoretical study of object-oriented languages, there are two major lines of research: Abadi-Cardelli’s ς-calculus [1] and Fisher-Mitchell’s lambda calculus of object (and its extension by others) [11, 16, 15, 2]. Considering that objects are an advanced data abstraction mechanism evolved from records, the type systems of both calculi are conventional in the following sense: The fundamental distinction between objects and records — object components can invoke one another and thus form a component interdependency within objects whereas records cannot — is not reflected in object types in either calculus. The result of failing to have object component interdependency information represented in object types is that two behaviorally distinct objects which deserve to be typed differently, may have the same type. For example, using the notion of ς-calculus [1], let objets a = [x = 1, y = 2] and b = [x = 1, y = ς(s : Self )(s.x + 1)], where ς is the binder, s is the self variable with the (self) type Self , and s.x is the invocation of field x. In object a, methods3 x and y are independent, whereas in b, (the evaluation of) y depends on (the evaluation of) 3
Note that in ς-calculus, fields and methods are not critically distinguished. Fields can be regarded as methods with a constant function body.
x. The behavioral difference of a and b can be seen by the results of the invocation of their methods y before and after their methods x are updated in the same manner. For instance, let⇐ be the method update operation in ς-calculus such that M.l ⇐ N evaluates to the object obtained by replacing the method l in M by N . Then, a.y = 2, (a.x ⇐ 2).y = 2, b.y = 2, but (b.x ⇐ 2).y = 3. We see that the behavior of a, in terms of the computation of a.y, remains the same before and after the updating operation, but the behavior of b is changed after the same updating operation is applied to b. In conventional object type systems, this behavioral discrepancy is not captured. Instead, a and b are of the same type [x : int, y : int] and thus can be used interchangeably in any program context where an object of type [x : int, y : int] is expected. As such, some programming problems will inevitably occur (shown in the next section) especially when subtyping and inheritance are considered.4
2
Issues
We present two issues that exist, among others, in the conventional object type systems due to the absence of handling of component interdependencies of objects. The first one address a practical programming issue; the second one pertains to the fundamental structure of object subtyping. 2.1
The Distance of a Movable Point
Points with additional attributes (e.g., color points [3, 5, 13], movable points [1, 2, 13]) have been an interesting study-case in the fundamental research of objectoriented languages. Here, we observe a new problem that is associated with movable points. Consider the following 1-d point x = 1.0 p1 = mvx = ς(s : Self )λ(i : real )(s.x⇐ s.x + i) dist = ς(s : Self )s.x where mvx moves the point to a new position on the x-axis and dist returns the distance from the origin to the current position of the point. In conventional object type systems, p1 would be of type x : real P1 = mvx : real → Self . dist : real Suppose we would like to define a function, m1d, which takes a 1-d point and moves it 1 unit of distance along the x-axis and then returns the distance from the 4
There is a notion of “behavioral subtyping” in the literature (e.g. [17]). Although object behaviors are the major concerns in both [17] and our work, they are fundamentally different.
origin to the new position of the point. Because of subtyping and subsumption, inevitably, m1d will take as its arguments some higher dimensional points which are of subtype of P1 , and in that case, we would like this function to move the higher dimensional points just 1 unit of distance along the x-axis and keep other coordinates of the points unchanged. Naturally, m1d can be written as follows: m1d = λ(p : P1 )(p.mvx (1)).dist As expected, m1d(p1 ) = 2.0, it moves p1 and returns the distance correctly. We now define a “free” 2-d point x = 1.0 y = 2.0 mvx = ς(s : Self )λ(i : real )(s.x⇐ s.x + i) p2 = mvy = ς(s : Self )λ(i : real )(s.y⇐ s.y + i) p dist = ς(s : Self ) (s.x)2 + (s.y)2 where the intention of each method is obvious. The type of p2 would be x : real y : real P2 = mvx : real → Self , mvy : real → Self dist : real and P2