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 23Lemma 3 For a type graph Γ, a node t ∈ Γ, a type substitution s = 〈α ↦→ u〉, and two instantiationgraphs J 1 and J 2 of t over s, J 1 ≃ J 2 .Proof. Let G = Γ t α, f 1 and f 2 be the instantiation functions from G to J 1 and J 2 ,respectively, and U = {u | α ∈ G, α ↦→ u ∈ s}. Notice that U excludes those mappings in s oftype variables not in G. We can construct the isomorphism h : J 1 → J 2 as follows:– h(n) = n, if n ∈ U, since n must be in both J 1 and J 2 ,– h(n) = f 2 (f −11 (n)), if n /∈ U, since both f 1 and f 2 are injective on nodes not in α.We can show that if t ∈ α, h(J 1 .) = J 1 . = f 1 (t) = f 2 (t) = J 2 ., otherwise, h(J 1 .) =f 2 (f −11 (J 1.)) = f 2 (t) = J 2 .. Thus, h is an isomorphism preserving nominal nodes. □For a node t ∈ Γ, we denote an instantiation node j of t over a type substitution s as Γ ⊢ j ≃ t〈s〉.For a generic class C ∈ Γ, let (Γ ′ , n) = shlo(Γ, C), if a node j ∈ Γ and a type substitution ssatisfy Γ ′ ⊢ j ≃ n〈s〉, we also say that j is an instantiation node of C over s in Γ, denoted asΓ ⊢ j ≃ C〈s〉.Given that Γ ⊢ j ≃ t〈s〉, a node n that is type equivalent to j in Γ is called a class instantiationof t over s, denoted as Γ ⊢ n ∼ t〈s〉.Table 3: Construction of Instantiationsins 0 (Γ, ts, f) ̂=t ∈ ts S dom(f)ins 0 (Γ, ts, f ∪ {t ↦→ t})t ∈ ts dom(f) j ∈ S Γ.ns ns = adj -ns(Γ, t)(〈N ′ , E ′ 〉, f ′ ) = ins 0 (〈Γ.ns ∪ {j}, Γ.es〉, ns, f ∪ {t ↦→ j})ins 0 (〈N ′ , E ′ ∪ {j a −→ f ′ (n) | n ∈ ns}〉, ts, f ′ ) (Γ, f) .We now show that <strong>for</strong> a type graph Γ, a node t ∈ Γ and a type substitution s, there is alwaysan extension Γ ′ of Γ with a partial function f from Γ to Γ ′ such that Γ ′ ⊢ f(t) ≃ t〈s〉.We define the extending function as ins 0 in Table 3. The function takes a type graph Γ, a set tsof the root nodes of templates and a map f as the arguments, and returns an updated type graphwith an updated map. Initially, ts is a singleton set of the node t, and f is the type substitutions. For each structural node n ∈ ts, the function introduces a new structural node n ′ , adds amapping n ↦→ n ′ , then recursively constructs the instantiation nodes <strong>for</strong> the adjacent nodes ofn, finally adds new edges from n ′ to the instantiation nodes, corresponding to the edges from nto its adjacent nodes. For each nominal node t in ts but not in α, the function adds an identitymapping t ↦→ t. The map being updated in the function is also used as the “visited” flags, wherea node in the domain of the map is considered visited.Report 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!