Lectures onType Theory
ch:modal-effect-types: ch:modal-effect-types
appendix sectionsolutions

ch:modal-effect-types: ch:modal-effect-types

Exercise 33.1.

Replacement gives [{write}](F)={write}. Extension gives write(F)={write,read}. Composition is left to right, so ([{write}]read)(F)={read,write}. The latter two retain read; absolute replacement alone does not.

Exercise 33.2.

Progress may classify K[doU] as normal at , because its definition asks only for e. The usual empty-effect corollary can no longer remove that alternative, so the term can be stuck on an unhandled request. This countermodel attacks the corollary from progress; it does not contradict the separately stated preservation conclusion.

Exercise 33.3.

Left-to-right composition gives [E]=[,E]. The return variable has type [,E]A; the resumption has type [E](BB). The handler rule additionally requires [E]id@F and [E]([E][E])@F. Since [E][E]=[E], both obligations reduce to the absolute-modality transformation premises at F.

Exercise 33.4.

The source function translates to mod[,E](λxAr.dox):[,E](ArBr). Its application to V is letmod[,E]f=λ,Ex.MrinfVr. The absolute box runs the body at exactly ,E. Replacing it by would retain every ambient effect, so it would not encode the source arrow’s exact row.

Exercise 33.5.

Writing T=11, the translated block begins Λf^.modf^(λx1.λf[f^]Tc.letmod[f^]f~=finf~x). Thus the formal capability becomes an effect variable, the block body is boxed by an extension modality, its block argument is boxed absolutely at that effect variable, and elimination records the same absolute modality on the hatted callable variable.

Exercise 33.6.

Typing uses the binding freshness convention when M-Local extends the local signature: f must avoid the translated context so that substituting it for f^ captures no pre-existing label. This is alpha-freshness of the local binder, not an extra side condition on the rule. Operational preservation uses freshness when the generated runtime instance context extends with one new label and when substitution identifies the tracked effect variable with that unique label. Reusing an active label aliases two dynamic instances; the instance-context extension and local-label case would then lose their inversion premise even if the signatures agree.

Exercise 33.7.

Write Hr=handler{askprreturnp}. Its row translation is Hrr=mod[](λt.handle[](letmod[ask]t=tint())with{returnxletmod[ask]x=xinx,askprp}). The handled thunk has type [ask](11); its absolute box is the source row. The row proof uses that Rsc retains duplicate labels while commuting adjacent distinct labels, so the handler case removes the selected occurrence without contracting the residual row.

For the System-C term, let G translate the body after abstracting the tracked block: G=Λf^.modf^(λf[f^](11).letmod[f^]f~=finletmodk=f~ink()). Its handler translation has the modal skeleton localf:11inletmodfg=Gfinhandle[](g(mod[f](mod(λx1.dofx))))with{returnxletmod[f]x=xinx,fprp}. Here f^, f^, [f], and f are respectively the quantified effect variable, extension modality, absolute box on the operation implementation, and fresh runtime label. The capability proof uses freshness of f and simultaneous preservation for blocks and computations; neither premise is supplied by the row proof. Both source terms return unit after one handled request, but their target terms are related only by this chosen observation, not by a proved source equivalence.

Exercise 33.8.

The proved span is FεMet[Rsc],CMet[S]. The first domain has duplicate-preserving rows and first-class functions; the second has sets and second-class blocks. Their steps also use different runtime configurations. A source-to-source compiler would require an explicit term and type translation plus a relation between observations and a forward simulation (or another operational-correctness argument). Neither target translation supplies an inverse with which to manufacture these data.

Exercise 33.9.

Introduction checks the identity function under lock([E]F) at E, yielding mod[E](λx.x):[E](AA)@F. Elimination with outer modality id binds h:[E]F(AA). Using h after no further lock requires [E]id@F. If h instead has a type of pure kind, M-Aux-Abs discharges the auxiliary premise of M-Var without a modality transformation.

Exercise 33.10.

For application, the induction hypotheses type the function at [E](AB) and the argument at A. Rule M-LetMod eliminates the box, after which ordinary application yields B@E.

For the handler, the translated thunk has [,E](1A), its returned value has [,E]A, and its resumption has [E](BA), matching the translation of the source continuation arrow. A source handled-request step substitutes the parameter and rehandled continuation. The target first performs modal beta, then the Met operation step, and finally modal beta in the translated clause; the resulting term is the translation of the source reduct. This is a nonempty finite sequence, as required by the conclusion.

Exercise 33.11.

The simultaneous hypotheses translate values, blocks, and computations. In the block case, introduce one effect variable f^j per formal block, box the function under f^¯, and eliminate each formal’s [f^j] box before applying the computation hypothesis. In the call case, if actual Qj has capability set Cj, instantiate f^j:=Cjc. The target result type is then Bc[Cjc/f^j], equal by the translation-substitution lemma to B[Cj/fj]c. Eliminating the relative box places the call at the union of the callee and actual capability effects.

Exercise 33.12.

  1. Theorem 33.2 plus the first validity condition proves the claim.

  2. No theorem proves it. The two translations form a span, and neither has a proved inverse.

  3. The claim fails because the METL artifact implements neither source translation; an implementation may pass its own examples while a proposed System-C encoder mishandles a block call.

  4. The claim fails because effect safety constrains stuck requests. Ownership noninterference constrains observations. Two safe programs may write different public values.

Search the book

Type to search the local edition.