Lectures onType Theory
ch:capability-region-types: ch:capability-region-types
appendix sectionsolutions

ch:capability-region-types: ch:capability-region-types

exercise 50.1.

Choose outer ρ0 and fresh local ρ, and annotate letregion ρ in let x=1 at ρ in 2 at ρ0 end end. The body effect is {put(ρ),put(ρ0)}. The result is an integer at ρ0, and the empty initial TE does not mention ρ. Those are RI-Letregion’s freshness facts. The rule removes the local put effect, leaving {put(ρ0)}; it has no continuation-effect premise.

exercise 50.3.

Deleting the outer π0 from epairFirst returns the allocated pair, whose result type is int,int at ρ. Hence ρftv(τ), violating R-Letregion. Without that premise, evaluation could remove ρ and return an address into it.

exercise 50.2.

Initially M=Ψ={} and C=. A fresh-region step chooses ν, yielding M(ν)={}, Ψ(ν)={}, and C={ν1}. Pair allocation adds a fresh label with tuple type to Ψ(ν), but retains the unique capability. Projection uses the tuple entry and authority for ν. Deallocation consumes {ν1} and removes ν from M and Ψ, returning C to empty. A later projection cannot establish either the location typing ν.:τ or capability satisfiability for ν.

exercise 50.4.

Take a well-typed terminating run and its terminal state. Preservation keeps the terminal state well typed. Progress says a terminal expression is haltv for a word value v:int. Cap-Halt requires its current capability equal to . Capability cardinality preservation ensures that equality cannot erase a unique occurrence of a live region. Satisfiability then implies that the memory typing has no live region names. Canonical memory typing says a concrete memory realizing the empty memory typing is itself empty. Hence the terminal state is ({},haltv).

exercise 50.5.

Write the body of epairFirst as e, the outer meta-level continuation as k=xk;ek, and the body’s result parameter as x. The essential target shape is let newrgn ρ,xρ in CPS(e;x;let freergn xρ in apply(k,x)). Immediately after newrgn, the translation environment’s current capability and bound contain {ρ1}. The body effect translates to an absorbable capability under that bound. The continuation receives the body’s value while unique ρ is still available, consumes it at freergn, and invokes k under the old bound. The displayed equation with CapOf(ψ) remains true after deleting the discharged singleton; the fresh-region premise prevents k’s type or capability from mentioning ρ.

exercise 50.6.

L3 allocation returns an existential package containing Capρint and a duplicable pointer. Its swap step replaces that capability by Capρ(int×int) and returns the old integer; free consumes the repackaged capability and pointer. This is the card that owns strong update. Linear-region allocation extends ψ and returns a linear capability plus unrestricted handle; accesses thread the capability and freergn consumes it, as covered by target safety. Monadic runRGN pushes an empty region stack, allocates and reads within it, discards it, and returns 7. Its rank-2 result type cannot mention the fresh region, so this card owns lifetime hiding. None of the latter two claims imports L3’s strong-update theorem.

Search the book

Type to search the local edition.