13.07.2015 Views

A Graph-Based Generic Type System for Object-Oriented Programs

A Graph-Based Generic Type System for Object-Oriented Programs

A Graph-Based Generic Type System for Object-Oriented Programs

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Type</strong> Operations 25Proof. By Definition 12 and the definition of substitution composition, we can directly establishthe instantiation function.□In addition, an instantiation of a conjunction of a set of classes can be distributed over theconjunction.Lemma 6 Given a type graph Γ, nodes t and a type substitution s, if <strong>for</strong> nodes j, j ′ , r, r ′ ,then Γ ⊢ r ′ ∼ j ′ .Γ ⊢ j ≃ t〈s〉, r ′ ∼ ⋓ j, r ∼ ⋓ t, j ′ ≃ r〈s〉,Proof. For a navigation path a in the <strong>for</strong>m of a or σ.m.x, and a path j ′ a −→ u ∈ Γ, by instantiation,there is either a path r −→ a u ∈ Γ, or a path r −→ a α ∈ Γ if α ↦→ u ∈ s. Thus, by conjunction, there⊲exists a node t 0 ∈ t such that t 0 −→∗−→ a ⊲u ∈ Γ, or t 0 −→∗−→ a α ∈ Γ. Let j 0 ∈ j be the instantiation⊲node of t 0 . There exists a path j 0 −→∗−→ a u 0 ∈ Γ such that Γ ⊢ u 0 ≃ u, either directly mapped,or by the substitution α ↦→ u. Thus there exists a path r ′ a −→ u′0 ∈ Γ such that Γ ⊢ u ′ 0 ∼ u. Wehave proven that <strong>for</strong> such a navigation path a, j ′ a −→ u ∈ Γ =⇒ ∃r′ a −→ u′0 • Γ ⊢ u ′ 0 ∼ u. Theopposite is similar.□4.5 Recursive <strong>Generic</strong> ClassesFor a non-recursive generic class D〈β〉, we draw the graph of D〈β〉 directly from its textualdefinition. <strong>Based</strong> on this graph, we can construct any instantiation of D〈β〉 in the way stated inthe previous subsection. However, <strong>for</strong> a recursive generic class C〈α〉, a class instantiation C〈s〉,where s is a type substitution, may be used as the type of an attribute of C〈α〉. In this case,there is an edge from the node C to the node representing C〈s〉, thus the graph of C〈α〉 dependson the graph of C〈s〉. For the same reason the graph of C〈s〉 depends on the graph of C〈s 2 〉,and so on, where s k ̂= s k−1 ◦ s. Notice that Lemma 5 ensures that the notation of instantiationC〈s k 〉 is well defined <strong>for</strong> a positive number k. Because of the recursive instantiation, a genericclass C〈α〉 with an attribute of type C〈s〉 is defined only if the type substitution s is convergent.A type substitution s is called convergent if the set {s i | i > 0} is finite, otherwise it is calleddivergent. For example, 〈α ↦→ α〉 and 〈α ↦→ β, β ↦→ α〉 are convergent substitutions, while〈α ↦→ C〈α ↦→ α〉〉 and 〈α ↦→ γ, γ ↦→ D〈β ↦→ α〉〉 are divergent ones. A type substitution s isdivergent if and only if there is a list of mappings α 1 ↦→ Te 1 , . . . , α k ↦→ Te k (k ≥ 1) in s suchthat α i+1 occurs as an actual type in Te i <strong>for</strong> 1 ≤ i < k and α 1 occurs as an actual type in aclass instantiation in Te k .When s is convergent, the set {C〈s i 〉 | i > 0} of instantiations that the generic class C〈α〉depends on is finite, i.e., the graph of C〈α〉 is finite. Since the types C〈s i 〉 mutually refer to eachReport No. 448, June 2011UNU-IIST, P.O. Box 3058, Macao

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!