Lectures onType Theory
ch:system-f: ch:system-f
appendix sectionsolutions

ch:system-f: ch:system-f

Exercise 5.1.

We prove the equation simultaneously with the corresponding equation for types, since the annotation of a term abstraction invokes the type case. The type grammar has three constructor cases. In the variable case, a variable distinct from X and Y is unchanged; at X, both sides are B[C/Y]; and at Y, both sides are C, using Xftv(C). Arrow types follow componentwise. For a universal type Z.A, alpha-rename Z fresh for B,C,X,Y; the type induction hypothesis gives (Z.A)[B/X][C/Y]=definitionZ.(A[B/X][C/Y])=inductionhypothesisZ.(A[C/Y][B[C/Y]/X])=definition(Z.A)[C/Y][B[C/Y]/X].

The term-variable case is immediate. The term-abstraction and application cases are the componentwise calculations (λx:A.s)[B/X][C/Y]=λx:A[B/X][C/Y].s[B/X][C/Y]=λx:A[C/Y][B[C/Y]/X].s[C/Y][B[C/Y]/X],(s1s2)[B/X][C/Y]=s1[C/Y][B[C/Y]/X]s2[C/Y][B[C/Y]/X]. The first line uses the type and term induction hypotheses; the second uses the two term induction hypotheses. Term binders have first been chosen fresh for the terms under discussion.

For a type abstraction whose displayed binder is already suitable, say t=ΛZ.s with ZX,Y and Zftv(B,C), the calculation is (ΛZ.s)[B/X][C/Y]=ΛZ.s[B/X][C/Y]=ΛZ.s[C/Y][B[C/Y]/X]=(ΛZ.s)[C/Y][B[C/Y]/X]. If the displayed Z occurs in B or C, choose one variable W fresh for s,B,C,X,Y and first use alpha-equivalence ΛZ.s=αΛW.s[W/Z]. Both sides are then calculated with this same display: (ΛW.s[W/Z])[B/X][C/Y]=ΛW.s[W/Z][B/X][C/Y]=ΛW.s[W/Z][C/Y][B[C/Y]/X]=(ΛW.s[W/Z])[C/Y][B[C/Y]/X]. This is the freshening step that would be lost by silently changing the binder on only one side.

Finally, type application changes both of its components: (s[D])[B/X][C/Y]=s[B/X][C/Y][D[B/X][C/Y]]=s[C/Y][B[C/Y]/X][D[C/Y][B[C/Y]/X]]=(s[D])[C/Y][B[C/Y]/X]. The type-abstraction calculation and this last calculation exhaust the two System F term forms not already present in the simply typed calculus, so the induction proves the equation for every t.

Exercise 5.2.

Write I=X.XX. The closed formation tree needed by the type application is XXXX typeFTyVarXXXX typeFTyVarXXX typeFTyArrI typeFTyAll. With the subscripts serving only to mark the two occurrences of the same variable, the complete term tree is f:If:I;f:Ifop:IFVarXXXX typeFTyVarXXXX typeFTyVarXXX typeFTyArrI typeFTyAll;f:Ifop[I]:IIFAllEf:If:I;f:Ifarg:IFVar;f:Ifop[I]farg:IFArrE;λf:I.f[I]f:IIFArrIx:Xx:XX;x:Xx:XFVarX;λx:X.x:XXFArrI;ΛX.λx:X.x:IFAllI;did:IFArrE. Thus the operator occurrence of f first synthesizes I and, after F-All-E, synthesizes II; the argument occurrence synthesizes I without instantiation.

exercise 5.3.

Put I=Y.YY. Its closed formation derivation is YYYY typeFTyVarYYYY typeFTyVarYYY typeFTyArrI typeFTyAll. Substitution [I/X] sends the context f:XX,x:X to f:II,x:I. The transformed term derivation is f:IIf:II,x:I;f:II,x:If:IIFVarx:If:II,x:I;f:II,x:Ix:IFVar;f:II,x:Ifx:IFArrE. Term substitution cannot produce this tree: it replaces a term variable by a term and leaves every annotation and declaration type unchanged. Here the operation replaces the type variable in both declarations and in the result classifier.

Exercise 5.4.

Inverting the final application gives a type A and premises Δ;Γ(ΛX.t)[C]:AD,Δ;Γu:A. Inverting the type application supplies a body type B such that Δ;ΓΛX.t:X.B,ΔC type,B[C/X]=AD. Inverting the type abstraction finally gives Δ,X;Γt:B. Context formation for the abstraction ensures that X is absent from the types in Γ. Type substitution therefore yields Δ;Γt[C/X]:B[C/X]=AD. The reduct of the left subterm is exactly t[C/X]. Reusing the unchanged argument premise rebuilds the final rule: Δ;Γt[C/X]:ADΔ;Γu:AΔ;Γt[C/X]u:DFArrE. This is preservation for the congruence step induced by the type-beta contraction.

exercise 5.5.

Use the boolean itself as its eliminator: notF:=λb:BoolF.ΛX.λt:X.λf:X.b[X]ft,andF:=λb1:BoolF.λb2:BoolF.b1[BoolF]b2falseF. Inside the first term, b[X]:XXX, so the reversed arguments give an X; the three introductions produce the required boolean. Inside the second, instantiation at BoolF makes the two branch arguments have the required common type.

The reductions are notFtrueFβΛX.λt:X.λf:X.trueF[X]ftβΛX.λt:X.λf:X.(λt:X.λf:X.t)ftβΛX.λt:X.λf:X.(λf:X.f)tβfalseF,andFfalseFtrueFβ(λb2:BoolF.falseF[BoolF]b2falseF)trueFβfalseF[BoolF]trueFfalseFβ(λt:BoolF.λf:BoolF.f)trueFfalseFβ(λf:BoolF.f)falseFβfalseF,andFfalseFfalseFβ(λb2:BoolF.falseF[BoolF]b2falseF)falseFβfalseF[BoolF]falseFfalseFβ(λt:BoolF.λf:BoolF.f)falseFfalseFβ(λf:BoolF.f)falseFβfalseF. The second step of the first trace and the third step of each conjunction trace are type beta; all remaining contractions are term beta.

Exercise 5.6.

Define map+:=λs:A+FB.ΛX.λh:AX.λk:BX.s[X](λa:A.h(fa))(λb:B.k(gb)). Under s:A+FB we have s[X]:(AX)(BX)X. The two displayed lambdas have types AX and BX, since f:AA and g:BB. The body consequently has type X; the three introductions give map+:A+FBA+FB. For the two constructors, compatible beta reduction gives map+(inlF(a))βΛX.λh:AX.λk:BX.h(fa)=inlF(fa),map+(inrF(b))βΛX.λh:AX.λk:BX.k(gb)=inrF(gb). If s, f, and g are variables, applying the mapper has instead the variable-headed beta-normal form ΛX.λh:AX.λk:BX.s[X](λa:A.h(fa))(λb:B.k(gb)). There is no root redex at s[X], so no constructor case can be selected.

Exercise 5.7.

Iterate addition of the second argument once for every successor in the first: multF:=λm:NatF.λn:NatF.m[NatF]zeroF(addFn). The iterator typing gives the required result type. Its calculation at two and three is multF23β(addF3)((addF3)zeroF)βaddF33β6.

Put P=NatF×FNatF and define p0:=zeroF,zeroFF,step:=λp:P.sndF(p),succF(sndF(p))F,predF:=λn:NatF.fstF(n[P]p0step). Both projections in step have type NatF, so step:PP and the iterator produces a P. At zero, predFzeroFβfstF(p0)βzeroF. Writing pj=j1,jF for j1, the projection laws give p0step0,1Fstep1,2Fstep2,3F. Consequently predF3βfstF2,3Fβ2. All arrows in the displayed state trace abbreviate the beta contractions of the Church projections followed by the successor contraction.

Exercise 5.8.

Two closed decorations of the Curry identity are λx:I.x:II,ΛX.λx:X.x:I. Both erase to λx.x, but their types differ. Their Curry derivations are respectively x:Ix:I;x:ICx:ICVar;Cλx.x:IICArrI and x:Xx:XX;x:XCx:XCVarX;Cλx.x:XXCArrI;Cλx.x:ICAllI.

For a Curry term containing an application, take m=λf.(λx.x)f. It has the following two Church decorations at the same type: t1=λf:I.(λx:I.x)f:II,t2=λf:I.(ΛX.λx:X.x)[I]f:II. The first Curry tree uses the direct II typing of the inner identity: x:If:I,x:I;f:I,x:ICx:ICVar;f:ICλx.x:IICArrIf:If:I;f:ICf:ICVar;f:IC(λx.x)f:ICArrE;Cm:IICArrI. In the second tree, replace the left premise of that C-Arr-E by x:Xf:I,x:XX;f:I,x:XCx:XCVarX;f:ICλx.x:XXCArrI;f:ICλx.x:ICAllII type;f:ICλx.x:IICAllE. Decoration of the first tree inserts no universal constructors at the inner identity; decoration of the replacement inserts ΛX and then the type application [I]. Erasure makes the two resulting Church terms equal to the same m.

exercise 5.9.

Erasure gives (λf.ff)(λx.x). Algorithm W assigns the lambda-bound f one fresh monotype α. Typing the body application treats the left occurrence as a function with fresh result β and the right occurrence as its argument, producing ααβ. The occurs check rejects this equation.

The Curry derivation instead assigns f:I. Universal elimination is inserted at the function occurrence, decorating it as f[I]:II; the argument occurrence remains f:I. The body therefore decorates to f[I]f:I, and the whole term becomes the Church term of equation 5.1. No first-order unifier can repair the HM equation, because a finite monotype cannot equal a proper arrow tree containing itself. The successful derivation changes the typing discipline: it instantiates the polymorphic type of a lambda-bound variable.

Exercise 5.10.

Let ΔA type. Define abortA:=λz:VoidF.z[A]. Under z:VoidF=X.X, universal elimination gives the open judgment Δ;z:VoidFz[A]:A. Arrow introduction therefore derives Δ;abortA:VoidFA.

The construction is an eliminator, not an inhabitant of its domain. The consistency corollary says that no closed term can be supplied as its VoidF argument. Applying the eliminator would require exactly the closed inhabitant excluded by that corollary.

exercise 5.11.

For item 1, let n be a neutral beta-normal form with no free type variables. It has no one-step reducts. The premise of (CR3) is therefore vacuous, so n belongs to every candidate.

For item 2, define RS={tt has no free type variables and uR, tuS}. Choose distinct variables x,z fresh for t. Item 1 gives zR, so tzSSN. Put s:=tx. Then s[z/x]=tz, and reflection through the fresh substitution gives txSN. An infinite reduction from t would lift through the left application context to an infinite reduction from tx; hence tSN0. This proves (CR1) for every member of RS.

For (CR2), suppose tRS and tβt. For every uR, compatibility gives tuβtu, and (CR2) for S gives tuS. Type-closedness is preserved by reduction, so tRS.

For (CR3), let t be neutral and type-closed, and suppose every tβt lies in RS. Fix uR. The application tu is neutral. Induct on n=ν(u), with induction hypothesis tvS for every vR satisfying ν(v)<n. This measure is finite by (CR1) for R. An immediate reduct tu lies in S by the premise on t. An immediate reduct tu has uR by (CR2), and ν(u)<n; the induction hypothesis therefore puts tu in S. There is no root contraction because t is neutral. Thus (CR3) for S gives tuS, and consequently tRS. The three clauses prove that RS is exactly the arrow candidate used in the chapter.

For item 3, take t=q[D]. The term t[C]=(q[D])[C] is a type application whose operator is itself a type application, not a type abstraction, so it has no outer root contraction. Its immediate reducts are: (q[D])[C]when qβq,s[D/Y][C]when q=ΛY.s. Types do not reduce, so neither D nor C contributes another case. Both displayed forms are t[C] for an immediate reduct t of t. The universal-candidate premise puts every such t in the universal candidate; its defining clause then puts t[C] in F(C,R). Applying (CR3) in F(C,R) proves t[C]F(C,R).

Exercise 5.13.

For p:A×FB, expansion of every abbreviation turns the reconstructed pair into ΛX.λk:ABX.k(p[A](λa:A.λb:B.a))(p[B](λa:A.λb:B.b)). The comparison term is the neutral variable p. It is beta-normal. The expanded term is also beta-normal: both occurrences of p are neutral, the two projection continuations contain no redex, and the final applications are headed by the variable k. Its outer constructor is Λ, whereas the outer shape of p is neutral, so the two normal forms are not alpha-equal and hence are not beta-convertible.

Likewise, with BoolF=X.XXX, the two boolean candidates are bandΛX.λt:X.λf:X.b[X]tf. For neutral b, the operator b[X] is not a type abstraction, and its two term applications are not lambda-headed. Both candidates are therefore beta-normal, but again one is neutral and the other begins with Λ.

The first absent equation is the primitive product uniqueness rule fst(p),snd(p)=p. The second is the corresponding Boolean uniqueness, or eta, rule saying that a Boolean is uniquely reconstructed by eliminating it into its two branches. The Church encodings validate their constructor–eliminator beta laws, not these primitive eta laws under beta conversion alone.

Exercise 5.12.

Normalize a closed inhabitant and invert its typing. Its initial form is forced to be ΛX.λf:XX.r,f:XXr:XX. If r is neutral, its head must be the only term variable in the context, namely f. Since f already has the required arrow type, no application may follow it. This gives the eta-short normal form ΛX.λf:XX.f. Otherwise inversion makes r=λx:X.u, where f:XX,x:Xu:X. A normal term at the atomic type X is neutral. Its head is x, giving u=x, or it is headed by f and has the form fu. Repeating the same argument on the strictly smaller u gives a unique n0 with u=fnx. Thus all remaining forms are exactly ΛX.λf:XX.λx:X.fnx. The normal/neutral shape lemma proves that no third case exists, and Church–Rosser makes the member of the list unique under beta conversion. Function eta would add λx:X.fx=ηf(xfv(f)), which identifies the long member with n=1 and the eta-short member. Beta conversion alone does not identify them.

Exercise 9.14.

Fix a closed type C and a candidate R, and put η:=η[X(C,R)]. For every declaration x:B in Γ, the side condition Xftv(Γ) gives Xftv(B). Interpretation irrelevance therefore gives [[B]]η=[[B]]η. Each image σ(x) belongs to the right side, so the same substitution σ is η-reducible for Γ.

Apply the induction hypothesis to the premise under η. It gives t[η^][σ][[A]]η. The valuation η^ first performs η^ and then [C/X]. Every image of σ has no free type variables, so the term–type substitution equation yields t[η^][σ]=αt[η^][σ][C/X]=s[C/X]. Since C and R were arbitrary, this proves s[C/X][[A]]η for every pair required by the universal candidate.

The type-abstraction expansion lemma also requires normalization of s. Choose C=I:=Y.YY,R=SN0. The membership just proved and (CR1) give s[I/X]SN. Reflection through the closed type substitution gives sSN. Type-abstraction expansion now yields ΛX.s[[X.A]]η, which is exactly the transformed conclusion of F-All-I.

Exercise 5.14.

The replacement abandons item 3 of definition 9.47: an arrow is no longer interpreted as the full set VU. The selected family F(U,V) still supplies the functions needed to interpret abstraction and application, and at least one of these sets is a proper subset of VU. The cardinality step |T(X)|=|BBX| in theorem 5.40 is no longer available.

This semantic restriction changes none of the chapter’s syntactic results. Preservation remains true because its proof uses typing inversion and the two substitution lemmas, not a set interpretation. Strong normalization remains true because its proof uses reducibility candidates over syntax. Syntactic consistency remains true because it follows from normalization, subject reduction, and the normal-form shape lemma. Hence the exact answers are: preservation holds, normalization holds, and there is still no closed term of X.X. Reynolds’ theorem rules out one simultaneous package of set-theoretic clauses; it does not refute any of these local theorems.

Practical route.

The explicit System F checker of exercise 9.15 is built in appendix F; its context-formation guard, evidence replay, compatible reduction checks, and preserved mutation are recorded in appendix E.

Search the book

Type to search the local edition.