Objects and Classes in Algol-like Languages1

Queue = class queue local Var[list int] e init e := [ ] meth finit = (e := [ ]), ins = x. (e := e@[x]), del = (if e = [ ] then skip else e := tl(e)), front = if e 6= [ ] then hd(e) else 0 g The interpretation of IA types is [[exp[Æ]]](Q) = Q Æ [[Æ]] [[comm]](Q) = Q Æ Q [[val[Æ]]](Q) = [[Æ]] [[ 1 2]](Q) = [[ 1]](Q) [[ 2]](Q) [[fxi: igi]](Q) = Q xi [[ i]](Q) [[ 1 ! 2]](Q) = 8Z: [[ 1]](Q Z)! [[ 2]](Q Z) [[cls ]](Q) = 9Z: [[ ]](Q Z) [Q Æ Q Z] where denotes smash product, Æ denotes strict function space, and ! denotes continuous function space. The quanti ers 8 and 9 are similar to the set-theoretic case. The ordering on 8Z: T (X;Z) is pointwise while that on 9Z: T (X;Z) is the least relation v such that p vT (X;Z) p 0 =) hjZ; pji v hjZ; pji The relation parts of the operators Æ,! and 8 are as in the set-theoretic case. For and 9, the relations R S and 9S: T (R;S) are de ned to be the least complete relations satisfying: x R x ^ y S y =) [(x; y)] R S [(x; y)] 9S:Z $ Z : p [T (R;S)] p =) hjZ; pji [9S: T (R;S)] hjZ ; pji Such least relations exist because complete relations are closed under arbitrary intersections. 5.2. Object-based semantics The \object-based" semantics described in [58, 48] (see also [5]) treats objects as state machines and describes them purely by their observable behavior. The observable behavior is given in terms of event traces whose structure is determined by the type of the object. This is similar to how processes are described in the semantics of CSP or CCS. Since no internal states appear in the denotations, proving the equivalence of two classes reduces to proving the equality of their trace sets. The object-based semantics, described in [58, 48], makes these ideas work for Idealized Algol. For simplicity, we consider a version of Idealized Algol with \Syntactic Control of Interference", where functions are only applied to arguments that they do not interfere with. This is the language treated in [58]. The reader is referred to this paper for all the background material for this section. We start with the notion of a coherent space [24], which is a simple form of event structure [69]. A coherent space is a pair A = (jAj;^A) where jAj is a (countable) set and^A is a re exive-symmetric binary relation on jAj. The elements of jAj are to be thought of as events for the objects of a particular type. The relation ^A, called the coherence relation, states whether two events can possibly be observed from the same object in the same state. The free object space generated by A is a coherent space A = (jAj ;^A ) where jAj is the set of ( nite) sequences over jAj (\traces") and ^A is de ned by ha1; : : : ; ani^A hb1; : : : ; bmi () 8i = 1; : : : ;min(n;m): ha1; : : : ; ai 1i = hb1; : : : ; bi 1i =) ai ^A bi This states that, after carrying out a sequence of events ha1; : : : ; ai 1i, the two traces must have coherent events at position i. If ai = bi, then the same condition applies to position i+ 1. But if ai 6= bi, then the two events lead to distinct states and, so, there is no coherence condition on future events. An element of a coherent space A is a pairwise coherent subset x jAj. So, the elements of free object spaces denote trace sets for objects. Functions appropriate for these spaces are what are called regular maps f : A ! B , de ned in [58]. It turns out that regular maps can be described more simply in terms of linear maps of type A ! B. We actually de ne \multiple-argument linear maps" because they are needed for the term interpretation. A linear map of the form F : A 1; : : : ; A k ! B is a relation F (jA1j : : : jAkj ) jBj such that, whenever (~s; b); (~ s0; b) 2 F , we have (8i: si ^A i si) =) b _ ^B b 0 ^ (b = b =) ~s = ~ s0) (We are using the notation ~s = (s1; : : : ; sk) for the members of jA1j jAkj . ) Every such linear map denotes a multiple-argument regular map F : A 1; : : : ; A k ! B given by F = f(~ s1 ~ sn; hb1; : : : ; bni) j (~ s1; b1); : : : ; ( ~ sn; bn) 2 Fg Coherent spaces for the events of various Idealized Algol types are shown in Table 10. For each IA type , there is a coherent space which we also denote (ambiguously) by . The symbols a; b; : : : are used for denoting events, s; s; : : : for event traces, and i and l for the labels in disjoint unions of sets. The trace sets for objects of type are the elements of . Since we have a state-free description of objects, there is no characteristic di erence between objects and classes as in the parametricity semantics. The only di erence is that a class can be used repeatedly to generate new instances. So, a trace of a class is a sequence of object traces, one for each instance generated. Therefore, we de ne