Lectures onType Theory
ch:disjoint-intersections: ch:disjoint-intersections
appendix sectionsolutions

ch:disjoint-intersections: ch:disjoint-intersections

Exercise 21.1.

The first pair has distinct ordinary heads, so it is algorithmically disjoint. For the products, the first coordinates have distinct ordinary heads, so the left product rule proves disjointness even though the second coordinates are both Int. Two arrows with the same result are rejected because the arrow clause compares only results. If their domains are D1,D2 and their common result is R, the raw type (D1&D2)R is a common supertype. The domain intersection need not be well formed. There is no common supertype in either accepted case.

Exercise 21.2.

Without the disjointness premises of I-Merge and WF-&, synthesis gives 1,,2:Int&Int with target (1,2). The two checking derivations end in I-Sub, using c1=λp.π1p,c2=λp.π2p. Their targets are c1(1,2)1 and c2(1,2)2. Both are well typed; their different values are the coherence failure.

Exercise 21.3.

Let X=Int, Y=IntInt, and A=X&Y. Let Z=Int×Int; then AZ. Write cX:XX and cY:YY for the raw coercions generated by S-Int and S-Arr, and put dX=λq.cX(π1q),dY=λq.cY(π2q),cA=λq.(dXq,dYq). These are the rule-generated coercions for A<:X, A<:Y, and A<:A. For (A&Z)<:A, the forbidden direct left rule gives λp.cA(π1p). Rule S-&R, followed by the permitted ordinary projections to X and Y, gives λp.((λq.dX(π1q))p,(λq.dY(π1q))p). Both have target type (|A|×|Z|)|A|, but they are not alpha equal. They do beta-normalize to the same projection pair; this does not rescue the chapter’s raw-syntax uniqueness claim. Thus coercion typing still holds; lemma 21.10 is the first metatheorem in the chapter to fail, and raw elaboration coherence subsequently fails with it.

Exercise 21.4.

From (A&B)&C, the coercion to B is λp.π2(π1p). From A&(B&C), it is λp.π1(π2p). Their domains are respectively (|A|×|B|)×|C| and |A|×(|B|×|C|). Coherence compares two derivations of one fixed source judgment; it does not identify distinct, merely isomorphic source types or insert a product associator.

Exercise 21.5.

The merge synthesizes Int&(IntInt) and elaborates to (1,λx.x). Checking the annotated function position against IntInt inserts λp.π2p. Application therefore elaborates to (λp.π2p)(1,λx.x)2(λx.x)22.

Exercise 21.6.

If the result types are disjoint, inversion of any common arrow supertype would exhibit a common supertype of the results, a contradiction. Conversely, if A2 and B2 share C, then (A1&B1)C is a raw common supertype of A1A2 and B1B2. The witness grammar is unrestricted, so this remains valid when its domain intersection is not well formed.

Exercise 21.7.

Take A=Int&(IntInt),B=Int&(Int×Int). They are incomparable: answering the function component of A, or the product component of B, is impossible from the other type. Both subtype C=Int. Closed inhabitants 1,,(λx.x) and 2,,(3,4), with the displayed component annotations, coerce to 1 and 2. Thus incomparability does not imply disjointness.

Exercise 21.8.

For an intersection target, both derivations must end in S-&R; the ordinary-target premises exclude S-&Li. For an intersection source and ordinary target, two different left projections are excluded by unique contribution, and two equal projections reduce to the induction hypothesis. For equal ordinary heads, inversion forces the same one of S-Int, S-Arr, and S-Prod; distinct heads have no derivation. These are all overlapping last-rule pairs.

Search the book

Type to search the local edition.