Lectures onType Theory
ch:quantitative-types: ch:quantitative-types
appendix sectionsolutions

ch:quantitative-types: ch:quantitative-types

exercise 54.1.

The outer function occurrence contributes 1. The inner application lies in an argument scaled by r, so the inner function occurrence contributes r. The input lies under both argument positions and contributes r2. Thus the grades are 1+r and r2. In the Boolean semiring, the function grade is true and the input grade is r; idempotent disjunction and conjunction cannot recover a call count.

exercise 54.2.

The premise of L-Prom must have a fully graded context, so y:A blocks promotion. From L-Var, derive y:Ay:A, use L-Der to get y:[A]1y:A, and apply rank-one promotion to conclude y:[A]1[y]:1A.

exercise 54.3.

Typing the redex ends with G-App from Δ,x:rAt:B and Θu:A, hence its context is Δ+rΘ. Graded substitution derives the same context for t[u/x]. This preserves a static annotation. No premise connects the semiring element to a measured number of machine steps or dynamic variable lookups.

exercise 54.4.

In the one-element semiring, 0=1. A constant body typed after zero weakening can therefore be abstracted at an arrow marked 1. A direct map to AB would demand that the bound variable occur linearly, but the constant body contains no occurrence. The grade 1 has lost exact-use meaning.

exercise 54.5.

Expanding the equations gives G[[2(AA)]]=(G[[AA]]2K)1K, where G[[AA]]=((G[[A]]1G[[A]])1K)1K. The grade 2 is on the continuation consuming the boxed payload. Removing either continuation changes the translated type and invalidates the typing induction.

exercise 54.6.

Changing the operation performed by p changes the index e on Te and the effect-composition premise for its bind. Changing the number or mode of uses of x changes r on Dr and the scalar multiplying its discharged context. Neither change determines the other.

exercise 54.7.

Let one location be targeted by two outgoing references, each with permission 1. Their total is 2, so the assignment does not satisfy the theorem’s incoming sum-one premise and is not a counterexample. It does destroy the desired unique full-permission state. Graded substitution computes context demand but has no heap-target relation summing all aliases to one location, so it cannot exclude the assignment.

exercise 54.9.

Put F=rAA. The source’s two application steps are f:1FGf:Ff:1FGf:Fx:1AGx:Af:1F,x:rAGfx:AGAppf:1+rF,x:r2AGf(fx):AGApp The direct translation inserts one promotion at each application: x:[A]1Lx:Ax:[A]rL[x]:rALProm The outer application promotes the translated inner application: f:[F]1,x:[A]rLL[[fx]]:Af:[F]r,x:[A]r2L[L[[fx]]]:rALProm The outer L-App adds its independent f:[F]1 to the second promotion’s f:[F]r. The two translated abstractions each use L-Let followed by L-Abs, giving LL[[λf.λx.f(fx)]]:1+rFr2AA.

exercise 54.10.

For function beta, expand CPS application, beta-reduce the outer continuation lambdas, apply the translated abstraction, and reach the translation of the substituted body. Modal beta passes the translated boxed payload to the let continuation before substituting it. Reductions underneath continuation lambdas are full-beta target steps, not source call-by-name positions.

exercise 54.11.

Let p return under effect e and let a discharged input be available at coeffect 2. Effect bind composes e with the continuation effect using the effect monoid. Duplicating the input scales its discharged context using the coeffect semiring. Writing ee and 2[Δ] on separate derivation lines prevents either coordinate from being mistaken for the other.

exercise 54.8.

If all references to a location have total permission 1 and one reference alone carries 1, then that reference is unique at that moment. A uniqueness attribute alone does not derive the fractional calculus’s multistep permission-sum invariant for new locations; heap compatibility and borrow safety are additional hypotheses.

Search the book

Type to search the local edition.