exercise 8.1.
Put 𝑅𝑁:={𝑥:𝖭𝖺𝗍},𝑅𝑇:={𝑥:𝖳𝗈𝗉},𝑅𝐶:={𝑥:𝖭𝖺𝗍,𝖼𝗈𝗅𝗈𝗋:𝖡𝗈𝗈𝗅}. There are six successful ordered pairs. Their complete rule trees are {𝑥}⊆{𝑥}𝑋𝖭𝖺𝗍<:𝖭𝖺𝗍S−Refl𝑅𝑁<:𝑅𝑁S−Rcd. {𝑥}⊆{𝑥}𝑋𝖭𝖺𝗍<:𝖳𝗈𝗉S−Top𝑅𝑁<:𝑅𝑇S−Rcd. {𝑥}⊆{𝑥}𝑋𝖳𝗈𝗉<:𝖳𝗈𝗉S−Refl𝑅𝑇<:𝑅𝑇S−Rcd. {𝑥}⊆{𝑥,𝖼𝗈𝗅𝗈𝗋}𝑋𝖭𝖺𝗍<:𝖭𝖺𝗍S−Refl𝑅𝐶<:𝑅𝑁S−Rcd. The remaining two are {𝑥}⊆{𝑥,𝖼𝗈𝗅𝗈𝗋}𝑋𝖭𝖺𝗍<:𝖳𝗈𝗉S−Top𝑅𝐶<:𝑅𝑇S−Rcd. {𝑥,𝖼𝗈𝗅𝗈𝗋}⊆{𝑥,𝖼𝗈𝗅𝗈𝗋}𝑋𝖭𝖺𝗍<:𝖭𝖺𝗍S−Refl𝑋𝖡𝗈𝗈𝗅<:𝖡𝗈𝗈𝗅S−Refl𝑅𝐶<:𝑅𝐶S−Rcd. For 𝑅𝑁 <:𝑅𝐶 and 𝑅𝑇 <:𝑅𝐶, the target label set {𝑥,𝖼𝗈𝗅𝗈𝗋} is not contained in the source label set {𝑥}. Thus the first premise of S-Rcd fails. For 𝑅𝑇 <:𝑅𝑁, label inclusion holds, but the field premise would be 𝖳𝗈𝗉 <:𝖭𝖺𝗍. Subtype-shape inversion excludes that judgment. These are the remaining three ordered pairs.
Exercise 8.2.
The first judgment holds. Its complete structural derivation is 𝑋𝖭𝖺𝗍<:𝖳𝗈𝗉S−Top𝑋𝖭𝖺𝗍<:𝖳𝗈𝗉S−Top𝖳𝗈𝗉→𝖭𝖺𝗍<:𝖭𝖺𝗍→𝖳𝗈𝗉S−Arr. The first premise is reversed: the target domain 𝖭𝖺𝗍 is below the source domain 𝖳𝗈𝗉.
The second judgment would require 𝖳𝗈𝗉 <:𝖭𝖺𝗍 both for its reversed domain premise and for its covariant codomain premise. Subtype-shape inversion excludes that judgment. Operationally, an erroneous covariant use would permit 𝑔:=𝜆𝑛:𝖭𝖺𝗍.𝗎𝗇𝗂𝗍:𝖭𝖺𝗍→𝖳𝗈𝗉 to be subsumed to 𝖳𝗈𝗉 →𝖭𝖺𝗍. Then 𝑔 𝗎𝗇𝗂𝗍 would be assigned type 𝖭𝖺𝗍 but would reduce to 𝗎𝗇𝗂𝗍, which is not a natural. This application is the preservation counterexample ruled out by domain contravariance.
exercise 8.3.
Recall 𝑐={𝑥=0,𝖼𝗈𝗅𝗈𝗋=𝗍𝗋𝗎𝖾},𝖢𝗈𝗅𝗈𝗋𝖯𝗈𝗂𝗇𝗍={𝑥:𝖭𝖺𝗍,𝖼𝗈𝗅𝗈𝗋:𝖡𝗈𝗈𝗅},𝖯𝗈𝗂𝗇𝗍={𝑥:𝖭𝖺𝗍}. The typing of the redex, including width subtyping and subsumption, is 𝑋⋅⊢0:𝖭𝖺𝗍T−Zero𝑋⋅⊢𝗍𝗋𝗎𝖾:𝖡𝗈𝗈𝗅True⋅⊢𝑐:𝖢𝗈𝗅𝗈𝗋𝖯𝗈𝗂𝗇𝗍T−Rcd{𝑥}⊆{𝑥,𝖼𝗈𝗅𝗈𝗋}𝑋⋅⊢𝖭𝖺𝗍<:𝖭𝖺𝗍S−Refl⋅⊢𝖢𝗈𝗅𝗈𝗋𝖯𝗈𝗂𝗇𝗍<:𝖯𝗈𝗂𝗇𝗍S−Rcd⋅⊢𝑐:𝖯𝗈𝗂𝗇𝗍T−Sub𝑥∈dom(𝖯𝗈𝗂𝗇𝗍)⋅⊢𝑐.𝑥:𝖭𝖺𝗍T−Proj. Operationally, E-Proj gives 𝑐.𝑥 ⟶0. The reduct has the required type by the leaf 𝑋⋅⊢0:𝖭𝖺𝗍T−Zero. Thus the field selected by reduction has exactly the type retained by the subsumed record interface.
Immutability is essential for the depth part of the argument. If writable fields were covariant, an alias of type {𝑞 :𝖭𝖺𝗍} could also be used at {𝑞 :𝖳𝗈𝗉}. A write of 𝗍𝗋𝗎𝖾 :𝖡𝗈𝗈𝗅 <:𝖳𝗈𝗉 through the second alias would leave the first alias reading a Boolean where its type promises a natural. No such write exists for the immutable records of this chapter.
Exercise 8.4.
Prove simultaneously for every closed value form that a derivation ⋅ ⊢𝑣 :𝐴 cannot have 𝐴 =𝖡𝗈𝗍, by induction on that typing derivation. A final introduction rule fixes both the outer syntax and a nonbottom result type: 𝑣introduction result𝜆𝑥:𝐶.𝑡𝐶→𝐷{ℓ𝑖=𝑣𝑖}𝑖∈𝐼{ℓ𝑖:𝐴𝑖}𝑖∈𝐼⟨𝑣1,𝑣2⟩𝐴1×𝐴2𝗂𝗇𝗅(𝑣),𝗂𝗇𝗋(𝑣)𝐴1+𝐴2𝗎𝗇𝗂𝗍𝖴𝗇𝗂𝗍𝗍𝗋𝗎𝖾,𝖿𝖺𝗅𝗌𝖾𝖡𝗈𝗈𝗅0,𝗌𝗎𝖼(𝑣)𝖭𝖺𝗍. No one of these outer constructors is 𝖡𝗈𝗍. A closed value cannot be a variable, and no elimination rule concludes the typing of one of the listed value syntaxes.
It remains to treat a derivation ending in subsumption: ⋅⊢𝑣:𝐶𝐶<:𝐴⋅⊢𝑣:𝐴T−Sub. If 𝐴 =𝖡𝗈𝗍, clause Bot-Down of lemma 8.5 forces 𝐶 =𝖡𝗈𝗍. The first premise is a strictly smaller typing derivation of the same closed value at 𝖡𝗈𝗍, contradicting the induction hypothesis. This also explains why all value forms are handled simultaneously: a chain of final subsumptions is peeled until an introduction rule is reached, and bottom cannot appear at either stage.
Exercise 8.5.
Let 𝑅={𝑥:𝖭𝖺𝗍,𝑞:𝖡𝗈𝗈𝗅},𝑆={𝑞:𝖡𝗈𝗈𝗅,𝑟:𝖴𝗇𝗂𝗍}. Their common label set is {𝑞} and their union of labels is {𝑥,𝑞,𝑟}. Since the common field types are identical, 𝑅⊔𝑆={𝑞:𝖡𝗈𝗈𝗅},𝑅⊓𝑆={𝑥:𝖭𝖺𝗍,𝑞:𝖡𝗈𝗈𝗅,𝑟:𝖴𝗇𝗂𝗍}. The four bound judgments are the following instances of S-Rcd: 𝑅<:{𝑞:𝖡𝗈𝗈𝗅},𝑆<:{𝑞:𝖡𝗈𝗈𝗅},𝑅⊓𝑆<:𝑅,𝑅⊓𝑆<:𝑆. For the first row, the singleton target label set is contained in the corresponding source set; for the second, the target label set is contained in {𝑥,𝑞,𝑟}. Every retained field premise is 𝐾 <:𝐾 for 𝐾 ∈{𝖭𝖺𝗍,𝖡𝗈𝗈𝗅,𝖴𝗇𝗂𝗍} and follows by S-Refl. These inclusions and reflexive field trees are all the premises of the four S-Rcd derivations.
Now replace 𝑆 by 𝑆′={𝑞:𝖳𝗈𝗉,𝑟:𝖴𝗇𝗂𝗍}. The recursive definition computes the common field bounds 𝖡𝗈𝗈𝗅⊔𝖳𝗈𝗉=𝖳𝗈𝗉,𝖡𝗈𝗈𝗅⊓𝖳𝗈𝗉=𝖡𝗈𝗈𝗅. Hence 𝑅⊔𝑆′={𝑞:𝖳𝗈𝗉},𝑅⊓𝑆′={𝑥:𝖭𝖺𝗍,𝑞:𝖡𝗈𝗈𝗅,𝑟:𝖴𝗇𝗂𝗍}. For example, the 𝑞 premises of the upper-bound trees are 𝖡𝗈𝗈𝗅 <:𝖳𝗈𝗉 and 𝖳𝗈𝗉 <:𝖳𝗈𝗉, while those of the lower-bound trees are 𝖡𝗈𝗈𝗅 <:𝖡𝗈𝗈𝗅 and 𝖡𝗈𝗈𝗅 <:𝖳𝗈𝗉. The identical-field abbreviation does not apply because its hypothesis asks for literally equal common field types, whereas 𝖡𝗈𝗈𝗅 ≠𝖳𝗈𝗉; the global recursive bound calculation is what supplies their join and meet.
exercise 8.6.
Define 𝖢𝗈𝗅𝗈𝗋𝖺𝖻𝗅𝖾:={𝗀𝖾𝗍𝖢𝗈𝗅𝗈𝗋:𝖴𝗇𝗂𝗍→𝖡𝗈𝗈𝗅} and 𝗋𝖾𝗆𝖾𝗆𝖻𝖾𝗋𝖢𝗈𝗅𝗈𝗋:=Λ𝑋<:𝖢𝗈𝗅𝗈𝗋𝖺𝖻𝗅𝖾.𝜆𝑜:𝑋.⟨𝑜,𝑜.𝗀𝖾𝗍𝖢𝗈𝗅𝗈𝗋 𝗎𝗇𝗂𝗍⟩. In the context Ω =𝑋 <:𝖢𝗈𝗅𝗈𝗋𝖺𝖻𝗅𝖾,𝑜 :𝑋, the observation has the complete derivation (𝑜:𝑋)∈ΩΩ⊢𝑜:𝑋T−VarΩ(𝑋)=𝖢𝗈𝗅𝗈𝗋𝖺𝖻𝗅𝖾Ω⊢𝑋<:𝖢𝗈𝗅𝗈𝗋𝖺𝖻𝗅𝖾S−VarΩ⊢𝑜:𝖢𝗈𝗅𝗈𝗋𝖺𝖻𝗅𝖾T−Sub𝗀𝖾𝗍𝖢𝗈𝗅𝗈𝗋∈dom(𝖢𝗈𝗅𝗈𝗋𝖺𝖻𝗅𝖾)Ω⊢𝑜.𝗀𝖾𝗍𝖢𝗈𝗅𝗈𝗋:𝖴𝗇𝗂𝗍→𝖡𝗈𝗈𝗅T−Proj𝑋Ω⊢𝗎𝗇𝗂𝗍:𝖴𝗇𝗂𝗍Unit−IΩ⊢𝑜.𝗀𝖾𝗍𝖢𝗈𝗅𝗈𝗋 𝗎𝗇𝗂𝗍:𝖡𝗈𝗈𝗅T−App. Call the displayed observation derivation D𝗈𝖻𝗌. For the next tree abbreviate 𝑏𝑋(𝑜) =⟨𝑜,𝑜.𝗀𝖾𝗍𝖢𝗈𝗅𝗈𝗋 𝗎𝗇𝗂𝗍⟩. Pair the observation with the original 𝑜 :𝑋, then introduce the term and type binders: (𝑜:𝑋)∈ΩΩ⊢𝑜:𝑋T−VarD𝗈𝖻𝗌Ω⊢𝑏𝑋(𝑜):𝑋×𝖡𝗈𝗈𝗅T−Pair𝑋<:𝖢𝗈𝗅𝗈𝗋𝖺𝖻𝗅𝖾⊢𝜆𝑜:𝑋.𝑏𝑋(𝑜):𝑋→𝑋×𝖡𝗈𝗈𝗅T−Lam⋅⊢𝗋𝖾𝗆𝖾𝗆𝖻𝖾𝗋𝖢𝗈𝗅𝗈𝗋:∀𝑋<:𝖢𝗈𝗅𝗈𝗋𝖺𝖻𝗅𝖾.𝑋→𝑋×𝖡𝗈𝗈𝗅T−TAbs.
Take the two-method record type and value from the chapter: 𝐶:=𝖢𝗈𝗅𝗈𝗋𝖯𝗈𝗂𝗇𝗍𝖮𝖻𝗃,𝖼𝗈𝗅𝗈𝗋𝖾𝖽:𝐶. The bound premise for instantiation is the width derivation {𝗀𝖾𝗍𝖢𝗈𝗅𝗈𝗋}⊆{𝗀𝖾𝗍𝖷,𝗀𝖾𝗍𝖢𝗈𝗅𝗈𝗋}𝑋⋅⊢𝖴𝗇𝗂𝗍→𝖡𝗈𝗈𝗅<:𝖴𝗇𝗂𝗍→𝖡𝗈𝗈𝗅S−Refl⋅⊢𝐶<:𝖢𝗈𝗅𝗈𝗋𝖺𝖻𝗅𝖾S−Rcd. Hence the instantiation and application rules give ⋅⊢𝗋𝖾𝗆𝖾𝗆𝖻𝖾𝗋𝖢𝗈𝗅𝗈𝗋:∀𝑋<:𝖢𝗈𝗅𝗈𝗋𝖺𝖻𝗅𝖾.𝑋→𝑋×𝖡𝗈𝗈𝗅⋅⊢𝐶<:𝖢𝗈𝗅𝗈𝗋𝖺𝖻𝗅𝖾⋅⊢𝗋𝖾𝗆𝖾𝗆𝖻𝖾𝗋𝖢𝗈𝗅𝗈𝗋[𝐶]:𝐶→𝐶×𝖡𝗈𝗈𝗅T−TApp⋅⊢𝖼𝗈𝗅𝗈𝗋𝖾𝖽:𝐶⋅⊢𝗋𝖾𝗆𝖾𝗆𝖻𝖾𝗋𝖢𝗈𝗅𝗈𝗋[𝐶] 𝖼𝗈𝗅𝗈𝗋𝖾𝖽:𝐶×𝖡𝗈𝗈𝗅T−App. The requested reduction is 𝗋𝖾𝗆𝖾𝗆𝖻𝖾𝗋𝖢𝗈𝗅𝗈𝗋[𝐶] 𝖼𝗈𝗅𝗈𝗋𝖾𝖽⟶(𝜆𝑜:𝐶.⟨𝑜,𝑜.𝗀𝖾𝗍𝖢𝗈𝗅𝗈𝗋 𝗎𝗇𝗂𝗍⟩) 𝖼𝗈𝗅𝗈𝗋𝖾𝖽⟶⟨𝖼𝗈𝗅𝗈𝗋𝖾𝖽,𝖼𝗈𝗅𝗈𝗋𝖾𝖽.𝗀𝖾𝗍𝖢𝗈𝗅𝗈𝗋 𝗎𝗇𝗂𝗍⟩⟶⟨𝖼𝗈𝗅𝗈𝗋𝖾𝖽,(𝜆𝑢:𝖴𝗇𝗂𝗍.𝗍𝗋𝗎𝖾) 𝗎𝗇𝗂𝗍⟩⟶⟨𝖼𝗈𝗅𝗈𝗋𝖾𝖽,𝗍𝗋𝗎𝖾⟩. The first component remains the original two-method record at type 𝐶.
Exercise 8.7.
The annotated body is still ⟨𝑜,𝑜.𝗀𝖾𝗍𝖷 𝗎𝗇𝗂𝗍⟩ but its local context is now Ω𝖳𝗈𝗉=𝑋<:𝖳𝗈𝗉,𝑜:𝑋. The variable rule gives Ω𝖳𝗈𝗉 ⊢𝑜 :𝑋. To use T-Proj at 𝗀𝖾𝗍𝖷, the derivation in the original term first subsumed 𝑜 to 𝖯𝗈𝗂𝗇𝗍𝖮𝖻𝗃={𝗀𝖾𝗍𝖷:𝖴𝗇𝗂𝗍→𝖭𝖺𝗍}. That step would now require the precise judgment Ω𝖳𝗈𝗉⊢𝑋<:𝖯𝗈𝗂𝗇𝗍𝖮𝖻𝗃.(1) An induction on a derivation with source 𝑋 proves the needed variable-source inversion: if Γ(𝑋) =𝖳𝗈𝗉 and Γ ⊢𝑋 <:𝐶, then 𝐶 is 𝑋 or 𝖳𝗈𝗉. The S-Var case uses the declared bound; the S-Trans case applies the induction hypothesis to its left premise and then lemma 18.6 to its right premise. Structural rules have nonvariable sources. Since 𝖯𝗈𝗂𝗇𝗍𝖮𝖻𝗃 is neither 𝑋 nor 𝖳𝗈𝗉, (1) is the first underivable judgment. Equivalently, after theorem 8.26, the algorithm promotes 𝑋 to 𝖳𝗈𝗉 and has no successful clause for a record target. Without (1), the receiver cannot be typed at any record interface containing 𝗀𝖾𝗍𝖷, so the projection and the claimed universal typing cannot be rebuilt.
exercise 8.8, exercise 8.9.
Assume Γ ⊢𝑃 <:𝑄 and begin with a judgment under Γ,𝑋 <:𝑄,Δ. The S-Var case of type substitution has exactly three positions for the looked-up declaration.
If the variable is 𝑋, its old conclusion is 𝑋 <:𝑄. The bound 𝑄 was formed before 𝑋, so 𝑄[𝑃/𝑋] =𝑄. After removing 𝑋 and transforming the suffix, weaken the premise through that suffix: Γ⊢𝑃<:𝑄Γ,Δ[𝑃/𝑋] 𝖼𝗍𝗑Γ,Δ[𝑃/𝑋]⊢𝑃<:𝑄weakening. This is precisely the substituted instance of 𝑋 <:𝑄.
If the looked-up variable 𝑌 occurs before 𝑋, then 𝑌 <:𝑅 is a declaration of Γ, and 𝑅 cannot mention the later 𝑋. Lookup is unchanged: (Γ,Δ[𝑃/𝑋])(𝑌)=𝑅Γ,Δ[𝑃/𝑋]⊢𝑌<:𝑅S−Var. Finally, if Δ =Δ0,𝑌 <:𝑅,Δ1, the transformed context is Γ,Δ0[𝑃/𝑋],𝑌<:𝑅[𝑃/𝑋],Δ1[𝑃/𝑋]. The corresponding lookup tree is (Γ,Δ[𝑃/𝑋])(𝑌)=𝑅[𝑃/𝑋]Γ,Δ[𝑃/𝑋]⊢𝑌<:𝑅[𝑃/𝑋]S−Var. These are all possible positions in the ordered context.
For narrowing, suppose the last typing rule is Γ,𝑋<:𝑄,Δ⊢𝑡:∀𝑌<:𝐴.𝐵Γ,𝑋<:𝑄,Δ⊢𝐶<:𝐴Γ,𝑋<:𝑄,Δ⊢𝑡[𝐶]:𝐵[𝐶/𝑌]T−TApp. The simultaneous narrowing induction hypotheses give both premises in the same strengthened context: Γ,𝑋<:𝑃,Δ⊢𝑡:∀𝑌<:𝐴.𝐵,Γ,𝑋<:𝑃,Δ⊢𝐶<:𝐴. Rebuilding the rule displays both required uses of the induction hypothesis: Γ,𝑋<:𝑃,Δ⊢𝑡:∀𝑌<:𝐴.𝐵Γ,𝑋<:𝑃,Δ⊢𝐶<:𝐴Γ,𝑋<:𝑃,Δ⊢𝑡[𝐶]:𝐵[𝐶/𝑌]T−TApp. The term and its result type are unchanged; only the declaration 𝑋 <:𝑄 has been narrowed to 𝑋 <:𝑃.
exercise 8.10.
Let Γ=𝑋<:𝑅,𝑅:={𝑥:𝖭𝖺𝗍,𝑞:𝖡𝗈𝗈𝗅},𝑃:={𝑥:𝖳𝗈𝗉}. The positive query takes source promotion, record comparison, and the top branch in that order. Including every priority guard, its tree is 𝑋≢𝛼𝑃𝑃≢𝛼𝖳𝗈𝗉Γ(𝑋)=𝑅𝑅≢𝛼𝑃{𝑥}⊆{𝑥,𝑞}𝖭𝖺𝗍≢𝛼𝖳𝗈𝗉Γ⊢a𝖭𝖺𝗍<:𝖳𝗈𝗉A−TopΓ⊢a𝑅<:𝑃A−RcdΓ⊢a𝑋<:𝑃A−Var. The complete recursive-query list is therefore 𝑋<:𝑃,𝑅<:𝑃,𝖭𝖺𝗍<:𝖳𝗈𝗉. Since 𝑤Γ(𝑅)=3,𝑤Γ(𝑋)=1+𝑤Γ(𝑅)=4,𝑤Γ(𝑃)=2, the sole promotion lowers the pair measure from 4 +2 =6 to 3 +2 =5. The record call then lowers it to 1 +1 =2.
For the reversed query 𝑃 <:𝑋, equality fails, the target is not top, the source is not bottom or a variable, and the outer constructors are a record and a variable. Thus its complete guard trace is 𝑃≢𝛼𝑋,𝑋≢𝛼𝖳𝗈𝗉,𝑃≢𝛼𝖡𝗈𝗍,𝑃 is not a variable,(𝑃,𝑋) matches no common structural form⎫{
{
{
{
{⎬{
{
{
{
{⎭⟹𝖿𝖺𝗂𝗅𝗎𝗋𝖾. There is no recursive query, no source promotion, and no algorithmic derivation tree for Γ ⊢a𝑃 <:𝑋.
Exercise 8.11.
Suppose the two nontrivial record derivations have conclusions Γ⊢a{ℓ𝑖:𝐴𝑖}𝑖∈𝐼<:{ℓ𝑗:𝐵𝑗}𝑗∈𝐽,Γ⊢a{ℓ𝑗:𝐵𝑗}𝑗∈𝐽<:{ℓ𝑘:𝐶𝑘}𝑘∈𝐾. They supply 𝐽 ⊆𝐼 and 𝐾 ⊆𝐽. Fix a target label ℓ ∈𝐾. The three field types named by the two derivations are 𝐴ℓin the first source,𝐵ℓin the middle record,𝐶ℓin the final target. Their field premises are Γ⊢a𝐴ℓ<:𝐵ℓ,Γ⊢a𝐵ℓ<:𝐶ℓ. Because 𝐵ℓ is a proper component of the middle record, its weight is strictly smaller than the middle-record weight. The lexicographic transitivity induction therefore applies exactly here and gives Γ⊢a𝐴ℓ<:𝐶ℓ. Doing this for every ℓ ∈𝐾, and composing label inclusions to obtain 𝐾 ⊆𝐼, supplies all premises of A-Rcd for the desired source and target records. If those records are alpha-identical, priority chooses A-Eq; otherwise the record nonidentity guard holds and A-Rcd rebuilds the conclusion.
Exercise 8.12.
Define 𝗌𝗎𝖻(Γ,𝐴,𝐵) by the following ordered cases. A recursive call returning failure makes the current case return failure; otherwise the named constructor is returned with the recursive trees as premises.
If 𝐴 ≡𝛼𝐵, return an A-Eq leaf.
If 𝐵 =𝖳𝗈𝗉, return an A-Top leaf.
If 𝐴 =𝖡𝗈𝗍, return an A-Bot leaf.
If 𝐴 =𝑋, fail when lookup is undefined; otherwise, with Γ(𝑋) =𝑈, recursively compute 𝐷 =𝗌𝗎𝖻(Γ,𝑈,𝐵) and return 𝐴 −𝑉𝑎𝑟(𝐷).
For two arrows, recursively compute the domain tree for 𝐵1 <:𝐴1 and the codomain tree for 𝐴2 <:𝐵2, then return A-Arr of them.
For two products or two sums, recursively compare corresponding components in source-to-target order and return A-Prod or A-Sum.
For two records, first fail unless every target label occurs in the source. Recursively compare 𝐴𝑗 <:𝐵𝑗 for each target label 𝑗 and return the finite A-Rcd tree.
For two bounded universals, first fail unless the bounds are alpha-identical. Rename the binders to a common fresh 𝑋, recursively compare the bodies under Γ,𝑋 <:𝐴, and return A-AllK.
For every other pair of outer forms, return failure.
The order is part of the definition, so reaching each case proves the side-condition that every earlier test failed. In particular the returned A-Top, A-Bot, A-Var, and structural nodes carry exactly the guards printed in the rule table.
Prove soundness of every returned tree by induction on 𝑚=𝑤Γ(𝐴)+𝑤Γ(𝐵). The first three branches return leaves whose conclusions and guards check directly. Promotion replaces 𝑤Γ(𝑋) =1 +𝑤Γ(𝑈) by 𝑤Γ(𝑈), so the induction hypothesis says the recursive result is a valid tree for 𝑈 <:𝐵; adjoining the successful lookup and guards makes a valid A-Var node. Every arrow, product, and sum call is on proper components and hence has smaller measure. Record calls are likewise on field components and there are finitely many of them; the prior label test supplies 𝐽 ⊆𝐼. In the universal branch, the body is the proper summand measured under the same extended context used by the recursive call, so its measure is smaller; the prior equality test supplies the invariant bound required by A-AllK. The induction hypotheses validate all child trees, and the corresponding rule validates the returned parent. Failure returns no tree and imposes no soundness obligation. Thus every possible successful return is a finite derivation checking against the displayed algorithmic rules.
exercise 8.13, exercise 8.15.
For the growing-context trace, put Γ𝑛:=𝑋0<:Θ,𝑋1<:𝑋0,…,𝑋𝑛<:𝑋𝑛−1(𝑛≥0),𝑇𝑘:=∀𝑋𝑘<:𝑋𝑘−1.¬𝑋𝑘(𝑘≥1). The chapter’s displayed iteration leaves Γ1 ⊢𝑋1 <:𝑇2. Source promotion reaches the next repeated query: Γ1⊢𝑋1<:𝑇2⇝Γ1⊢𝑋0<:𝑇2⇝Γ1⊢Θ<:𝑇2. The first requested continuation has both S-AllF premises visible at both nested uses: 𝑋Γ1⊢𝑋1<:𝖳𝗈𝗉S−TopΓ2⊢𝑋2<:𝑇3𝑋Γ2,𝑍2<:𝑋2⊢𝑍2<:𝑍2S−ReflΓ2⊢¬𝑇3<:¬𝑋2S−AllFΓ1⊢Θ<:𝑇2S−AllF. Its only open recursive premise promotes through every earlier declaration: Γ2⊢𝑋2<:𝑇3⇝Γ2⊢𝑋1<:𝑇3⇝Γ2⊢𝑋0<:𝑇3⇝Γ2⊢Θ<:𝑇3. The second continuation is therefore the following distinct tree: 𝑋Γ2⊢𝑋2<:𝖳𝗈𝗉S−TopΓ3⊢𝑋3<:𝑇4𝑋Γ3,𝑍3<:𝑋3⊢𝑍3<:𝑍3S−ReflΓ3⊢¬𝑇4<:¬𝑋3S−AllFΓ2⊢Θ<:𝑇3S−AllF. The outer rule compares the target bound 𝑋𝑖 with the unbounded source bound 𝖳𝗈𝗉; the inner rule reverses the bounds of the two negative abbreviations. The two continuations extend the context from Γ1 to Γ2 and then to Γ3. Each target quantifier supplies a fresh alpha-renamed declaration, so neither enlarged ordered context is textually equal to an earlier one.
Now let Γ ⊢𝑆 <:𝑇 be a closed full-𝐹<: statement. The direct typing reduction is (𝑓:𝑇→𝖳𝗈𝗉)∈(𝑓:𝑇→𝖳𝗈𝗉,𝑎:𝑆)Γ;𝑓:𝑇→𝖳𝗈𝗉,𝑎:𝑆⊢𝑓:𝑇→𝖳𝗈𝗉T−Var(𝑎:𝑆)∈(𝑓:𝑇→𝖳𝗈𝗉,𝑎:𝑆)Γ;𝑓:𝑇→𝖳𝗈𝗉,𝑎:𝑆⊢𝑎:𝑆T−VarΓ⊢𝑆<:𝑇Γ;𝑓:𝑇→𝖳𝗈𝗉,𝑎:𝑆⊢𝑎:𝑇T−SubΓ;𝑓:𝑇→𝖳𝗈𝗉,𝑎:𝑆⊢𝑓𝑎:𝖳𝗈𝗉T−AppΓ;𝑓:𝑇→𝖳𝗈𝗉⊢𝜆𝑎:𝑆.𝑓𝑎:𝑆→𝖳𝗈𝗉T−LamΓ;⋅⊢𝜆𝑓:𝑇→𝖳𝗈𝗉.𝜆𝑎:𝑆.𝑓𝑎:(𝑇→𝖳𝗈𝗉)→𝑆→𝖳𝗈𝗉T−Lam. The displayed T-Sub is the direct derivation’s single use of the input query.
Conversely, first establish the upward arrow-shape fact required in full 𝐹<:. Induct on a derivation of 𝐴1→𝐴2<:𝐶. The conclusion is that 𝐶 =𝖳𝗈𝗉, or that 𝐶 =𝐶1 →𝐶2 with 𝐶1 <:𝐴1 and 𝐴2 <:𝐶2. Reflexivity, S-Top, and S-Arr give exactly these alternatives. The source of S-Var is a type variable, and S-AllF has a universal source, so neither can be the final rule. We use in parallel the elementary maximality fact Γ⊢𝖳𝗈𝗉<:𝐶⟹𝐶=𝖳𝗈𝗉, proved by induction on its derivation; only reflexivity, top, and transitivity can occur.
In the transitivity case, write 𝐴1→𝐴2<:𝐸<:𝐶. The induction hypothesis for the first premise makes 𝐸 top or an arrow. If 𝐸 =𝖳𝗈𝗉, maximality applied to the second premise makes 𝐶 =𝖳𝗈𝗉. Otherwise let 𝐸 =𝐸1 →𝐸2, with 𝐸1 <:𝐴1 and 𝐴2 <:𝐸2. Apply the arrow induction hypothesis to the second premise. Its top alternative again concludes 𝐶 =𝖳𝗈𝗉; its arrow alternative gives 𝐶=𝐶1→𝐶2,𝐶1<:𝐸1<:𝐴1,𝐴2<:𝐸2<:𝐶2. Compose the two chains. This treats transitivity explicitly and exhausts the full-𝐹<: rules.
Now peel final T-Sub steps until the two syntax-directed T-Lam introductions for the displayed annotated lambdas are exposed. Invert the typing of their body 𝑓 𝑎. Application inversion supplies some domain 𝐷 such that 𝑓 is usable at a function type with domain 𝐷 and 𝑎 :𝐷. Inversion of the two variable typings through their final subsumption chains gives 𝑇→𝖳𝗈𝗉<:𝐷→𝐸,𝑆<:𝐷 for some result type 𝐸. Apply the just-proved arrow-shape induction to the first judgment: it gives 𝐷 <:𝑇 (and 𝖳𝗈𝗉 <:𝐸). Therefore Γ⊢𝑆<:𝐷Γ⊢𝐷<:𝑇Γ⊢𝑆<:𝑇S−Trans. The term has no free term variables. Its only possible free type variables are those declared by the supplied closed bound context Γ.
Exercise 8.14.
Assume a total decider 𝐷 for derivability of closed full-𝐹<: subtype statements. On a two-counter-machine instance 𝑀, perform these three effective steps:
construct Pierce’s rowing machine 𝑅 =R(𝑀);
construct the closed subtype statement 𝐽 =J(𝑅) =J(R(𝑀));
run 𝐷(𝐽) and answer “halts” exactly when the decider answers “derivable.”
Correctness in the accepting direction is the chain 𝐷(𝐽)=𝗒𝖾𝗌⟹𝐽 is derivable⟺𝑅 halts⟺𝑀 halts. Because 𝐷 is total and correct, a negative answer says that 𝐽 is not derivable. The reverse directions of the same two biconditionals give 𝐷(𝐽)=𝗇𝗈⟹𝐽 is not derivable⟺𝑅 does not halt⟺𝑀 does not halt. Thus 𝐷 would decide both answers to the undecidable machine-halting problem.
One divergent run of one subtype-search strategy proves only that this particular run or strategy fails to terminate on its input. It does not show that the queried judgment is underivable, and still less that no other total algorithm decides all judgments. The two effective reductions and both directions of their biconditionals are what turn a hypothetical total decider into a machine-halting decider; the growing divergent trace alone is not that reduction.