Lectures onType Theory
ch:ml-modules: ch:ml-modules
appendix sectionsolutions

ch:ml-modules: ch:ml-modules

Exercise 12.1.

Write the order package as O:=pack[t,le]:t:Ty.tt2. If a set implementation is represented by pack[u,empty,insert], the desired insert field has type tuu. That occurrence of t is legal only inside unpack[t,o]=O in pack[u,empty,insert]. Returning this package would put the locally fresh t in the result type, contradicting existential elimination’s no-escape premise. Giving the set an independent element witness loses the required equation. Replacing both witnesses by N restores the equation by revealing the representation, so it no longer implements the abstract interface.

Exercise 12.2.

Let leBool:=λb1:2.λb2:2.¬b1b2,pB:=2;leBool. Rule Basic derives pB:B(s::Sing(2);ss2)=ORDERED[2]. Transparent matching retains the singleton s::Sing(2), so a client may pass true to the comparison field. Opaque sealing instead derives pBORDERED:B(s::Ty;ss2). The exported s is abstract, and no judgment s2::Ty is available. The same client application is therefore rejected.

Exercise 12.3.

The first component supplies the singleton equation X.sN::Ty. The second component of ORDSET consequently specializes to SET[N]. Matching pB:SET[2] against it also requires X.s2::Ty. The two equations would imply N2::Ty, which constructor equivalence cannot derive. Thus Sigma-Match fails at its second premise; the ordinary dynamic operations of the two components are irrelevant.

Exercise 12.4.

Bind two separately sealed applications Si=SetFn(pO). Both applications are specialized at pO:ORDERED[N], so both interface element parameters are N. Opaque sealing nevertheless allocates distinct representation identities: no judgment S1.sS2.s is derivable even though both bodies use lists. A hierarchy sharing exactly the element type is Sigma(X:ORDERED[N]).Sigma(S1:SET[X.s]).SET[X.s]. The two set components mention the same path X.s, but each basic set signature binds its own abstract representation constructor.

Exercise 12.5.

At the manifest argument, Pi-Match compares the domain contravariantly and then specializes the result to SET[N]; Sub applies the match. The source calculation is SetFn(pO)(12.5)ListSetpOSET[N](12.1)ListSetpO. Substituting that value in the annotated let gives L(12.4)2;π2(π2(ListSetpO.d))0(π1(ListSetpO.d))(12.2)2;π2(π2nil,cons,memberpO)0π1nil,cons,memberpOESndPairtwice,thenEFstPair2;memberpO0nil. The target application binds the translated argument once and opens it before translating the body: (λz.OpenORDERED[N](z,X;PS(X)))TρEO(pO)βOpenORDERED[N](TρEO(pO),X;PS(X))βpack[ListN;nil,cons,memberpO]. The translated let opens this package. Its dynamic projection is unpack[r,x]=pack[ListN;q] in xβq, after which the same product projections select nil and memberpO. If the annotated result type mentioned S.s, the witness r opened for S would occur free in that result type. The existential-elimination no-escape premise would then fail, which is why the supported translation requires the displayed closed result.

Exercise 12.6.

Take K(z,step,read):=read(step(step(stepz))). For CN, the successive states are 0,1,2,3, so the result is 3. For CP, they are 0,,1,,2,,3,, and the observer again returns 3. If abstract equality were exported, the logical relation would additionally have to satisfy R(n,p)R(n,p)eqN(n,n)=eqP(p,p). Without this operation clause the fundamental-relation induction has no case for the new constant.

Exercise 12.7.

The basic clause gives psig(NatOrder0)=B(s::Sing(N);NN2). If pS=ListN;vS, the hierarchy clause and singleton propagation give Sigma(:psig(NatOrder0)).B(r::Sing(ListN);pty(vS)). An opaque seal is excluded from the grammar of projectible paths because it forgets static identity. The generative application SetFn(NatOrder0) is also nonprojectible. Neither has a clause in definition 12.12; inspecting either body would manufacture precisely the identity that the boundary hides or generates. If another signature is proposed as least for either projectible example, leastness yields matches in both directions between it and the displayed psig; the selected calculus supplies no antisymmetry rule that would turn those two matches into judgmental equality.

Exercise 14.8.

Within the selected α-small relation fibers, the functorial action is pointwise, so the two witnesses become wround(rj)=wpack(wunpack(rj))(j{1,2}). The output witnesses need not be equal: proof relevance records the chosen input witness and the two maps applied to it. Under bst, the dynamic round-trip functions are identified; the output still has the input static type components X0,X1 and the tracked family X~ between them. If relation fibers are truncated to propositions, both r1 and r2 become the same mere fact of relatedness, and the distinction between the two displayed outputs is erased.

The counter theorem’s proposition is R(n,m,). It is defined externally inside a simply typed logical relation. That calculus has no internal bst, no static-extent signature, no family of witness sets, and no model of phase-separated parametricity. Therefore its proof has the same broad shape as representation independence, but does not instantiate the hypotheses of the imported ModTT theorem.

Exercise 12.8.

In Crary’s comparison calculus, two ordinary avoiding answers may retain the four visible fields while choosing respectively D:intuvandD:booluv. The first types Dx but not Dy; the second types Dy but not Dx. Each therefore exposes a fact unavailable from the other, so neither subsigns the other.

The least answer in the extended signature language is t.sig {type au=t; datatype v=D of t; x:intu; y:boolu}. The leading t binds the generated name throughout the four-field signature and prevents it from escaping. This answer belongs to Crary’s existential-signature extension, not to definition 12.1.

Exercise 12.9.

Let MAP[a] bind a private representation and operations on keys of type a. Use the hierarchy Sigma(O:ORDERED).Sigma(S:SET[O.s]).MAP[O.s]. A natural-number implementation matches with O.sN, a set representation ListN, and an independent map representation such as List(N×String). The two representation paths are unrelated. Replacing the map by MAP[2] requires both O.sN and O.s2, so matching fails at N2::Ty.

Exercise 12.10.

After matching both counter components to a closed result, use the hierarchy signature Sigma(:COUNTER).COUNTER. Its target is Pack(COUNTER)×Pack(COUNTER), and the hierarchy translates to P1,P2. The second dynamic projection reduces by unpack[t,x]=π2P1,P2 in xProdβunpack[t,x]=P2 in xβv2, where P2=pack[t2,v2]. If the source second component was written using the first path, matching must first replace that path by its manifest constructor. Otherwise P2’s type contains the witness opened for P1, so returning the pair violates no-escape and lies outside theorem 12.7.

Exercise 12.12.

With the temporary App-P and Seal-P rules, an applicative result can be recognized only from stable syntax. The corresponding principal clause is psig(F(A))=σ2[A/X] when psig(F)=Pi(X:σ1).σ2,psig(A)sσ1, and equality of two such result paths requires equality of both the functor paths and the argument values. That information is absent from the four structural clauses of definition 12.12.

For the extended phrase if b then M1 else M2, the runtime Boolean b is not a projectible functor path or a module value. Neither App-P nor Seal-P derives projectibility for the conditional, even when both branches have the same signature. Thus it has no stable applicative identity without an additional, unsound inspection of runtime control flow.

Search the book

Type to search the local edition.