Introduction
React is a JavaScript library that enables programmers to declaratively specify dynamic user interfaces (UIs). It is currently the most popular library for front-end web development [48 , 49 ] , and has influenced the development of other widespread libraries and frameworks, such as Preact and NextJS. Through the React Native project, React-style programming is also now common in mobile app development.
React programmers structure UIs in terms of components , which are functions that compute and return HTML-like elements . Although basic components are pure functional specifications, React provides the useState function to persist some internal state across rerenders (re-evaluations) of components. The useState construct is one of a number of primitive hooks , which “hook into” React’s runtime: in this case, useState coordinates with the runtime to inject the most recent state value, and to rerender the necessary components when that value is updated.
We develop a formal understanding of this widely-used but under-studied state mechanism, which we name hook-indexed state . In prior work, Lee et al. [26 ] give a semantics for React, intended as a guide for React developers . In contrast, we study useState from a language designer ’s perspective. We examine how a language designer may integrate a version of hook-indexed state with static soundness guarantees into a reactive language. We also explore why a designer would consider hook-indexed state by relating it to standard ML-style state.
Soundness. To the novice React developer, useState may appear magically simple, but they will inevitably discover that what underlies this magic is in fact a fragile contraption, held together only by duct-tape invariants. If useState is placed inside a conditional statement, the program will crash. Updating state during a render may lead to an infinite rerender. To avoid such problems as these, programmers must obey the “Rules of React” [36 ] , a set of React-specific maxims (e.g. “only
Authors’ Contact Information: Toby Ueno, toby.ueno@ed.ac.uk, The University of Edinburgh, Edinburgh, UK; Ezra Cooper, ezra.cooper@ed.ac.uk, The University of Edinburgh, Edinburgh, UK; Simon Fowler, simon.fowler@glasgow.ac.uk, University of Glasgow, Glasgow, UK; Sam Lindley, sam.lindley@ed.ac.uk, The University of Edinburgh, Edinburgh, UK. call hooks at the top level”) that lead to bugs and unexpected behavior when broken, but which are not statically enforceable on the language level.1
We introduce a calculus, λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react , that captures the essence of hook-indexed state while abstracting away from the chaotic real-world semantics of JavaScript [21 ] and complicating orthogonal features/performance concerns of React [26 , 31 ] . We endow λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react with a novel type system, featuring lightweight effect typing and pseudo-linearity of pointers. Our type system captures and enforces the informal Rules of React that pertain to state.
Expressivity. The useState construct has an unorthodox dynamic context-dependent semantics. During the initial render of the component, it uses the provided argument as an initial value, but on successive renders, it must instead access some location on the heap [37 ] . This observation was first formalized by Lee et al. [26 ] , and is likewise modeled in our calculus λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react .
To elucidate the pros and cons of programming with useState, we consider what it takes to express hook-indexed state in terms of a more well-understood canonical model of state. We show by translation that the behavior of useState is expressible in terms of ML-style first-class references , which have a well-studied formalization [3 , 22 , 46 , 53 ] and are built-in to ML dialects such as OCaml [28 ] , F# [50 ] , and SML [40 ] . We define a calculus of first-class references, λ r e f r e a c t \lambda^{\mathrm{react}}_{\mathrm{ref}} λ ref react , and an encoding of λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react into λ r e f r e a c t \lambda^{\mathrm{react}}_{\mathrm{ref}} λ ref react which satisfies a tight operational correspondence [19 , 20 , 41 , 45 , 51 , 52 ] . The benefits and drawbacks of our translation are somewhat nuanced. Our encoding admits a compositional definition, and is local in that unrelated constructs are unaffected. However, it leads to code duplication and breaks abstraction, which shows an advantage of useState as a feature.
Contributions. Our primary contributions are summarized as follows.
We propose three reactive calculi: λ p u r e r e a c t \lambda^{\mathrm{react}}_{\mathrm{pure}} λ pure react (§ 3 ), λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react (§ 5 ), and λ r e f r e a c t \lambda^{\mathrm{react}}_{\mathrm{ref}} λ ref react (§ 7 ). Each has a sound type system and a small-step operational semantics.
λ p u r e r e a c t \lambda^{\mathrm{react}}_{\mathrm{pure}} λ pure react is stateless , and as such can only represent static elements, but is equipped with the machinery necessary to support stateful components.
λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react extends λ p u r e r e a c t \lambda^{\mathrm{react}}_{\mathrm{pure}} λ pure react with hook-based stateful components, in the style of React. Its type system notably features a lightweight effect system and a pseudo-linear pointer context.
λ r e f r e a c t \lambda^{\mathrm{react}}_{\mathrm{ref}} λ ref react extends λ p u r e r e a c t \lambda^{\mathrm{react}}_{\mathrm{pure}} λ pure react with reference-based stateful components, in the style of ML.
We define a translation from λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react to λ r e f r e a c t \lambda^{\mathrm{react}}_{\mathrm{ref}} λ ref react (§ 8 ), prove that the translation is type-preserving, and show a tight operational correspondence between the two calculi.
We demonstrate that λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react offers a scalable foundation by sketching three extensions: reconciliation, the useEffect hook, and custom hooks (§ 9 ).
Section 2 contains a more detailed exposition of React and useState and an overview of our findings. Section 8 surveys related work and Section 9 concludes.
Overview
Programming with React
React programmers structure UIs in terms of components , which are ordinary JavaScript functions that return elements . Elements are datatypes that specify HTML: they consist of text literals, tagged nodes (e.g. <div>, <p>), and components themselves. A complete program consists of a single root element that is rendered by the React runtime.
The Hello component below takes one parameter, name, and formats it into an element. We write this element as pseudo-HTML directly in JavaScript via the JSX syntax extension [38 ] . We may then use Hello in other components: the Main component below uses Hello twice with different1 : React has a linter plugin [33 ] that can help catch Rule violations but which, as a linter, cannot guarantee soundness. parameters. If we designate Main as the root of our program, React’s runtime will instantiate the component by evaluating it and its subcomponents, yielding the HTML on the right.
const Hello = ({name}) => {
const s = "Hello, ";
return (
<p>{s + name + "!"}</p>
);
}
const Main = () => {
return (<div class="foo">
<Hello name="reader" />
<Hello name="world" />
</div>);
}
(Rendered HTML)
<div class="foo">
<p>"Hello, reader!"</p>
<p>"Hello, world!"</p>
</div>
The above program is entirely static as it is unchanged by user input. The power of React lies in how the system dynamically responds to events. In this paper, we primarily focus on a single kind of event, clicks , although our system easily extends to others (following e.g. [15 ] ).
React supports primitive event handlers that can be attached to tags. We can provide the onClick attribute with an event handler function, which the runtime executes whenever the <div> is clicked. However, for these event handlers to affect the output of a React application, components must maintain state that event handlers can update. How do we model this state? JavaScript features mutable variables, introduced via the let keyword, but these cannot concisely capture the desired semantics. As a running example, consider a counter that displays its current value and, when clicked, increments that value. If we model this value as a local mutable variable, as in CounterLocal below, then x remains 0 after a click. This is because React rerenders the component by rerunning the function, rebinding x to its initial value.
const CounterLocal = () => { let x = 0; return (<div onClick={() => x = x + 1}>{x}</div>); }
We can persist the state across rerenders by hoisting x outside the function body, making it global.
let x = 0; const CounterGlobal = () => { return (<div onClick={() => x = x + 1}>{x}</div>); }
Alas, this style breaks when we instantiate the component multiple times. Updating x affects all instances of CounterGlobal, but each counter instance should maintain its own independent state.
React’s solution is the primitive useState hook, which coordinates with the runtime to maintain a local state cell across rerenders of the same component instance. The hook is parameterized by the initial state and returns both a value and a setter, the latter of which triggers a rerender when invoked. Upon rendering, useState returns the most recent state value. A correct implementation of a counter using useState is given by component Counter below: we can instantiate Counter in multiple places, and each will have its own local state value that persists across rerenders.
const Counter = () => { const [x, setX] = useState(0);
return (<div onClick={() => setX (x + 1)}>{x}</div>); }
Local State, by Hook or by Crook
Hooks such as useState are superficially simple, but beneath the veneer lie complex and fragile internals. Programmers must adhere to the statically unenforceable Rules of React [36 ] , lest they encounter one of many program-breaking pitfalls—we examine two of these pitfalls—inconsistent hook evaluation order and top-level setter calls —to see how useState leads to unexpected behavior.
Evaluation Order. Consider the following OutOfOrder code.
1 const OutOfOrder = () => { const [x, setX] = useState(true);
2 if (x) { const [y, setY] = useState(0); }
3 const [z, setZ] = useState("foo"); ...
On the first render, all three useState calls bind initial values true , 0, and "foo" to x, y, and z, respectively. However, if x is set to false and the component is rerendered, then z will be bound to 0. In React, useState calls are identified by their evaluation order with respect to a component instance, e.g. the first useState call sets/retrieves from the same place on the heap [37 ] . We refer to React’s state mechanism as hook-indexed state because the location of the state cell is indexed by the evaluation order of the corresponding hook. In OutOfOrder, the second such call is made at line 2 on the first render, but at line 3 on the second render, leading to the described bug.
To avoid this bug, React programmers must ensure that their hooks always respect the same evaluation order during each run of their components. This evaluation-order invariant is captured by the top-level restriction of the Rules of React, which states that hooks should only be called at the top level of components, i.e. not nested inside of conditionals, loops, and so on2 . This restriction ensures that the execution order of all useState calls is consistent, thereby avoiding the above bug.
Top-Level Setter Calls. The state values returned from useState are immutable, and so must be set using the provided setter. This setter, however, does not work like a standard reference update, as evidenced by the following component.
const CounterTwo = () => { const [x, setX] = useState(0); setX (x + 2);
return (<div onClick=() => setX (x + 1)> {x} </div>); }
CounterTwo only differs from Counter by the addition of the call to setX (x + 2). One might quite naturally assume that x is rendered with value 2, whereas in fact CounterTwo will not terminate .
If React detects that a setter is invoked during rendering, it will immediately attempt to rerender the component. As the setter call in CounterTwo is evaluated unconditionally, React will attempt this rerender indefinitely. Intuitively, React does this because it wants to avoid rendering stale state , but this behavior may easily catch the novice React programmer off guard.
Another Rule of React states that components should be pure , in that they should not perform side effects (but may perform, for instance, local mutation). Interestingly, React’s notion of purity does not preclude calling a state setter: the guidelines only caution against doing so unconditionally [34 ] . As with the other Rules, this invariant must be manually verified by the programmer.
A Core Calculus of Hook-Indexed State
In § 5 , we propose a calculus, λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react , which captures the essence of hook-indexed state. We draw inspiration from the work of Lee et al. [26 ] , but where their system prioritizes semantic faithfulness to React in all its glory, we design our language around safety and (relative) simplicity. We introduce component bodies D D D , which are wrapped into values as component { D } \{D\} { D } . The grammar of component bodies is as follows, where V V V are values and M , N M,N M , N are computations:
D : : = val V ∣ let x = M in D ∣ let x , x s e t = useState V in D D ::= \operatorname{val}\ V \mid\operatorname{let}\ x = M\ \operatorname{in}\ D \mid\operatorname{let}\ x,x_{\mathrm{set}} = \operatorname{useState}\ V\ \operatorname{in}\ D D ::= val V ∣ let x = M in D ∣ let x , x set = useState V in D
Bodies extend computations with the useState construct. This body-computation distinction syntactically enforces the top-level restriction: the prior OutOfOrder example, for instance, is syntactically invalid , as if-statements can only take the form if V V V then M M M else N N N , and not if V V V then D 1 D_1 D 1 else D 2 D_2 D 2 .
To give useState a small-step operational semantics, we must provide two key pieces of context.
We provide a pointer p p p to a component instance’s memory, which contains its state. We need this pointer to distinguish the state of different instantiations of the same component .
We provide a phase ϕ \phi ϕ , which is either Init (initial phase) or Succ (successor phase). When ϕ = I n i t \phi= \mathrm{Init} ϕ = Init , useState initializes state, and when ϕ = S u c c \phi= \mathrm{Succ} ϕ = Succ , useState retrieves state.
We define the body semantics via step judgment ⇝ p b \leadsto^{\mathrm{b}}_{p} ⇝ p b , which captures this context. Consider the first useState call in Counter. In λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react , that line evaluates as follows in the Init phase:
H 0 ; let x , x s e t = useState ℓ 0 in D ⇝ p I n i t D [ 0 / x , x s e t ℓ / x s e t ] ; H 1 \mathcal{H}_0; \operatorname{let}\ x,x_{\mathrm{set}} = \operatorname{useState}^{\ell}\ 0\ \operatorname{in}\ D \leadsto^{\mathrm{Init}}_{p} D[0/x,x_{\mathrm{set}}^{\ell}/x_{\mathrm{set}}]; \mathcal{H}_1 H 0 ; let x , x set = useState ℓ 0 in D ⇝ p Init D [ 0/ x , x set ℓ / x set ] ; H 1
where H 0 \mathcal{H}_0 H 0 is the initial heap and set p ℓ \operatorname{set}^{\ell}_{p} set p ℓ is a setter for the ℓ \ell ℓ th evaluated hook at pointer p p p . (For convenience, we annotate useState constructs with unique labels ℓ \ell ℓ in an elaboration pass: our syntax guarantees that these labels correspond to evaluation order.) The initial value 0 is bound to x x x , and is also saved on the updated heap H 1 \mathcal{H}_1 H 1 . We also bind a setter to x s e t x_{\mathrm{set}} x set .
Suppose later we evaluate a setter, perhaps in the event handler for Counter. Doing so is an ordinary computation, and does not require the extra context given to bodies in the step judgment.
H 1 ; set p ℓ ⇝ val ( ) ; H 2 \mathcal{H}_1 \mathrel{;} \operatorname{set}^{\ell}_{p} \leadsto\operatorname{val} () \mathrel{;} \mathcal{H}_2 H 1 ; set p ℓ ⇝ val ( ) ; H 2
Now, say we rerender Counter, which requires us to evaluate its body in the Succ phase. We disregard the initial value and look up the most recent value in H 2 \mathcal{H}_2 H 2 , which is now 1, and bind it to x x x .
H 2 ; let x , x s e t = useState 0 ℓ in D ⇝ p S u c c D [ 1 / x , set p ℓ / x s e t ] ; H 2 \mathcal{H}_2 \mathrel{;} \operatorname{let} x, x_{\mathrm{set}} = \operatorname{useState}^{\ell}_{0} \operatorname{in} D \mathrel{\leadsto^{\mathrm{Succ}}_{p}} D[1/x,\operatorname{set}^{\ell}_{p}/x_{\mathrm{set}}] \mathrel{;} \mathcal{H}_2 H 2 ; let x , x set = useState 0 ℓ in D ⇝ p Succ D [ 1/ x , set p ℓ / x set ] ; H 2
The Typing Rules of React
The syntactic restrictions of λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react get us only so far towards safety: for instance, the Succ phase becomes stuck at a useState call if the corresponding location on the heap has not yet been initialized. To statically eliminate such problems, we introduce a type system to λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react (§ 5.2 ) and prove it sound. Here we briefly survey its salient features.
Every Body Has a Type. The type of a body is a record L \mathcal{L} L that maps useState labels ℓ \ell ℓ to value types A A A . For example, in the typing derivation for Counter, an instance of rule TB-State records that the state at label ℓ \ell ℓ will have type Int once useState is executed (where ∅ \varnothing ∅ is the empty record):
Γ ⊢ 0 : I n t Γ , x : I n t , x s e t : ( I n t ⟶ M u t 1 ) ⊢ D : ∅ Γ ⊢ let x , x s e t = useState 0 ℓ in D : ( ℓ : I n t ) T B - S t a t e \frac{\Gamma\vdash0 : \mathrm{Int} \qquad\Gamma, x : \mathrm{Int}, x_{\mathrm{set}} : (\mathrm{Int} \mathrel{\stackrel{\mathrm{Mut}}{\longrightarrow}} 1) \vdash D : \varnothing}{\Gamma\vdash\operatorname{let} x, x_{\mathrm{set}} = \operatorname{useState}^{\ell}_{0} \operatorname{in} D : (\ell: \mathrm{Int})}
\quad\mathrm{TB\text{-}State} Γ ⊢ let x , x set = useState 0 ℓ in D : ( ℓ : Int ) Γ ⊢ 0 : Int Γ , x : Int , x set : ( Int ⟶ Mut 1 ) ⊢ D : ∅ TB - State
When a useState construct is evaluated, it disappears from the body, and so a body’s type changes during evaluation. Once a body reduces to a value, it has type ∅ \varnothing ∅ . (We defer discussion of the Mut annotation on the function arrow until later in this section.)
The Two-Body Problem. The type of a component instance’s memory is also given by L \mathcal{L} L . Each instance memory contains a state store σ \sigma σ that maps labels ℓ \ell ℓ to values V V V . If ℓ : A ∈ L \ell: A \in\mathcal{L} ℓ : A ∈ L , then V V V has type A A A , as expected. For a body with type L 1 \mathcal{L}_1 L 1 and an instance memory with type L 2 \mathcal{L}_2 L 2 , we compare L 1 \mathcal{L}_1 L 1 and L 2 \mathcal{L}_2 L 2 to obtain an invariant that depends on ϕ \phi ϕ as follows:
When ϕ = I n i t \phi= \mathrm{Init} ϕ = Init , we maintain that L 1 ∪ L 2 \mathcal{L}_1 \cup\mathcal{L}_2 L 1 ∪ L 2 is constant. All state labels ℓ \ell ℓ in dom ( L 1 ∪ L 2 ) \operatorname{dom}(\mathcal{L}_1 \cup\mathcal{L}_2) dom ( L 1 ∪ L 2 ) are either on the heap (if ℓ ∈ dom L 2 \ell\in\operatorname{dom}\mathcal{L}_2 ℓ ∈ dom L 2 ) or to be initialized (if ℓ ∈ dom L 1 \ell\in\operatorname{dom}\mathcal{L}_1 ℓ ∈ dom L 1 ). Once the body has reduced to a value, we have L 1 = ∅ \mathcal{L}_1 = \varnothing L 1 = ∅ , and the component instance is fully initialized .
When ϕ = S u c c \phi= \mathrm{Succ} ϕ = Succ , we maintain that L 1 ⊆ L 2 \mathcal{L}_1 \subseteq\mathcal{L}_2 L 1 ⊆ L 2 . All labels in the body must already be on the heap so that we can safely retrieve them via useState.
We illustrate the Init-phase invariant by returning to our Counter example. We zoom in from the entire heap H \mathcal{H} H to just the relevant store σ \sigma σ , which begins empty, and so has type ∅ \varnothing ∅ .
∅ ; let x , x s e t = useState 0 ℓ in D ⇝ p I n i t D [ 0 / x , set p ℓ / x s e t ] ; ℓ ↦ 0 \varnothing\mathrel{;} \operatorname{let} x, x_{\mathrm{set}} = \operatorname{useState}^{\ell}_{0} \operatorname{in} D \mathrel{\leadsto^{\mathrm{Init}}_{p}} D[0/x,\operatorname{set}^{\ell}_{p}/x_{\mathrm{set}}] \mathrel{;} \ell\mapsto0 ∅ ; let x , x set = useState 0 ℓ in D ⇝ p Init D [ 0/ x , set p ℓ / x set ] ; ℓ ↦ 0
After a step, the store ℓ ↦ 0 \ell\mapsto0 ℓ ↦ 0 now has type ( ℓ : I n t ) (\ell: \mathrm{Int}) ( ℓ : Int ) , but the body D D D has type ∅ \varnothing ∅ . Although the types have changed, their union , which was our invariant, has not. Now that all state cells in Counter have been initialized, it is safe to rerender Counter, i.e., to evaluate its body in the Succ phase. This also follows from our typing invariants. To begin Succ-phase evaluation, we require that L 1 ⊆ L 2 \mathcal{L}_1 \subseteq\mathcal{L}_2 L 1 ⊆ L 2 , which is true in this instance: both are equal to ( ℓ : I n t ) (\ell: \mathrm{Int}) ( ℓ : Int ) .
Every Instance Has a Phase. We embed body evaluation into normal computation via the runtime construct [ D 0 ] ⇓ p ϕ D [D_0] \mathrel{\Downarrow^{\phi}_{p}} D [ D 0 ] ⇓ p ϕ D , read as “initial body D 0 D_0 D 0 has evaluated to D D D at phase ϕ \phi ϕ and pointer p p p .” When ϕ = I n i t \phi= \mathrm{Init} ϕ = Init , evaluating this computation may set some memory at p p p , as described above. Now, consider the following computation, which initializes D D D twice at p p p .
let y = ⌈ D 0 ⌉ ↓ p I n i t ( let x , x s e t = u s e S t a t e ℓ 0 in … ) in ⌈ D 0 ⌉ ↓ p I n i t ( let x , x s e t = u s e S t a t e ℓ 1 in … ) \begin{aligned}
\text{let } y = \left\lceil D_0 \right\rceil\mathrel{\downarrow_{p}^{\mathrm{Init}}} \left(\text{let } x, x_{\mathrm{set}} = \mathrm{useState}^{\ell} 0 \text{ in } \ldots\right) \text{ in}\\
\left\lceil D_0 \right\rceil\mathrel{\downarrow_{p}^{\mathrm{Init}}} \left(\text{let } x, x_{\mathrm{set}} = \mathrm{useState}^{\ell} 1 \text{ in } \ldots\right)
\end{aligned} let y = ⌈ D 0 ⌉ ↓ p Init ( let x , x set = useState ℓ 0 in … ) in ⌈ D 0 ⌉ ↓ p Init ( let x , x set = useState ℓ 1 in … )
Once the first initialization is complete, we expect that the state store contains value 0 at label ℓ \ell ℓ , and that this remains unchanged unless a setter is called. However, the second initialization will overwrite the first, leading to unexpected behavior. We thus choose to forbid reinitialization and guarantee that every component instance is initialized exactly once .
To enforce this restriction, we introduce a phase context Φ \Phi Φ that maps pointers p p p to phases ϕ \phi ϕ . We define a non-standard context merging relation Z \mathrel{\mathbin{\mathsf{Z}}} Z on Φ \Phi Φ : we treat pointers with ϕ = I n i t \phi= \mathrm{Init} ϕ = Init linearly, whereas pointers with ϕ = S u c c \phi= \mathrm{Succ} ϕ = Succ are unrestricted. The typing rule TC-EvalI for construct ⌈ D 0 ⌉ ↓ p ϕ D \left\lceil D_0 \right\rceil\mathrel{\downarrow_{p}^{\phi}} D ⌈ D 0 ⌉ ↓ p ϕ D guarantees that p : I n i t p : \mathrm{Init} p : Init occurs in Φ \Phi Φ , meaning that no other computation in the derivation may refer to p p p in the phase context. The above expression is therefore untypeable (denoted by an ✗ \mathsf{✗} ✗ right of the conclusion), since we cannot merge the phase contexts Φ 1 \Phi_1 Φ 1 and Φ 2 \Phi_2 Φ 2 :
⋯ Γ ; Π ; Φ 1 ⊢ ⌈ D 0 ⌉ ↓ p ϕ D 1 : E l e m I n s t T C - E v a l I ⋯ Γ , y : E l e m I n s t ; Π ; Φ 2 ⊢ ⌈ D 0 ⌉ ↓ p ϕ D 2 : E l e m I n s t T C - E v a l I Γ ; Π ; Φ 1 Z Φ 2 ⊢ let y = ⌈ D 0 ⌉ ↓ p I n i t D 1 in ⌈ D 0 ⌉ ↓ p I n i t D 2 : E l e m I n s t ✗ T C - L e t \frac{
\begin{array}{c}
\cdots\qquad\Gamma; \Pi; \Phi_1 \vdash\left\lceil D_0 \right\rceil\mathrel{\downarrow_{p}^{\phi}} D_1 : \mathrm{ElemInst}
\quad\mathrm{TC\text{-}EvalI}
\\[4pt]
\cdots\qquad\Gamma, y : \mathrm{ElemInst} ; \Pi; \Phi_2 \vdash\left\lceil D_0 \right\rceil\mathrel{\downarrow_{p}^{\phi}} D_2 : \mathrm{ElemInst}
\quad\mathrm{TC\text{-}EvalI}
\end{array}
}{
\Gamma; \Pi; \Phi_1 \mathbin{\mathsf{Z}} \Phi_2 \vdash\text{let } y = \left\lceil D_0 \right\rceil\mathrel{\downarrow_{p}^{\mathrm{Init}}} D_1 \text{ in } \left\lceil D_0 \right\rceil\mathrel{\downarrow_{p}^{\mathrm{Init}}} D_2 : \mathrm{ElemInst}\quad\mathsf{✗}
}
\quad\mathrm{TC\text{-}Let} Γ ; Π ; Φ 1 Z Φ 2 ⊢ let y = ⌈ D 0 ⌉ ↓ p Init D 1 in ⌈ D 0 ⌉ ↓ p Init D 2 : ElemInst ✗ ⋯ Γ ; Π ; Φ 1 ⊢ ⌈ D 0 ⌉ ↓ p ϕ D 1 : ElemInst TC - EvalI ⋯ Γ , y : ElemInst ; Π ; Φ 2 ⊢ ⌈ D 0 ⌉ ↓ p ϕ D 2 : ElemInst TC - EvalI TC - Let
Every Body is (Almost) Pure. Modeling the retrying behavior that results from top-level setter calls, as mentioned in § 2.2 , would significantly complicate our semantics for no real gain. We regard such programs as ill-behaved3 , and we introduce a small effect system to rule them out. We have only two effects in λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react : Pure for pure computations and Mut for those that may modify the heap. In particular, setters s e t p ℓ \mathrm{set}_{p}^{\ell} set p ℓ have type A → M u t 1 A \mathrel{\xrightarrow{\mathrm{Mut}}} 1 A Mut 1 . The typing rule TB-Let for bodies, which allows us to introduce arbitrary computations, requires these computations to be Pure, which prevents us from invoking the setter inside of a body. For instance, the following derivation fails:
Γ ; Π ; ∅ ⊢ s e t p ℓ : I n t → M u t 1 T V - S e t t e r ⋯ Γ ; Π ; ∅ ⊢ s e t p ℓ x : 1 ! M u t T C - A p p Γ ; Π ⊢ let ( ) = s e t p ℓ x in ⋯ : L ✗ T B - L e t \frac{
\begin{array}{c}
\Gamma; \Pi; \varnothing\vdash\mathrm{set}_{p}^{\ell} : \mathrm{Int} \mathrel{\xrightarrow{\mathrm{Mut}}} 1
\quad\mathrm{TV\text{-}Setter}
\\[4pt]
\cdots\qquad\Gamma; \Pi; \varnothing\vdash\mathrm{set}_{p}^{\ell}\ x : 1\ !\ \mathrm{Mut}
\quad\mathrm{TC\text{-}App}
\end{array}
}{
\Gamma; \Pi\vdash\text{let } () = \mathrm{set}_{p}^{\ell}\ x \text{ in } \cdots: \mathcal{L}\quad\mathsf{✗}
}
\quad\mathrm{TB\text{-}Let} Γ ; Π ⊢ let ( ) = set p ℓ x in ⋯ : L ✗ Γ ; Π ; ∅ ⊢ set p ℓ : Int Mut 1 TV - Setter ⋯ Γ ; Π ; ∅ ⊢ set p ℓ x : 1 ! Mut TC - App TB - Let
Setters may, as expected, be used in event handlers, which have no such effect restriction.
Putting useState in Other Terms
Having outlined a well-behaved fragment of λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react , we are now ready to consider the expressive power of hook-indexed state. To this end, we seek to define a translation from λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react into some other calculus that lacks useState. We argue that this problem is non-trivial in that, to the best of our knowledge, the behavior of useState is not well-captured by any known model of persistent state in UI programming. We identify two particular features of useState that lead to this difficulty:
React components interleave initialization with ordinary computation. This prevents us from straightforwardly “decomposing” a component into its state and pure functions that update and render the state, in the style of e.g. λ M V U \lambda_{\mathrm{MVU}} λ MVU [15 ] or the reactive document calculus [6 ] .
During component evaluation, some useState constructs will have been initialized while others will not. Representing the state of a component as a single value is therefore awkward to do in a type-safe way: we could, for instance, declare every field in the value as optional during initialization, and then (somehow) guarantee that all fields are non-null once initialization is complete. (This also precludes adapting the React implementation, which models state as a dynamically typed list and only “enforces” safety via The Rules [37 ] .)
In light of these considerations, we demonstrate that useState can be expressed in terms of a language λ r e f r e a c t \lambda_{\mathrm{ref}}^{\mathrm{react}} λ ref react with first-class references , which are well-understood and widely used in dialects of ML [28 , 40 , 50 ] . Drawing inspiration from the two phases of evaluation, our translation duplicates component bodies , once under each phase. For example, the component
let CounterSquare = component { let x, setX = useState 0 in let y = x * x in V }
is translated as follows:
1 let Counter = component λ().{
2 let rr = ref(false) in
3 let xLoc = ref(0) in
4 let x = !xLoc in
5 let setX = λy.(xLoc := y; rr := true) in
6 let y = x * x in
7 (λ().(
8 let x = !xLoc in
9 let setX = λy.(xLoc := y; rr := true) in
10 let y = x * x in
11 W
12 ), rr, W) }
We leave the return value V V V and its translation W W W abstract for conciseness. We use monospaced font for example λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react and λ r e f r e a c t \lambda_{\mathrm{ref}}^{\mathrm{react}} λ ref react code.
The outermost function corresponds to the initial phase , whereas the inner function (returned by the outer one) represents the successor phase . Lines 3–5 and 8–9 of the target are the translations of useState in each phase. In the initial phase, we initialize a reference, which is crucially captured by the successor phase, wherein we access that same reference . Setters are translated as functions that set their associated reference, but they also flip a “rerender flag” rr, which is declared at the top of a component and is returned by the initial phase.
We prove that the translation between λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react and λ r e f r e a c t \lambda_{\mathrm{ref}}^{\mathrm{react}} λ ref react preserves both types and operational semantics . Furthermore, the translation is local in the sense that it only performs nontrivial work on components, bodies, and setters. For readability, we do not formulate it compositionally , but it easily admits a compositional definition.
Not all is perfect with the translation. Writing components in the style of the translation is cumbersome due to the duplication of code: in the above example, lines 6 and 10 both mirror the same expression let y = x * x from the source, but must be in both phases to maintain the semantics. Furthermore, the translation leaks the abstraction : for example, a programmer must now manually control the rerender flag, whereas in λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react , the flag is hidden neatly behind the declarative interface of useState.
Lambda-React-Pure: A Core Calculus for Stateless Reactivity
We present λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react , an extension of the simply-typed lambda calculus with elements and lightweight reactivity . λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react has no state, and so can only model static elements: nevertheless, we include state-related machinery (such as events and handlers) as λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react serves as a basis for λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react and λ r e f r e a c t \lambda_{\mathrm{ref}}^{\mathrm{react}} λ ref react .
Syntax
We present λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react ’s syntax below. Runtime-only syntax that is not intended to be written directly by the programmer is highlighted in gray: we call the remainder programmer-level . We adopt Barendregt’s variable convention [4 ] and identify terms up to α \alpha α -equality. We formulate λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react in a fine-grain call-by-value (FGCBV) style [29 ] , with a syntactic distinction between values and computations , and where intermediate computations must be explicitly let-bound: this style simplifies the metatheory by restricting where nested computations can occur. We can straightforwardly elaborate a more standard nested calculus into FGCBV through let-insertion.
Types A , B : : = 1 ∣ S t r ∣ B o o l ∣ A → B ∣ A × B ∣ L i s t A ∣ E l e m e n t ∣ A t t r ∣ E l e m I n s t Type context Γ : : = ∅ ∣ Γ , x : A Values V , W : : = x ∣ ( ) ∣ s ∣ t r u e ∣ f a l s e ∣ λ x . M ∣ ( V , W ) ∣ [ ] ∣ V : : W ∣ attr ( V , W ) ∣ onClick V ∣ text V ∣ tag ( V , W ) ∣ textInst V ∣ tagInst i d ( V , W ) Computations M , N : : = val V ∣ let x = M in N ∣ V W ∣ if V then M else N ∣ fst V ∣ snd V ∣ fold V 1 V 2 V 3 ∣ init V ∣ click i d V ∣ runClick V ∣ update V \begin{aligned}
\text{Types } A, B &::= 1 \mid\mathrm{Str} \mid\mathrm{Bool} \mid A \to B \mid A \times B \mid\mathrm{List}\ A \mid\mathrm{Element} \mid\mathrm{Attr} \mid\mathrm{ElemInst}\\
\text{Type context } \Gamma&::= \varnothing\mid\Gamma, x : A\\
\text{Values } V, W &::= x \mid() \mid s \mid\mathrm{true} \mid\mathrm{false} \mid\lambda x.M \mid(V,W) \mid[] \mid V :: W \mid\operatorname{attr}(V,W)\\
&\mid\operatorname{onClick}\ V \mid\operatorname{text}\ V \mid\operatorname{tag}(V,W) \mid\operatorname{textInst}\ V \mid\operatorname{tagInst}_{id}(V,W)\\
\text{Computations } M, N &::= \operatorname{val}\ V \mid\operatorname{let}\ x = M\ \operatorname{in}\ N \mid V\ W \mid\operatorname{if}\ V\ \operatorname{then}\ M\ \operatorname{else}\ N \mid\operatorname{fst}\ V \mid\operatorname{snd}\ V\\
&\mid\operatorname{fold}\ V_1\ V_2\ V_3 \mid\operatorname{init}\ V \mid\operatorname{click}_{id}\ V \mid\operatorname{runClick}\ V \mid\operatorname{update}\ V
\end{aligned} Types A , B Type context Γ Values V , W Computations M , N ::= 1 ∣ Str ∣ Bool ∣ A → B ∣ A × B ∣ List A ∣ Element ∣ Attr ∣ ElemInst ::= ∅ ∣ Γ , x : A ::= x ∣ ( ) ∣ s ∣ true ∣ false ∣ λ x . M ∣ ( V , W ) ∣ [ ] ∣ V :: W ∣ attr ( V , W ) ∣ onClick V ∣ text V ∣ tag ( V , W ) ∣ textInst V ∣ tagInst i d ( V , W ) ::= val V ∣ let x = M in N ∣ V W ∣ if V then M else N ∣ fst V ∣ snd V ∣ fold V 1 V 2 V 3 ∣ init V ∣ click i d V ∣ runClick V ∣ update V
Variables x Strings s Identifiers i d \text{Variables }x \qquad\text{Strings }s \qquad\text{Identifiers }id Variables x Strings s Identifiers i d
Types. Standard types include the unit type 1 1 1 , strings S t r \mathrm{Str} Str , booleans B o o l \mathrm{Bool} Bool , functions A 1 → A 2 A_1 \to A_2 A 1 → A 2 , products A 1 × A 2 A_1 \times A_2 A 1 × A 2 , and lists L i s t A \mathrm{List}\ A List A . The Element type denotes decorated trees of strings (e.g. HTML, XML), and Attr is the type of those decorations. ElemInst represents the realization of an element, to be generated by the runtime from an element: alternatively, we may think of elements as specifications of instances. A single Element may be realized into multiple distinguishable ElemInsts.
Values. Values include variables (ranged over by x x x ), the unit value, strings (ranged over by s s s ), booleans, λ \lambda λ -abstractions, pairs, and list constructors, all of which are entirely standard. attr ( V , W ) \operatorname{attr}(V,W) attr ( V , W ) denotes a purely cosmetic attribute (given by a key-value pair of strings), whereas onClick V \operatorname{onClick}\ V onClick V attaches an event handler V V V to its parent element. The constructors text and tag produce elements: text V V V embeds a string into an element, whereas tag ( V , W ) \operatorname{tag}(V,W) tag ( V , W ) contains a list of subelements W W W annotated with some attributes V V V (the tag name can be understood as a special attribute). The corresponding instance constructors are textInst and tagInst respectively, and are analogous except that tagInst carries an identifier , ranged over by i d id i d and generated at runtime.
Computations. The val construct treats a value as a pure computation, and computations are sequenced using let-binders. Constructs for application, conditionals, and pair projection are standard. The remaining computations model fragments of the runtime. init V V V realizes an element V V V into an instance. clicki d _{id} i d V V V searches an instance V V V for a node with identifier i d id i d , and if found, runs any onClick event handlers. runClick V V V runs an attribute V V V ’s handler if it exists. update V V V reinitializes any instances with outdated state. (In λ p u r e r e a c t \lambda^{\mathrm{react}}_{\mathrm{pure}} λ pure react , no instances have state, and so update V V V is a no-op, but including it here makes our lives easier when considering different implementations of stateful components in § 5.3 and § 7.2 .)
Canonicity. These “runtime constructs” are prima facie ad-hoc, but they can easily be expressed in terms of more standard constructs. Elements, attributes, and instances are all inductive datatypes, so we could define our runtime in terms of folds/destructors on these datatypes. init is a fold on elements, runClick destructs an attribute, and clicki d _{id} i d and update are folds on instances. For simplicity, we choose to explicitly define only the machinery necessary for our purposes.
Syntactic sugar. For brevity, we use the following abbreviations in presentation (for all languages):
We use CBV syntax instead of strict FGCBV, i.e. we allow for nested computations and often elide val, assuming a (standard) elaboration pass that performs let-insertion appropriately;
we allow for n-ary tuple-deconstruction (e.g. let x , y , z = V x,y,z = V x , y , z = V in M M M ), assuming a standard desugaring into multiple pair destructurings,
and we use the following abbreviations:
M ; N ≜ let x = M in N ( for x ∉ fv ( N ) ) λ ( ) . M ≜ λ x . M ( for x ∉ fv ( M ) ) map V W ≜ fold ( λ x . λ a c c . V x : : a c c ) [ ] W iter V W ≜ fold ( λ x . λ ( ) . V x ) ( ) W inits V ≜ map ( λ x . init x ) V clicks i d V ≜ iter ( λ x . click i d x ) V runClicks V ≜ iter ( λ x . runClick x ) V updates V ≜ map ( λ x . update x ) V \begin{aligned}
M ; N &\triangleq\operatorname{let}\ x = M\ \operatorname{in}\ N \qquad&&(\text{for }x \notin\operatorname{fv}(N))\\
\lambda().M &\triangleq\lambda x.M \qquad&&(\text{for }x \notin\operatorname{fv}(M))\\
\operatorname{map}\ V\ W &\triangleq\operatorname{fold}\ (\lambda x.\lambda acc.Vx :: acc)\ []\ W\\
\operatorname{iter}\ V\ W &\triangleq\operatorname{fold}\ (\lambda x.\lambda().Vx)\ ()\ W\\
\operatorname{inits}\ V &\triangleq\operatorname{map}\ (\lambda x.\operatorname{init}\ x)\ V\\
\operatorname{clicks}_{id}\ V &\triangleq\operatorname{iter}\ (\lambda x.\operatorname{click}_{id}\ x)\ V\\
\operatorname{runClicks}\ V &\triangleq\operatorname{iter}\ (\lambda x.\operatorname{runClick}\ x)\ V\\
\operatorname{updates}\ V &\triangleq\operatorname{map}\ (\lambda x.\operatorname{update}\ x)\ V
\end{aligned} M ; N λ ( ) . M map V W iter V W inits V clicks i d V runClicks V updates V ≜ let x = M in N ≜ λ x . M ≜ fold ( λ x . λa cc . V x :: a cc ) [ ] W ≜ fold ( λ x . λ ( ) . V x ) ( ) W ≜ map ( λ x . init x ) V ≜ iter ( λ x . click i d x ) V ≜ iter ( λ x . runClick x ) V ≜ map ( λ x . update x ) V ( for x ∈ / fv ( N )) ( for x ∈ / fv ( M ))
Typing Rules for Values Γ ⊢ V : A \Gamma\vdash V : A Γ ⊢ V : A
x : A ∈ Γ Γ ⊢ x : A T V - V a r Γ ⊢ ( ) : 1 T V - U n i t V ∈ { t r u e , f a l s e } Γ ⊢ V : B o o l T V - B o o l Γ ⊢ s : S t r T V - S t r Γ , x : A ⊢ M : B Γ ⊢ λ x . M : A → B T V - L a m Γ ⊢ [ ] : L i s t A T V - N i l \frac{x : A \in\Gamma}{\Gamma\vdash x : A}\ \mathrm{TV\text{-}Var}
\qquad
\frac{}{ \Gamma\vdash() : 1}\ \mathrm{TV\text{-}Unit}
\qquad
\frac{V \in\{\mathrm{true},\mathrm{false}\}}{\Gamma\vdash V : \mathrm{Bool}}\ \mathrm{TV\text{-}Bool}
\qquad
\frac{}{\Gamma\vdash s : \mathrm{Str}}\ \mathrm{TV\text{-}Str}
\qquad
\frac{\Gamma, x : A \vdash M : B}{\Gamma\vdash\lambda x.M : A \to B}\ \mathrm{TV\text{-}Lam}
\qquad
\frac{}{\Gamma\vdash[] : \mathrm{List}\ A}\ \mathrm{TV\text{-}Nil} Γ ⊢ x : A x : A ∈ Γ TV - Var Γ ⊢ ( ) : 1 TV - Unit Γ ⊢ V : Bool V ∈ { true , false } TV - Bool Γ ⊢ s : Str TV - Str Γ ⊢ λ x . M : A → B Γ , x : A ⊢ M : B TV - Lam Γ ⊢ [ ] : List A TV - Nil
Γ ⊢ V : A Γ ⊢ W : L i s t A Γ ⊢ V : : W : L i s t A T V - C o n s Γ ⊢ V : A Γ ⊢ W : B Γ ⊢ ( V , W ) : A × B T V - P a i r Γ ⊢ V : S t r Γ ⊢ W : S t r Γ ⊢ a t t r ( V , W ) : A t t r T V - A t t r Γ ⊢ V : 1 → 1 Γ ⊢ o n C l i c k V : A t t r T V - O n C l i c k \frac{\Gamma\vdash V : A \quad\Gamma\vdash W : \mathrm{List}\ A}{\Gamma\vdash V :: W : \mathrm{List}\ A}\ \mathrm{TV\text{-}Cons}
\qquad
\frac{\Gamma\vdash V : A \quad\Gamma\vdash W : B}{\Gamma\vdash(V,W) : A \times B}\ \mathrm{TV\text{-}Pair}
\qquad
\frac{\Gamma\vdash V : \mathrm{Str} \quad\Gamma\vdash W : \mathrm{Str}}{\Gamma\vdash\mathrm{attr}(V,W) : \mathrm{Attr}}\ \mathrm{TV\text{-}Attr}
\qquad
\frac{\Gamma\vdash V : 1 \to1}{\Gamma\vdash\mathrm{onClick}\ V : \mathrm{Attr}}\ \mathrm{TV\text{-}OnClick} Γ ⊢ V :: W : List A Γ ⊢ V : A Γ ⊢ W : List A TV - Cons Γ ⊢ ( V , W ) : A × B Γ ⊢ V : A Γ ⊢ W : B TV - Pair Γ ⊢ attr ( V , W ) : Attr Γ ⊢ V : Str Γ ⊢ W : Str TV - Attr Γ ⊢ onClick V : Attr Γ ⊢ V : 1 → 1 TV - OnClick
Γ ⊢ V : S t r Γ ⊢ t e x t V : E l e m e n t T V - T e x t Γ ⊢ V : L i s t A t t r Γ ⊢ W : L i s t E l e m e n t Γ ⊢ t a g ( V , W ) : E l e m e n t T V - T a g Γ ⊢ V : S t r Γ ⊢ t e x t I n s t V : E l e m I n s t T V - T e x t I Γ ⊢ V : L i s t A t t r Γ ⊢ W : L i s t E l e m I n s t Γ ⊢ t a g I n s t i d ( V , W ) : E l e m I n s t T V - T a g I \frac{\Gamma\vdash V : \mathrm{Str}}{\Gamma\vdash\mathrm{text}\ V : \mathrm{Element}}\ \mathrm{TV\text{-}Text}
\qquad
\frac{\Gamma\vdash V : \mathrm{List}\ \mathrm{Attr} \quad\Gamma\vdash W : \mathrm{List}\ \mathrm{Element}}{\Gamma\vdash\mathrm{tag}(V,W) : \mathrm{Element}}\ \mathrm{TV\text{-}Tag}
\qquad
\frac{\Gamma\vdash V : \mathrm{Str}}{\Gamma\vdash\mathrm{textInst}\ V : \mathrm{ElemInst}}\ \mathrm{TV\text{-}TextI}
\qquad
\frac{\Gamma\vdash V : \mathrm{List}\ \mathrm{Attr} \quad\Gamma\vdash W : \mathrm{List}\ \mathrm{ElemInst}}{\Gamma\vdash\mathrm{tagInst}_{id}(V,W) : \mathrm{ElemInst}}\ \mathrm{TV\text{-}TagI} Γ ⊢ text V : Element Γ ⊢ V : Str TV - Text Γ ⊢ tag ( V , W ) : Element Γ ⊢ V : List Attr Γ ⊢ W : List Element TV - Tag Γ ⊢ textInst V : ElemInst Γ ⊢ V : Str TV - TextI Γ ⊢ tagInst i d ( V , W ) : ElemInst Γ ⊢ V : List Attr Γ ⊢ W : List ElemInst TV - TagI
Typing Rules for Computations Γ ⊢ M : A \Gamma\vdash M : A Γ ⊢ M : A
Γ ⊢ V : A Γ ⊢ v a l V : A T C - V a l Γ ⊢ M : A Γ , x : A ⊢ N : B Γ ⊢ l e t x = M i n N : B T C - L e t Γ ⊢ V : A → B Γ ⊢ W : A Γ ⊢ V W : B T C - A p p Γ ⊢ V : B o o l Γ ⊢ M : A Γ ⊢ N : A Γ ⊢ i f V t h e n M e l s e N : A T C - I f \frac{\Gamma\vdash V : A}{\Gamma\vdash\mathrm{val}\ V : A}\ \mathrm{TC\text{-}Val}
\qquad
\frac{\Gamma\vdash M : A \quad\Gamma, x : A \vdash N : B}{\Gamma\vdash\mathrm{let}\ x = M\ \mathrm{in}\ N : B}\ \mathrm{TC\text{-}Let}
\qquad
\frac{\Gamma\vdash V : A \to B \quad\Gamma\vdash W : A}{\Gamma\vdash V\ W : B}\ \mathrm{TC\text{-}App}
\qquad
\frac{\Gamma\vdash V : \mathrm{Bool} \quad\Gamma\vdash M : A \quad\Gamma\vdash N : A}{\Gamma\vdash\mathrm{if}\ V\ \mathrm{then}\ M\ \mathrm{else}\ N : A}\ \mathrm{TC\text{-}If} Γ ⊢ val V : A Γ ⊢ V : A TC - Val Γ ⊢ let x = M in N : B Γ ⊢ M : A Γ , x : A ⊢ N : B TC - Let Γ ⊢ V W : B Γ ⊢ V : A → B Γ ⊢ W : A TC - App Γ ⊢ if V then M else N : A Γ ⊢ V : Bool Γ ⊢ M : A Γ ⊢ N : A TC - If
Γ ⊢ V : A × B Γ ⊢ f s t V : A T C - F s t Γ ⊢ V : A × B Γ ⊢ s n d V : B T C - S n d Γ ⊢ V : E l e m e n t Γ ⊢ i n i t V : E l e m I n s t T C - I n i t Γ ⊢ V : E l e m I n s t Γ ⊢ c l i c k i d V : 1 T C - C l i c k \frac{\Gamma\vdash V : A \times B}{\Gamma\vdash\mathrm{fst}\ V : A}\ \mathrm{TC\text{-}Fst}
\qquad
\frac{\Gamma\vdash V : A \times B}{\Gamma\vdash\mathrm{snd}\ V : B}\ \mathrm{TC\text{-}Snd}
\qquad
\frac{\Gamma\vdash V : \mathrm{Element}}{\Gamma\vdash\mathrm{init}\ V : \mathrm{ElemInst}}\ \mathrm{TC\text{-}Init}
\qquad
\frac{\Gamma\vdash V : \mathrm{ElemInst}}{\Gamma\vdash\mathrm{click}_{id}\ V : 1}\ \mathrm{TC\text{-}Click} Γ ⊢ fst V : A Γ ⊢ V : A × B TC - Fst Γ ⊢ snd V : B Γ ⊢ V : A × B TC - Snd Γ ⊢ init V : ElemInst Γ ⊢ V : Element TC - Init Γ ⊢ click i d V : 1 Γ ⊢ V : ElemInst TC - Click
Γ ⊢ V : A t t r Γ ⊢ r u n C l i c k V : 1 T C - R u n Γ ⊢ V : E l e m I n s t Γ ⊢ u p d a t e V : E l e m I n s t T C - U p d a t e Γ ⊢ V 1 : A → B → B Γ ⊢ V 2 : B Γ ⊢ V 3 : L i s t A Γ ⊢ f o l d V 1 V 2 V 3 : B T C - F o l d \frac{\Gamma\vdash V : \mathrm{Attr}}{\Gamma\vdash\mathrm{runClick}\ V : 1}\ \mathrm{TC\text{-}Run}
\qquad
\frac{\Gamma\vdash V : \mathrm{ElemInst}}{\Gamma\vdash\mathrm{update}\ V : \mathrm{ElemInst}}\ \mathrm{TC\text{-}Update}
\qquad
\frac{\Gamma\vdash V_1 : A \to B \to B \quad\Gamma\vdash V_2 : B \quad\Gamma\vdash V_3 : \mathrm{List}\ A}{\Gamma\vdash\mathrm{fold}\ V_1\ V_2\ V_3 : B}\ \mathrm{TC\text{-}Fold} Γ ⊢ runClick V : 1 Γ ⊢ V : Attr TC - Run Γ ⊢ update V : ElemInst Γ ⊢ V : ElemInst TC - Update Γ ⊢ fold V 1 V 2 V 3 : B Γ ⊢ V 1 : A → B → B Γ ⊢ V 2 : B Γ ⊢ V 3 : List A TC - Fold
Furthermore, following JSX, we allow for direct embedding of HTML-like structures into source code, and desugar these structures into elements and attributes. { V } \{V\} { V } embeds the value V V V into such a structure. For instance, the computation on the left desugars to the computation on the right:
let s = "Hello, world!" in
<div onClick={λ().()} class="foo">
<b>{x}</b>
{s}
</div>
let s = val "Hello, world!" in
val tag(
attr("tag", "div") :: onClick (λy.val ())
:: attr("class", "foo") :: [],
tag(attr("tag", "b") :: [], x :: []) :: text s :: [])
We elide a formal definition of this desugaring process, although we note that it is type-directed , since embedded strings (s s s in the above example) should be wrapped in the text constructor while embedded tags (x x x above) should not.
Type System
We have separate but mutually inductive typing judgments for values and computations (Figure 1 ). Most rules are entirely unsurprising. Rule TV-OnClick specifies that an event handler should have type 1 → 1 1 \to1 1 → 1 : since λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react has no side effects, the contents of the handler will only become significant in the presence of effectful extensions.
Figure 1. Typing rules for λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react values and computations.
Programs. We require that a (programmer-level) program M M M satisfies ∅ ⊢ M : E l e m e n t \varnothing\vdash M : \mathrm{Element} ∅ ⊢ M : Element . The initial configuration M 0 M_0 M 0 is then l e t x = M i n i n i t x \mathrm{let}\ x = M\ \mathrm{in}\ \mathrm{init}\ x let x = M in init x , and satisfies ∅ ⊢ M 0 : E l e m I n s t \varnothing\vdash M_0 : \mathrm{ElemInst} ∅ ⊢ M 0 : ElemInst .
Operational Semantics
Figure 2 defines a small-step reduction on computations; substitution is defined on values and computations in the expected way. The β \beta β -reduction rules on expressions are standard; the remaining
Figure 2. Small-step operational semantics and top-level semantics for λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react .
Reduction Rules for Computations
β \beta β -reductions
let x = M in N ⇝ let x = M ′ in N EC-Let (if M ⇝ M ′ ) let x = val V in M ⇝ M [ V / x ] EC-Val ( λ x . M ) V ⇝ M [ V / x ] EC-App fold V W [ ] ⇝ val W EC-FdN if true then M else N ⇝ M EC-IfT if false then M else N ⇝ N EC-IfF fst ( V , W ) ⇝ val V EC-Fst snd ( V , W ) ⇝ val W EC-Snd fold V f V 0 ( V h : : V t ) ⇝ V f V h ( fold V f V 0 V t ) EC-FdC \begin{aligned}
\text{let } x = M \text{ in } N &\leadsto\text{let } x = M' \text{ in } N && \text{EC-Let}\\
&\quad\text{(if } M \leadsto M'\text{)}\\
\text{let } x = \operatorname{val}\ V \text{ in } M &\leadsto M[V/x] && \text{EC-Val}\\
(\lambda x.M)\ V &\leadsto M[V/x] && \text{EC-App}\\
\operatorname{fold}\ V\ W\ [] &\leadsto\operatorname{val}\ W && \text{EC-FdN}\\
\text{if true then } M \text{ else } N &\leadsto M && \text{EC-IfT}\\
\text{if false then } M \text{ else } N &\leadsto N && \text{EC-IfF}\\
\operatorname{fst}\ (V,W) &\leadsto\operatorname{val}\ V && \text{EC-Fst}\\
\operatorname{snd}\ (V,W) &\leadsto\operatorname{val}\ W && \text{EC-Snd}\\
\operatorname{fold}\ V_f\ V_0\ (V_h :: V_t) &\leadsto V_f\ V_h\ (\operatorname{fold}\ V_f\ V_0\ V_t) && \text{EC-FdC}
\end{aligned} let x = M in N let x = val V in M ( λ x . M ) V fold V W [ ] if true then M else N if false then M else N fst ( V , W ) snd ( V , W ) fold V f V 0 ( V h :: V t ) ⇝ let x = M ′ in N (if M ⇝ M ′ ) ⇝ M [ V / x ] ⇝ M [ V / x ] ⇝ val W ⇝ M ⇝ N ⇝ val V ⇝ val W ⇝ V f V h ( fold V f V 0 V t ) EC-Let EC-Val EC-App EC-FdN EC-IfT EC-IfF EC-Fst EC-Snd EC-FdC
Runtime reductions
init ( text V ) ⇝ val ( textInst V ) EC-InitText init ( tag ( V , W ) ) ⇝ let x = inits W in val ( tagInst i d ( V , x ) ) , i d fresh EC-InitTag click i d ( textInst V ) ⇝ val ( ) EC-ClickText click i d ( tagInst i d ( V , W ) ) ⇝ runClicks V ; clicks i d W EC-ClickTagT click i d ( tagInst i d ′ ( V , W ) ) ⇝ clicks i d W , i d ≠ i d ′ EC-ClickTagF runClick attr ( V , W ) ⇝ val ( ) EC-RunAttr runClick ( onClick V ) ⇝ V ( ) EC-RunClick update ( textInst V ) ⇝ val textInst V EC-UpdateText update ( tagInst i d ( V , W ) ) ⇝ let x = updates W in val ( tagInst i d ( V , x ) ) EC-UpdateTag \begin{aligned}
\operatorname{init}\ (\operatorname{text}\ V) &\leadsto\operatorname{val}\ (\operatorname{textInst}\ V) && \text{EC-InitText}\\
\operatorname{init}\ (\operatorname{tag}(V,W)) &\leadsto\text{let } x = \operatorname{inits}\ W \text{ in } \operatorname{val}\ (\operatorname{tagInst}_{id}(V,x)),\quad id\ \text{fresh} && \text{EC-InitTag}\\
\operatorname{click}_{id}\ (\operatorname{textInst}\ V) &\leadsto\operatorname{val}\ () && \text{EC-ClickText}\\
\operatorname{click}_{id}\ (\operatorname{tagInst}_{id}(V,W)) &\leadsto\operatorname{runClicks}\ V\ ;\ \operatorname{clicks}_{id}\ W && \text{EC-ClickTagT}\\
\operatorname{click}_{id}\ (\operatorname{tagInst}_{id'}(V,W)) &\leadsto\operatorname{clicks}_{id}\ W,\quad id \ne id' && \text{EC-ClickTagF}\\
\operatorname{runClick}\ \operatorname{attr}(V,W) &\leadsto\operatorname{val}\ () && \text{EC-RunAttr}\\
\operatorname{runClick}\ (\operatorname{onClick}\ V) &\leadsto V\ () && \text{EC-RunClick}\\
\operatorname{update}\ (\operatorname{textInst}\ V) &\leadsto\operatorname{val}\ \operatorname{textInst}\ V && \text{EC-UpdateText}\\
\operatorname{update}\ (\operatorname{tagInst}_{id}(V,W)) &\leadsto\text{let } x = \operatorname{updates}\ W \text{ in } \operatorname{val}\ (\operatorname{tagInst}_{id}(V,x)) && \text{EC-UpdateTag}
\end{aligned} init ( text V ) init ( tag ( V , W )) click i d ( textInst V ) click i d ( tagInst i d ( V , W )) click i d ( tagInst i d ′ ( V , W )) runClick attr ( V , W ) runClick ( onClick V ) update ( textInst V ) update ( tagInst i d ( V , W )) ⇝ val ( textInst V ) ⇝ let x = inits W in val ( tagInst i d ( V , x )) , i d fresh ⇝ val ( ) ⇝ runClicks V ; clicks i d W ⇝ clicks i d W , i d = i d ′ ⇝ val ( ) ⇝ V ( ) ⇝ val textInst V ⇝ let x = updates W in val ( tagInst i d ( V , x )) EC-InitText EC-InitTag EC-ClickText EC-ClickTagT EC-ClickTagF EC-RunAttr EC-RunClick EC-UpdateText EC-UpdateTag
Top-level Eventful Reduction Rules
M ⇝ ⊤ N (if M ⇝ N ) ET-Lift val V ⇝ ⊤ click i d V ; update V ET-Event \begin{aligned}
M &\leadsto_{\top} N && \text{(if } M \leadsto N\text{)} && \text{ET-Lift}\\
\operatorname{val}\ V &\leadsto_{\top} \operatorname{click}_{id}\ V\ ;\ \operatorname{update}\ V && \text{ET-Event}
\end{aligned} M val V ⇝ ⊤ N ⇝ ⊤ click i d V ; update V (if M ⇝ N ) ET-Event ET-Lift
rules show how to evaluate the runtime computations. Rules EC-InitText and EC-InitTag evaluate static text and tag expressions Element into their runtime counterparts of type ElemInst. In the case of tags, this involves creating a fresh runtime identifier.
Rules EC-ClickText, EC-ClickTagT, and EC-ClickTagF handle the click i d \operatorname{click}_{id} click i d construct, which invokes all of the event handlers contained within the node with identifier i d id i d . Specifically in the case that the identifier of a tag instance tagInst i d ( V , W ) \operatorname{tagInst}_{id}(V,W) tagInst i d ( V , W ) matches i d id i d , EC-ClickTagT evaluates runClicks V \operatorname{runClicks}\ V runClicks V to invoke all handlers contained within the node’s attributes, and recursively searches W W W . Correspondingly, rule EC-RunAttr ignores key-value attributes, and EC-RunClick invokes any onClick handlers.
To simulate “reactive behavior” (i.e. how the system responds to user input), we introduce an additional step judgment ⇝ ⊤ \leadsto_{\top} ⇝ ⊤ with two rules: a congruence rule ET-Lift, and a rule ET-Event that represents event reception. This latter rule nondeterministically chooses a node identifier whose handlers should be run. The right-hand-side involves finding and invoking the onClick handler, but also performing node updates, which are more meaningful in λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react and λ r e f r e a c t \lambda_{\mathrm{ref}}^{\mathrm{react}} λ ref react .
Metatheory
λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react enjoys syntactic type soundness, given as usual by progress and preservation.
Theorem 3.1 (Type Soundness for ⇝ \leadsto ⇝ ).
Preservation: If Γ ⊢ M : A \Gamma\vdash M : A Γ ⊢ M : A and M ⇝ N M \leadsto N M ⇝ N , then Γ ⊢ N : A \Gamma\vdash N : A Γ ⊢ N : A .
Progress: If ∅ ⊢ M : A \varnothing\vdash M : A ∅ ⊢ M : A , then either ∃ V . M = val V \exists V.M = \operatorname{val}\ V ∃ V . M = val V or ∃ N . M ⇝ N \exists N.M \leadsto N ∃ N . M ⇝ N .
Proof. Preservation by induction on M ⇝ N M \leadsto N M ⇝ N , progress by induction on ∅ ⊢ M : A \varnothing\vdash M : A ∅ ⊢ M : A .
We also have a form of type soundness for the top-level step judgment ⇝ ⊤ \leadsto_{\top} ⇝ ⊤ , wherein the computation type must be ElemInst. Since we can always receive an event, ⇝ ⊤ \leadsto_{\top} ⇝ ⊤ never terminates.
Theorem 3.2 (Type Soundness for ⇝ ⊤ \rightsquigarrow_{\top} ⇝ ⊤ ).
Preservation: If Γ ⊢ M : E l e m I n s t \Gamma\vdash M : \mathrm{ElemInst} Γ ⊢ M : ElemInst and M ⇝ ⊤ N M \rightsquigarrow_{\top} N M ⇝ ⊤ N , then Γ ⊢ N : E l e m I n s t \Gamma\vdash N : \mathrm{ElemInst} Γ ⊢ N : ElemInst .
Progress: If ∅ ⊢ M : A \emptyset\vdash M : A ∅ ⊢ M : A , then ∃ N . M ⇝ ⊤ N \exists N.\,M \rightsquigarrow_{\top} N ∃ N . M ⇝ ⊤ N .
Proof. By case-analysis on M ⇝ N M \rightsquigarrow N M ⇝ N and ∅ ⊢ M : A \emptyset\vdash M : A ∅ ⊢ M : A respectively, with appeal to Theorem 3.1. □ \square □
Lambda-React-Hook: A Calculus of Hook-Indexed State
We extend λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react with components based on hook-indexed state in the style of React hooks.
Syntax
Term-Level. Below we present the new λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react syntax; runtime-only syntax is again highlighted in gray. To enforce the top-level restriction, we add component bodies .
Effects E : : = P u r e ∣ M u t Label record L : : = ∅ ∣ L , ℓ : A Pointers p Types A , B : : = ⋯ ∣ A → E B Heap context Π : : = ∅ ∣ Π , p : L Labels ℓ Phase context Φ : : = ∅ ∣ Φ , p : ϕ Values V , W : : = ⋯ ∣ component { D } ∣ compInst p ( ⌈ D ⌉ , V ) ∣ set p ℓ Computations M , N : : = ⋯ ∣ ⌈ D 0 ⌉ ↓ p ϕ D Bodies D : : = val V ∣ let x = M in D ∣ let x , x s e t = useState ℓ V in D Phase ϕ : : = I n i t ∣ S u c c Instance memory π : : = { r e r e n d e r : b , s t : σ } State store σ : : = ∅ ∣ σ , ℓ ↦ V Heap H : : = ∅ ∣ H , p ↦ π Boolean flag b : : = t t ∣ f f \begin{aligned}
\text{Effects } E &::= \mathrm{Pure}\mid\mathrm{Mut}
&\text{Label record } L &::= \emptyset\mid L,\ell:A
&\text{Pointers } p\\
\text{Types } A,B &::= \cdots\mid A\xrightarrow{E}B
&\text{Heap context } \Pi&::= \emptyset\mid\Pi,p:L
&\text{Labels } \ell\\
\text{Phase context } \Phi&::= \emptyset\mid\Phi,p:\phi\\
\text{Values } V,W &::= \cdots\mid\operatorname{component}\{D\}\mid\operatorname{compInst}_{p}(\lceil D\rceil,V)\mid\operatorname{set}_{p}^{\ell}\\
\text{Computations } M,N &::= \cdots\mid\lceil D_{0}\rceil\mathrel{\downarrow_{p}^{\phi}}D\\
\text{Bodies } D &::= \operatorname{val}V\mid\operatorname{let}x=M\operatorname{in}D\mid\operatorname{let}x,x_{\mathrm{set}}=\operatorname{useState}^{\ell}V\operatorname{in}D\\
\text{Phase } \phi&::= \mathrm{Init}\mid\mathrm{Succ}
&\text{Instance memory } \pi&::= \{\mathrm{rerender}:b,\mathrm{st}:\sigma\}
&\text{State store } \sigma::= \emptyset\mid\sigma,\ell\mapsto V\\
\text{Heap } H &::= \emptyset\mid H,p\mapsto\pi
&\text{Boolean flag } b &::= \mathrm{tt}\mid\mathrm{ff}
\end{aligned} Effects E Types A , B Phase context Φ Values V , W Computations M , N Bodies D Phase ϕ Heap H ::= Pure ∣ Mut ::= ⋯ ∣ A E B ::= ∅ ∣ Φ , p : ϕ ::= ⋯ ∣ component { D } ∣ compInst p (⌈ D ⌉ , V ) ∣ set p ℓ ::= ⋯ ∣ ⌈ D 0 ⌉ ↓ p ϕ D ::= val V ∣ let x = M in D ∣ let x , x set = useState ℓ V in D ::= Init ∣ Succ ::= ∅ ∣ H , p ↦ π Label record L Heap context Π Instance memory π Boolean flag b ::= ∅ ∣ L , ℓ : A ::= ∅ ∣ Π , p : L ::= { rerender : b , st : σ } ::= tt ∣ ff Pointers p Labels ℓ State store σ ::= ∅ ∣ σ , ℓ ↦ V
Components are made stateful by the useState construct, written let x , x s e t = useState ℓ V in D \operatorname{let}x,x_{\mathrm{set}}=\operatorname{useState}^{\ell}V\operatorname{in}D let x , x set = useState ℓ V in D . Upon evaluation, the current state value is bound to x x x , and a setter for the state cell is bound to x s e t x_{\mathrm{set}} x set . V V V is the initial state value. ℓ \ell ℓ ranges over a set of labels , and identifies the location of the state cell (with respect to a given component instance). Instead of the programmer writing these labels, we expect that they are generated via a straightforward elaboration pass.
Component instances are crucially differentiated from components: a single component may be instantiated multiple times. In such cases, ℓ \ell ℓ alone is insufficient to distinguish a state cell on the heap, so we use runtime-generated pointers p p p to disambiguate state cells at runtime.
We introduce three new values, principal among which are components component { D } \operatorname{component}\{D\} component { D } that wrap bodies D D D into elements and can then be composed with other elements (e.g. as the child of a tag). A component instance compInst p ( ⌈ D ⌉ , V ) \operatorname{compInst}_{p}(\lceil D\rceil,V) compInst p (⌈ D ⌉ , V ) has memory at pointer p p p on the heap, initial body D D D (which is used for rerendering), and child element V V V . Conceptually, component instances are a stateful “shell” around their sub-elements, with no content that would manifest in e.g. their reification into HTML. Setters , written set p ℓ \operatorname{set}_{p}^{\ell} set p ℓ , support mutation of a particular state cell ( p , ℓ ) (p,\ell) ( p , ℓ ) .
The sole new computation, ⌈ D 0 ⌉ ↓ p ϕ D \lceil D_{0}\rceil\mathrel{\downarrow_{p}^{\phi}}D ⌈ D 0 ⌉ ↓ p ϕ D , embeds body evaluation into computation evaluation: as explained in Section 2.3, evaluating bodies requires a phase ϕ \phi ϕ and occurs at a pointer p p p . Evaluation occurs on the right-hand body D D D , while the left-hand body D 0 D_{0} D 0 remains fixed: in practice, D D D is a reduction of D 0 D_{0} D 0 . This computation is read, “at phase ϕ \phi ϕ and pointer p p p , D 0 D_{0} D 0 has evaluated to D D D .”
The heap H \mathcal{H} H stores the contents of the state cells owned by each instance, along with a flag to track whether the instance should be rerendered. Specifically, H \mathcal{H} H contains some number of pointers p p p associated with instance memories π \pi π . Each π \pi π is a record with two fields: rerender contains a meta-boolean flag b b b tracking whether the instance should be rerendered, and st contains the state σ \sigma σ of the instance, where σ \sigma σ is a map from labels ℓ \ell ℓ to values V V V . We identify heaps and state stores up to reordering of their entries.
Type-Level. To prohibit top-level setter calls as explained in § 2.4 , we introduce a simple effect system to the language with only two effects, Pure (for pure computations) and Mut for state-altering computations. We add effect annotations to all function arrows.
Label records L \mathcal{L} L map labels ℓ \ell ℓ to types A A A : as mentioned in § 2.4 , they serve as the type of both bodies D D D and of state stores σ \sigma σ . The heap type Π \Pi Π is a map from pointers p p p to label records L \mathcal{L} L . We also introduce a phase context Φ \Phi Φ that tracks the current phase of each component instance to prohibit reinitialization, as described in § 2.4 . Both Π \Pi Π and Φ \Phi Φ are runtime typing contexts , in that they “grow” as a configuration steps, and do not grow throughout a single typing derivation (read bottom-to-top).
Notation. We use array indexing notation to refer to particular values in maps (such as Π \Pi Π and H \mathcal{H} H ), and we use dot-notation to refer to specific fields of record π \pi π . Furthermore, we use bar notation, e.g. H ∣ x ↦ V \mathcal{H} \mid x \mapsto V H ∣ x ↦ V , to concisely denote (potentially multi-level) record updates. For instance, expression H ∣ H [ p ] . s t [ ℓ ] ↦ V \mathcal{H} \mid\mathcal{H}[p].\mathrm{st}[\ell] \mapsto V H ∣ H [ p ] . st [ ℓ ] ↦ V would be read as “heap H \mathcal{H} H with the state cell at pointer p p p and label ℓ \ell ℓ set to V V V .”
Type System
We introduce three significant changes from λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react throughout the type system, which is shown in Figure 3 . First, Π \Pi Π and Φ \Phi Φ serve as additional contexts in all judgments. Second, we extend the computation typing judgment to capture the computational effect . For brevity, we re-present only the programmer-level λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react rules in Figure 3 with their effects: all runtime-only computations in λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react have the Mut effect. We also introduce a new typing judgment for bodies.
Figure 3. Selected value, computation, and body typing rules in λ r e a c t h o o k \lambda_{\mathrm{react}}^{\mathrm{hook}} λ react hook .
Phase Contexts. A component instance is initialized once, but may be rerun at will after initialization. Reflecting this, in Φ \Phi Φ , we treat pointers in phase Init linearly , whereas we allow pointers in phase Succ to be used multiple times. We define disjoint context merging accordingly as a partial operation Φ = Φ 1 ⋈ Φ 2 \Phi= \Phi_1 \bowtie\Phi_2 Φ = Φ 1 ⋈ Φ 2 . When rules are read bottom-to-top, this acts as a split. In particular, we have that if p : I n i t p : \mathrm{Init} p : Init in Φ 1 \Phi_1 Φ 1 , then for the result to be well-defined, we must have p ∉ dom ( Φ 2 ) p \notin\operatorname{dom}(\Phi_2) p ∈ / dom ( Φ 2 ) . We write Φ 1 ⋈ Φ 2 \Phi_1 \bowtie\Phi_2 Φ 1 ⋈ Φ 2 in the conclusion of a typing rule to abbreviate a premise Φ = Φ 1 ⋈ Φ 2 \Phi= \Phi_1 \bowtie\Phi_2 Φ = Φ 1 ⋈ Φ 2 .
⋅ = ⋅ ⋈ ⋅ Φ = Φ 1 ⋈ Φ 2 p ∉ dom ( Φ ) Φ , p : S u c c = ( Φ 1 , p : S u c c ) ⋈ ( Φ 2 , p : S u c c ) Φ = Φ 1 ⋈ Φ 2 p ∉ dom ( Φ ) Φ , p : ϕ = ( Φ 1 , p : ϕ ) ⋈ Φ 2 Φ = Φ 1 ⋈ Φ 2 p ∉ dom ( Φ ) Φ , p : ϕ = Φ 1 ⋈ ( Φ 2 , p : ϕ ) \begin{aligned}
\cdot&= \cdot\bowtie\cdot\\
\Phi= \Phi_1 \bowtie\Phi_2 \quad p \notin\operatorname{dom}(\Phi) \qquad
\Phi, p : \mathrm{Succ} &= (\Phi_1, p : \mathrm{Succ}) \bowtie(\Phi_2, p : \mathrm{Succ}) \\
\Phi= \Phi_1 \bowtie\Phi_2 \quad p \notin\operatorname{dom}(\Phi) \qquad
\Phi, p : \phi&= (\Phi_1, p : \phi) \bowtie\Phi_2 \\
\Phi= \Phi_1 \bowtie\Phi_2 \quad p \notin\operatorname{dom}(\Phi) \qquad
\Phi, p : \phi&= \Phi_1 \bowtie(\Phi_2, p : \phi)
\end{aligned} ⋅ Φ = Φ 1 ⋈ Φ 2 p ∈ / dom ( Φ ) Φ , p : Succ Φ = Φ 1 ⋈ Φ 2 p ∈ / dom ( Φ ) Φ , p : ϕ Φ = Φ 1 ⋈ Φ 2 p ∈ / dom ( Φ ) Φ , p : ϕ = ⋅ ⋈ ⋅ = ( Φ 1 , p : Succ ) ⋈ ( Φ 2 , p : Succ ) = ( Φ 1 , p : ϕ ) ⋈ Φ 2 = Φ 1 ⋈ ( Φ 2 , p : ϕ )
Definition 4.1. Say Succ ( Φ ) \operatorname{Succ}(\Phi) Succ ( Φ ) iff all p ∈ dom ( Φ ) p \in\operatorname{dom}(\Phi) p ∈ dom ( Φ ) have Φ [ p ] = Succ \Phi[p] = \operatorname{Succ} Φ [ p ] = Succ .
To respect linearity, we always have Succ ( Φ ) \operatorname{Succ}(\Phi) Succ ( Φ ) for values, bodies, and pure computations. This fact is captured in the following lemma; we defer discussions of the typing judgments to below.
Lemma 4.2. If Γ ; Π ; Φ ⊢ V : A \Gamma; \Pi; \Phi\vdash V : A Γ ; Π ; Φ ⊢ V : A or Γ ; Π ; Φ ⊢ D : L \Gamma; \Pi; \Phi\vdash D : \mathcal{L} Γ ; Π ; Φ ⊢ D : L or Γ ; Π ; Φ ⊢ M : A ! P u r e \Gamma; \Pi; \Phi\vdash M : A ! \mathrm{Pure} Γ ; Π ; Φ ⊢ M : A ! Pure , then Succ ( Φ ) \operatorname{Succ}(\Phi) Succ ( Φ ) .
Proof. By mutual induction on the typing derivation. The conclusion is either given directly (for lambdas and terms with no subterms), or by inductive hypothesis for other terms with subterms. □ \square □
Values. We elide rules that feature only the additions of Π \Pi Π and Φ \Phi Φ . The updated TV-LAM rule uses the updated computation typing judgment, explained in more detail below. For now, we note that the computation performs an effect E E E , which is captured by the annotation on the function type arrow. Rule TV-COMP makes use of the body typing judgment Γ ; Π ; Φ ⊢ D : L \Gamma; \Pi; \Phi\vdash D : \mathcal{L} Γ ; Π ; Φ ⊢ D : L . We defer discussion of this judgment but it ensures that component body D D D is well typed with state labels L \mathcal{L} L ; the labels are only necessary for runtime typing guarantees, and so L \mathcal{L} L does not appear in the conclusion. The body typing judgment guarantees that the computation type underlying D D D is Element. The TV-SETTER rule assigns a type to a setter based on the type of state cell ( p , ℓ ) (p,\ell) ( p , ℓ ) according to Π \Pi Π . The first premise implies that p ∈ dom ( Π ) p \in\operatorname{dom}(\Pi) p ∈ dom ( Π ) and ℓ ∈ dom ( Π [ p ] ) \ell\in\operatorname{dom}(\Pi[p]) ℓ ∈ dom ( Π [ p ]) . The TV-COMP1 rule types a component instantiation. Its first premise ensures that all state cells in the instance memory, represented by Π [ p ] \Pi[p] Π [ p ] , are consistent with the type of the component instance’s initial body D D D . The second premise ( Φ 1 ⋈ Φ 2 ) [ p ] = Succ (\Phi_1 \bowtie\Phi_2)[p] = \operatorname{Succ} ( Φ 1 ⋈ Φ 2 ) [ p ] = Succ guarantees that initialization of p p p is complete, and thus that the component is safe to rerender. The third premise ensures that the child of a component instance is an E l e m I n s t \mathrm{ElemInst} ElemInst .
Computations. The λ r e a c t h o o k \lambda_{\mathrm{react}}^{\mathrm{hook}} λ react hook computation typing judgement has the form Γ ; Π ; Φ ⊢ M : A ! E \Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash M : A\mathbin{!}E Γ ; Π ; Φ ⊢ M : A ! E , which can be read “under typing environment Γ \Gamma Γ , heap context Π \Pi Π , and phase context Φ \Phi Φ , computation M M M has type A A A and produces effects $E”. Our effect system classes expressions as Pure (for expressions that do not change the heap) or Mut. The effect system is deliberately simple: rule TC-Sub allows us to treat Pure expressions as Mut, and rules like TC-Let and TC-If require that their subcomputations share the same effect type. We omit TC-Snd due to its similarity to TC-Fst.
The construct ⌈ D 0 ⌉ ↓ φ p D \lceil D_0 \rceil\mathrel{\downarrow_{\varphi}^{p}} D ⌈ D 0 ⌉ ↓ φ p D is typed by either TC-EvalI and TC-EvalS, depending on the value of the phase φ \varphi φ . In the former, L \mathcal{L} L can be read as “the labels left to be initialized”, and then the first premise asserts that the initial body D 0 D_0 D 0 contains the labels (and appropriately associated types) in the instance memory at p p p and those still to be initialized. Consequently, when L = ∅ \mathcal{L} = \varnothing L = ∅ , then D 0 D_0 D 0 has type Π [ p ] \Pi[p] Π [ p ] , satisfying the first premise of TV-CompI. In TC-EvalS, we guarantee that all labels left in D D D are already in the instance memory. Set operations ∪ \cup ∪ and ⊆ \subseteq ⊆ are defined on label records in the obvious way; L ⊎ L ′ \mathcal{L} \uplus\mathcal{L}' L ⊎ L ′ resolves to L ∪ L ′ \mathcal{L} \cup\mathcal{L}' L ∪ L ′ alongside the premise that L \mathcal{L} L and L ′ \mathcal{L}' L ′ are disjoint.
Bodies. As previously mentioned, the type of a body is a label record L \mathcal{L} L , which denotes the labels (and their associated types) present in the body.
Rules TB-Val and TB-Let are analogous to their computation-level counterparts TC-Val and TC-Let, respectively. TB-Val enforces that the ultimate type of any body is Element, and assigns as its state-labels the empty record ∅ \varnothing ∅ . TB-Let allows us to embed computations into bodies, and leaves the label record of the continuation unchanged. These embedded computations must be Pure, which guarantees that no setters, which have effect Mut, are invoked inside of bodies.
Rule TB-State types the useState construct. We require that the initial value has type A A A , and in the continuation body, we add a binding x : A x : A x : A to Γ \Gamma Γ to record the type of the value. We also add a binding x s e t : A → M u t 1 x_{\mathrm{set}} : A \mathrel{\xrightarrow{\mathrm{Mut}}} 1 x set : A Mut 1 for the setter. The conclusion of the rule includes ℓ : A \ell: A ℓ : A in the label set to indicate that state cell ℓ \ell ℓ has been used.
Operational Semantics
The semantics of λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react extend those of λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react by including a heap H \mathcal{H} H . We elide the augmented λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react β \beta β -reduction rules as none except EC-Let and ET-Lift interact with H \mathcal{H} H . We also introduce a series of new rules for computations and a new step judgment ⇝ φ p \rightsquigarrow_{\varphi}^{p} ⇝ φ p on bodies.
Computations. Figure Figure 4 details all new reduction rules in λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react . EC-AppSet reduces a setter application to a unit value and updates the heap accordingly. EC-InitComp creates a fresh pointer p p p to a new instance memory on the heap and begins the evaluation of D D D . EC-ClickComp triggers click handlers in the body of a component instance.
Figure 4. Operational semantics for λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react computations and bodies, extending λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react .
The purpose of the update construct is to rerender any component bodies whose state has changed, and in λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react has a nontrivial semantics. To update a component instance at pointer p p p , if H [ p ] . r e r e n d e r = t t \mathcal{H}[p].\mathrm{rerender} = \mathrm{tt} H [ p ] . rerender = tt , EC-UpdateCompT begins the re-evaluation of D D D . If H [ p ] . r e r e n d e r = f f \mathcal{H}[p].\mathrm{rerender} = \mathrm{ff} H [ p ] . rerender = ff , EC-UpdateCompF instead propagates the update trigger to the child of the instance.
EC-Eval is a congruence rule that allows evaluation in the body D D D of ⌈ D 0 ⌉ ↓ φ p D \lceil D_0 \rceil\mathrel{\downarrow_{\varphi}^{p}} D ⌈ D 0 ⌉ ↓ φ p D , and EC-EvalDone embeds the result of evaluating a component into a component instance.
Bodies. The step judgment for a λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react body is parameterized by a phase φ \varphi φ and a pointer p p p , i.e. we evaluate bodies in a particular phase and with respect to a particular heap location . Rules EB-Let and EB-Val ignore these extra parameters and use the standard let-binding semantics.
The semantics of useState is determined by φ \varphi φ . If φ = I n i t \varphi= \mathrm{Init} φ = Init , then EC-StateI applies, which binds the provided initial value to x x x and simultaneously adds it to the heap at ( p , ℓ ) (p,\ell) ( p , ℓ ) . If instead φ = S u c c \varphi= \mathrm{Succ} φ = Succ , then EC-StateS binds to x x x the current value on the heap at ( p , ℓ ) (p,\ell) ( p , ℓ ) , and leaves the heap unchanged. In either case, we also bind a setter for location ( p , ℓ ) (p,\ell) ( p , ℓ ) to x s e t x_{\mathrm{set}} x set .
Reduction Rules for Computations
H ; i n i t c o m p o n e n t { D } ⇝ ⌈ D ⌉ ↓ p I n i t D ; H , p ↦ { s t : ∅ , r e r e n d e r : f f } , if p fresh H ; u p d a t e ( c o m p I n s t p ( ⌈ D ⌉ , V ) ) ⇝ ⌈ D ⌉ ↓ p S u c c D ; H ∣ H [ p ] . r e r e n d e r ↦ f f , if H [ p ] . r e r e n d e r = t t H ; u p d a t e ( c o m p I n s t p ( ⌈ D ⌉ , V ) ) ⇝ c o m p I n s t p ( ⌈ D ⌉ , u p d a t e V ) ; H , if H [ p ] . r e r e n d e r = f f H ; ⌈ D 0 ⌉ ↓ p ϕ D ⇝ ⌈ D 0 ⌉ ↓ p ϕ D ′ ; H ′ , if H ; D ⇝ p ϕ D ′ ; H ′ H ; ⌈ D ⌉ ↓ p ϕ v a l V ⇝ c o m p I n s t p ( ⌈ D ⌉ , i n i t V ) ; H H ; c l i c k i d ( c o m p I n s t p ( ⌈ D ⌉ , V ) ) ⇝ c l i c k i d V ; H H ; s e t p ℓ V ⇝ v a l ( ) ; H ′ , where H ′ = H ∣ H [ p ] . s t [ ℓ ] ↦ V and H [ p ] . r e r e n d e r ↦ t t \begin{aligned}
\mathcal{H};\ \mathrm{init\ component}\ \{D\} &\leadsto\lceil D\rceil\mathrel{\downarrow^{\mathrm{Init}}_{p}} D;\ \mathcal{H},p\mapsto\{\mathrm{st}:\varnothing,\mathrm{rerender}:\mathrm{ff}\}, && \text{if }p\text{ fresh}\\
\mathcal{H};\ \mathrm{update}\left(\mathrm{compInst}_{p}(\lceil D\rceil,V)\right) &\leadsto\lceil D\rceil\mathrel{\downarrow^{\mathrm{Succ}}_{p}}D;\ \mathcal{H}\mid\mathcal{H}[p].\mathrm{rerender}\mapsto\mathrm{ff}, && \text{if }\mathcal{H}[p].\mathrm{rerender}=\mathrm{tt}\\
\mathcal{H};\ \mathrm{update}\left(\mathrm{compInst}_{p}(\lceil D\rceil,V)\right) &\leadsto\mathrm{compInst}_{p}(\lceil D\rceil,\mathrm{update}\ V);\ \mathcal{H}, && \text{if }\mathcal{H}[p].\mathrm{rerender}=\mathrm{ff}\\
\mathcal{H};\ \lceil D_{0}\rceil\mathrel{\downarrow^{\phi}_{p}}D &\leadsto\lceil D_{0}\rceil\mathrel{\downarrow^{\phi}_{p}}D';\ \mathcal{H}', && \text{if }\mathcal{H};D\mathrel{\leadsto^{\phi}_{p}}D';\mathcal{H}'\\
\mathcal{H};\ \lceil D\rceil\mathrel{\downarrow^{\phi}_{p}}\mathrm{val}\ V &\leadsto\mathrm{compInst}_{p}(\lceil D\rceil,\mathrm{init}\ V);\ \mathcal{H}\\
\mathcal{H};\ \mathrm{click}_{id}\left(\mathrm{compInst}_{p}(\lceil D\rceil,V)\right) &\leadsto\mathrm{click}_{id}\ V;\ \mathcal{H}\\
\mathcal{H};\ \mathrm{set}^{\ell}_{p}\ V &\leadsto\mathrm{val}\ (); \mathcal{H}', && \text{where }\mathcal{H}'=\mathcal{H}\mid\mathcal{H}[p].\mathrm{st}[\ell]\mapsto V\text{ and }\mathcal{H}[p].\mathrm{rerender}\mapsto\mathrm{tt}
\end{aligned} H ; init component { D } H ; update ( compInst p (⌈ D ⌉ , V ) ) H ; update ( compInst p (⌈ D ⌉ , V ) ) H ; ⌈ D 0 ⌉ ↓ p ϕ D H ; ⌈ D ⌉ ↓ p ϕ val V H ; click i d ( compInst p (⌈ D ⌉ , V ) ) H ; set p ℓ V ⇝ ⌈ D ⌉ ↓ p Init D ; H , p ↦ { st : ∅ , rerender : ff } , ⇝ ⌈ D ⌉ ↓ p Succ D ; H ∣ H [ p ] . rerender ↦ ff , ⇝ compInst p (⌈ D ⌉ , update V ) ; H , ⇝ ⌈ D 0 ⌉ ↓ p ϕ D ′ ; H ′ , ⇝ compInst p (⌈ D ⌉ , init V ) ; H ⇝ click i d V ; H ⇝ val ( ) ; H ′ , if p fresh if H [ p ] . rerender = tt if H [ p ] . rerender = ff if H ; D ⇝ p ϕ D ′ ; H ′ where H ′ = H ∣ H [ p ] . st [ ℓ ] ↦ V and H [ p ] . rerender ↦ tt
Reduction Rules for Bodies
H ; l e t x = M i n D ⇝ p ϕ l e t x = N i n D ; H ′ , if H ; M ⇝ N ; H ′ H ; l e t x = v a l V i n D ⇝ p ϕ D [ V / x ] ; H H ; l e t x , x s e t = u s e S t a t e ℓ V i n D ⇝ p I n i t D [ V / x , s e t p ℓ / x s e t ] ; H ∣ H [ p ] . s t [ ℓ ] ↦ V H ; l e t x , x s e t = u s e S t a t e ℓ V i n D ⇝ p S u c c D [ H [ p ] . s t [ ℓ ] / x , s e t p ℓ / x s e t ] ; H \begin{aligned}
\mathcal{H};\ \mathrm{let}\ x=M\ \mathrm{in}\ D &\leadsto^{\phi}_{p}\ \mathrm{let}\ x=N\ \mathrm{in}\ D;\mathcal{H}', && \text{if }\mathcal{H};M\leadsto N;\mathcal{H}'\\
\mathcal{H};\ \mathrm{let}\ x=\mathrm{val}\ V\ \mathrm{in}\ D &\leadsto^{\phi}_{p}\ D[V/x];\mathcal{H}\\
\mathcal{H};\ \mathrm{let}\ x,x_{\mathrm{set}}=\mathrm{useState}^{\ell}\ V\ \mathrm{in}\ D &\leadsto^{\mathrm{Init}}_{p}\ D[V/x,\mathrm{set}^{\ell}_{p}/x_{\mathrm{set}}];\mathcal{H}\mid\mathcal{H}[p].\mathrm{st}[\ell]\mapsto V\\
\mathcal{H};\ \mathrm{let}\ x,x_{\mathrm{set}}=\mathrm{useState}^{\ell}\ V\ \mathrm{in}\ D &\leadsto^{\mathrm{Succ}}_{p}\ D[\mathcal{H}[p].\mathrm{st}[\ell]/x,\mathrm{set}^{\ell}_{p}/x_{\mathrm{set}}];\mathcal{H}
\end{aligned} H ; let x = M in D H ; let x = val V in D H ; let x , x set = useState ℓ V in D H ; let x , x set = useState ℓ V in D ⇝ p ϕ let x = N in D ; H ′ , ⇝ p ϕ D [ V / x ] ; H ⇝ p Init D [ V / x , set p ℓ / x set ] ; H ∣ H [ p ] . st [ ℓ ] ↦ V ⇝ p Succ D [ H [ p ] . st [ ℓ ] / x , set p ℓ / x set ] ; H if H ; M ⇝ N ; H ′
Metatheory
Configuration Typing. To reason about runtime configurations, we must describe what it means for a heap to be well-typed. Judgement Γ ; Π ; Φ ⊨ H \Gamma;\Pi;\Phi\models\mathcal{H} Γ ; Π ; Φ ⊨ H ensures that heap H \mathcal{H} H is consistent with heap context Π \Pi Π : namely that the pointers in the heap coincide with the pointers in the heap context, and that the values contained in the state store for each instance have types consistent with the heap context. Specifically, Γ ; Π ; Φ ⊨ H \Gamma;\Pi;\Phi\models\mathcal{H} Γ ; Π ; Φ ⊨ H abbreviates Γ ; Π ; Φ ⊨ H : Π \Gamma;\Pi;\Phi\models\mathcal{H}:\Pi Γ ; Π ; Φ ⊨ H : Π , which is defined as follows:
S u c c ( Φ ) Γ ; Π ; Φ ⊨ ∅ : ∅ Γ ; Π ; Φ 1 ⊨ σ : Σ Γ ; Π ; Φ 2 ⊢ V : A Γ ; Π ; Φ 1 ⊕ Φ 2 ⊨ σ , ℓ ↦ V : ( Σ , ℓ : A ) \begin{aligned}
\mathrm{Succ}(\Phi)\qquad&\Gamma;\Pi;\Phi\models\varnothing:\varnothing\\
\Gamma;\Pi;\Phi_{1}\models\sigma:\Sigma\qquad&\Gamma;\Pi;\Phi_{2}\vdash V:A\\
\Gamma;\Pi;\Phi_{1}\mathbin{\mathbin{\mathord\oplus}}\Phi_{2}\models\sigma,\ell\mapsto V:(\Sigma,\ell:A)
\end{aligned} Succ ( Φ ) Γ ; Π ; Φ 1 ⊨ σ : Σ Γ ; Π ; Φ 1 ⊕ Φ 2 ⊨ σ , ℓ ↦ V : ( Σ , ℓ : A ) Γ ; Π ; Φ ⊨ ∅ : ∅ Γ ; Π ; Φ 2 ⊢ V : A
S u c c ( Φ ) Γ ; Π ; Φ ⊨ ∅ : ∅ Γ ; Π 0 ; Φ 1 ⊨ H : Π Γ ; Π 0 ; Φ 2 ⊨ π . s t : L Γ ; Π 0 ; Φ 1 ⊕ Φ 2 ⊨ H , p ↦ π : ( Π , p : L ) \begin{aligned}
\mathrm{Succ}(\Phi)\qquad&\Gamma;\Pi;\Phi\models\varnothing:\varnothing\\
\Gamma;\Pi_{0};\Phi_{1}\models\mathcal{H}:\Pi\qquad&\Gamma;\Pi_{0};\Phi_{2}\models\pi.\mathrm{st}:L\\
\Gamma;\Pi_{0};\Phi_{1}\mathbin{\mathbin{\mathord\oplus}}\Phi_{2}\models\mathcal{H},p\mapsto\pi:(\Pi,p:L)
\end{aligned} Succ ( Φ ) Γ ; Π 0 ; Φ 1 ⊨ H : Π Γ ; Π 0 ; Φ 1 ⊕ Φ 2 ⊨ H , p ↦ π : ( Π , p : L ) Γ ; Π ; Φ ⊨ ∅ : ∅ Γ ; Π 0 ; Φ 2 ⊨ π . st : L
We then define configurations H ; M \mathcal{H};M H ; M to be well-typed via Γ ; Π ; Φ H ; Φ M ⊢ H ; M : A ! E \Gamma;\Pi;\Phi_{\mathcal{H}};\Phi_{M}\vdash\mathcal{H};M:A\mathbin{!}E Γ ; Π ; Φ H ; Φ M ⊢ H ; M : A ! E , which abbreviates that Φ H ⊕ Φ M \Phi_{\mathcal{H}}\mathbin{\mathbin{\mathord\oplus}}\Phi_{M} Φ H ⊕ Φ M is defined and we also have Γ ; Π ; Φ M ⊢ M : A ! E \Gamma;\Pi;\Phi_{M}\vdash M:A\mathbin{!}E Γ ; Π ; Φ M ⊢ M : A ! E and Γ ; Π ; Φ H ⊨ H \Gamma;\Pi;\Phi_{\mathcal{H}}\models\mathcal{H} Γ ; Π ; Φ H ⊨ H . We extend a similar notion to bodies via judgment Γ ; Π ; Φ D ; Φ M ⊢ H ; D : L \Gamma;\Pi;\Phi_{D};\Phi_{M}\vdash\mathcal{H};D:L Γ ; Π ; Φ D ; Φ M ⊢ H ; D : L .
Type Soundness. λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react enjoys syntactic type soundness, although the statements and proofs of such are more involved than those of λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react .
We prove progress for computations, for each phase of body evaluation, and for the top-level step judgment. When ϕ = S u c c \phi=\mathrm{Succ} ϕ = Succ , we require the premise that all labels in the body are also in the instance memory: this guarantees that we only ever access values from the heap that have already been initialized. Below we include only our top-level result. As with λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react , we can always receive an event, and so never terminate. Appendix A.§ 3 contains all other statements and full proofs.
Theorem 4.3 (Progress for ⇝ T \leadsto_{\mathrm{T}} ⇝ T ). If ∅ ; Π ; Φ H ; Φ M ⊢ H ; M : A ! E \varnothing;\Pi;\Phi_{\mathcal{H}};\Phi_{M}\vdash\mathcal{H};M:A\mathbin{!}E ∅ ; Π ; Φ H ; Φ M ⊢ H ; M : A ! E , then H ; M ⇝ T N ; H ′ \mathcal{H};M\leadsto_{\mathrm{T}}N;\mathcal{H}' H ; M ⇝ T N ; H ′ for some N N N and H ′ \mathcal{H}' H ′ .
Proof. By case-analysis on the typing derivation with appeal to Theorems A.13 (computations), A.14 (bodies for ϕ = I n i t \phi=\mathrm{Init} ϕ = Init ), and A.15 (bodies for ϕ = S u c c \phi=\mathrm{Succ} ϕ = Succ ), which are shown by mutual induction. □
We similarly must prove preservation for all three main modes of evaluation and the top-level step judgment. Since the heap and phases evolve as we step, we state preservation with respect to partial orders on both Π \Pi Π and Φ \Phi Φ , which are given as follows.
Definition 4.4 (Phase and phase context orders).
Phase order: ϕ ⊑ ϕ ′ \phi\sqsubseteq\phi' ϕ ⊑ ϕ ′ is the least partial order satisfying I n i t ⊑ S u c c \mathrm{Init} \sqsubseteq\mathrm{Succ} Init ⊑ Succ .
Phase context order: Φ ⊑ Φ ′ \Phi\sqsubseteq\Phi' Φ ⊑ Φ ′ holds iff Φ ( p ) ⊑ Φ ′ ( p ) \Phi(p) \sqsubseteq\Phi'(p) Φ ( p ) ⊑ Φ ′ ( p ) for all p ∈ dom ( Φ ) p \in\operatorname{dom}(\Phi) p ∈ dom ( Φ ) .
Phase context order (fresh): Φ ⊑ f r e s h Φ ′ \Phi\sqsubseteq_{\mathrm{fresh}} \Phi' Φ ⊑ fresh Φ ′ holds iff Φ ⊑ Φ ′ \Phi\sqsubseteq\Phi' Φ ⊑ Φ ′ and all p ∈ dom ( Φ ′ ) ∖ dom ( Φ ) p \in\operatorname{dom}(\Phi') \setminus\operatorname{dom}(\Phi) p ∈ dom ( Φ ′ ) ∖ dom ( Φ ) are fresh (with respect to a particular step).
The ⊑ f r e s h \sqsubseteq_{\mathrm{fresh}} ⊑ fresh notion is necessary to show the following lemma, since otherwise, a non-fresh extension to Φ 1 \Phi_1 Φ 1 could conflict with pointers in Φ 2 \Phi_2 Φ 2 .
Lemma 4.5. If Φ = Φ 1 ⋈ Φ 2 \Phi= \Phi_1 \bowtie\Phi_2 Φ = Φ 1 ⋈ Φ 2 and Φ 1 ⊑ f r e s h Φ 1 ′ \Phi_1 \sqsubseteq_{\mathrm{fresh}} \Phi'_1 Φ 1 ⊑ fresh Φ 1 ′ , then Φ ⊑ f r e s h Φ 1 ′ ⋈ Φ 2 \Phi\sqsubseteq_{\mathrm{fresh}} \Phi'_1 \bowtie\Phi_2 Φ ⊑ fresh Φ 1 ′ ⋈ Φ 2 (and Φ 1 ′ ⋈ Φ 2 \Phi'_1 \bowtie\Phi_2 Φ 1 ′ ⋈ Φ 2 is defined).
Proof. By case-analysis on an arbitrary p ∈ Φ p \in\Phi p ∈ Φ . We elide a full proof to Appendix A.4. □
Intuitively, the heap context order only permits Π \Pi Π to grow at a pointer p p p if p p p is in initialization phase according to Φ \Phi Φ . Otherwise, we require that Π [ p ] = Π ′ [ p ] \Pi[p] = \Pi'[p] Π [ p ] = Π ′ [ p ] .
Definition 4.6 (Heap context order). Define Π ⊑ Φ Π ′ \Pi\sqsubseteq_{\Phi} \Pi' Π ⊑ Φ Π ′ to hold iff (i) dom ( Π ) ⊆ dom ( Π ′ ) \operatorname{dom}(\Pi) \subseteq\operatorname{dom}(\Pi') dom ( Π ) ⊆ dom ( Π ′ ) , (ii) for all p ∈ dom ( Π ′ ) p \in\operatorname{dom}(\Pi') p ∈ dom ( Π ′ ) , either p ∈ dom ( Π ) p \in\operatorname{dom}(\Pi) p ∈ dom ( Π ) or Φ [ p ] = I n i t \Phi[p] = \mathrm{Init} Φ [ p ] = Init , and (iii) for all p ∈ dom ( Π ) p \in\operatorname{dom}(\Pi) p ∈ dom ( Π ) , if Φ [ p ] = I n i t \Phi[p] = \mathrm{Init} Φ [ p ] = Init then Π [ p ] ⊆ Π ′ [ p ] \Pi[p] \subseteq\Pi'[p] Π [ p ] ⊆ Π ′ [ p ] , and otherwise, Π [ p ] = Π ′ [ p ] \Pi[p] = \Pi'[p] Π [ p ] = Π ′ [ p ] .
The order ⊆ \subseteq ⊆ on label records in condition (iii) invokes type equality: both are defined as expected.
We can now state preservation. For computations, we make separate statements for Pure and Mut, since we also want to show that pure computations do not change the heap, i.e. typed purity implies operational purity. Here we again include only our top-level result: all other statements and full proofs can be found in Appendix A.4.
Theorem 4.7 (Preservation for ⇝ ⊤ \rightsquigarrow_{\top} ⇝ ⊤ ). If Γ ; Π ; Φ H ; Φ M ⊢ H ; M : E l e m I n s t ! M u t \Gamma\mathrel{;} \Pi\mathrel{;} \Phi_H \mathrel{;} \Phi_M \vdash H \mathrel{;} M : \mathrm{ElemInst}\mathbin{!}\mathrm{Mut} Γ ; Π ; Φ H ; Φ M ⊢ H ; M : ElemInst ! Mut and H ; M ⇝ ⊤ N ; H ′ H \mathrel{;} M \rightsquigarrow_{\top} N \mathrel{;} H' H ; M ⇝ ⊤ N ; H ′ , then for some Φ N \Phi_N Φ N , Φ H ′ \Phi'_H Φ H ′ , and Π ′ \Pi' Π ′ such that Φ M ⋈ Φ H ⊑ f r e s h Φ N ⋈ Φ H ′ \Phi_M \bowtie\Phi_H \sqsubseteq_{\mathrm{fresh}} \Phi_N \bowtie\Phi'_H Φ M ⋈ Φ H ⊑ fresh Φ N ⋈ Φ H ′ and Π ⊑ Φ N ⋈ Φ H ′ Π ′ \Pi\sqsubseteq_{\Phi_N \bowtie\Phi'_H} \Pi' Π ⊑ Φ N ⋈ Φ H ′ Π ′ , we have Γ ; Π ′ ; Φ H ′ ; Φ N ⊢ H ′ ; N : E l e m I n s t ! M u t \Gamma\mathrel{;} \Pi' \mathrel{;} \Phi'_H \mathrel{;} \Phi_N \vdash H' \mathrel{;} N : \mathrm{ElemInst}\mathbin{!}\mathrm{Mut} Γ ; Π ′ ; Φ H ′ ; Φ N ⊢ H ′ ; N : ElemInst ! Mut .
Proof. By case-analysis on the step, appealing to Lemma A.24 (computations for E = M u t E = \mathrm{Mut} E = Mut ). □
Consistency
Our type system allows us to statically rule out a large swath of “bad” behavior present in React. For instance, the infinite rerender cycle mentioned in § 2.2 can never arise: due to effect typing, setters can never be called at the top level of a component body.
To formally characterize the problem, we introduce the notion of consistency . Intuitively, a component D D D with instance pointer p p p is consistent with a heap H \mathcal{H} H if the evaluation sequence from D D D to a value V V V in Succ-phase does not modify the heap.
Definition 4.8. A configuration H ; D \mathcal{H} \mathrel{;} D H ; D is consistent with V V V at p p p iff H ; D ⇝ p S u c c val V ; H \mathcal{H} \mathrel{;} D \rightsquigarrow^{\mathrm{Succ}}_{p} \operatorname{val} V \mathrel{;} \mathcal{H} H ; D ⇝ p Succ val V ; H .
Importantly, if H ; D \mathcal{H} \mathrel{;} D H ; D is inconsistent but reduces to a value, then the heap has changed, at which point React will retry evaluation in order to avoid rendering stale state. Consistency guarantees that all rendered state is “consistent” with the heap, i.e. we never render stale state. We need not model React’s retry behavior in our semantics because our effect system statically enforces consistency. We prove that, if a well-typed configuration reduces to a value, then it is consistent with that value.
Theorem 4.9 (Component consistency). If Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L \Gamma\mathrel{;} \Pi\mathrel{;} \Phi_H \mathrel{;} \Phi_D \vdash\mathcal{H} \mathrel{;} D : \mathcal{L} Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L with L ∩ Π [ p ] = ∅ \mathcal{L} \cap\Pi[p] = \varnothing L ∩ Π [ p ] = ∅ , p ∉ dom ( Φ H ⋈ Φ D ) p \notin\operatorname{dom}(\Phi_H \bowtie\Phi_D) p ∈ / dom ( Φ H ⋈ Φ D ) , and H ; D ⇝ p φ V ; H ′ \mathcal{H} \mathrel{;} D \rightsquigarrow^{\varphi}_{p} V \mathrel{;} \mathcal{H}' H ; D ⇝ p φ V ; H ′ , then H ′ ; D \mathcal{H}' \mathrel{;} D H ′ ; D is consistent with V V V at p p p .
Proof. By induction on the length of the step sequence, relying on type soundness and the fact that subcomputations in bodies are pure. Appendix A.5 contains a full proof. □
Lambda-React-Ref: A Canonical Stateful Calculus
Our second reactive calculus λ r e f r e a c t \lambda_{\mathrm{ref}}^{\mathrm{react}} λ ref react extends λ p u r e r e a c t \lambda_{\mathrm{pure}}^{\mathrm{react}} λ pure react with components based on ML-style references .
Syntax and Typing Rules
Figure 5 (top) shows the syntax and typing rules of λ r e f r e a c t \lambda_{\mathrm{ref}}^{\mathrm{react}} λ ref react . Ref A A A is the type of references containing values of type A A A . All previous typing judgments are straightforwardly extended with the additional context Σ \Sigma Σ , so we concentrate on new constructs.
Figure 5. Additional syntax, typing rules, and reduction rules for λ r e f r e a c t \lambda_{\mathrm{ref}}^{\mathrm{react}} λ ref react .
Stateful components are encoded in λ r e f r e a c t \lambda_{\mathrm{ref}}^{\mathrm{react}} λ ref react via the component V V V constructor (with typing rule TV-Comp), where V V V is a function of type 1 → A c o m p 1 \to A_{\mathrm{comp}} 1 → A comp , and A c o m p A_{\mathrm{comp}} A comp abbreviates ( 1 → E l e m e n t ) × R e f B o o l × E l e m e n t (1 \to\mathrm{Element}) \times\mathrm{Ref\ Bool} \times\mathrm{Element} ( 1 → Element ) × Ref Bool × Element . This function will close over any references describing state required by the component and will return a triple. The three constituent types are as follows:
( 1 → E l e m e n t ) (1 \to\mathrm{Element}) ( 1 → Element ) is a rendering function that produces an Element based on the current state.
Ref Bool is a rerender flag that contains true if the component needs rerendered.
Element is the initial element returned by the component.
Like in λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react , instances compInst (with typing rule TV-CompI) are the realizations of components, and their three arguments correspond to the three constituents of type A c o m p A_{\mathrm{comp}} A comp , except that the
Syntax
Types A : : = ⋯ ∣ R e f A A ::= \cdots\mid\mathrm{Ref}\ A A ::= ⋯ ∣ Ref A
Values V , W : : = ⋯ ∣ c o m p o n e n t V ∣ c o m p I n s t ( V 1 , V 2 , V 3 ) ∣ ℓ V,W ::= \cdots\mid\mathrm{component}\ V \mid\mathrm{compInst}(V_1,V_2,V_3) \mid\ell V , W ::= ⋯ ∣ component V ∣ compInst ( V 1 , V 2 , V 3 ) ∣ ℓ
Computations e : : = ⋯ ∣ r e f V ∣ ! V ∣ V : = W e ::= \cdots\mid\mathrm{ref}\ V \mid{!}V \mid V := W e ::= ⋯ ∣ ref V ∣ ! V ∣ V := W
Store σ : : = ∅ ∣ σ , ℓ ↦ V \sigma::= \varnothing\mid\sigma,\ell\mapsto V σ ::= ∅ ∣ σ , ℓ ↦ V
Store type Σ : : = ∅ ∣ Σ , ℓ ↦ A \Sigma::= \varnothing\mid\Sigma,\ell\mapsto A Σ ::= ∅ ∣ Σ , ℓ ↦ A
Typing Rules for Values and Computations
Γ ; Σ ⊢ V : A \Gamma;\Sigma\vdash V:A Γ ; Σ ⊢ V : A
Γ ; Σ ⊢ M : A \Gamma;\Sigma\vdash M:A Γ ; Σ ⊢ M : A
TV-Comp
Γ ; Σ ⊢ V : 1 → A c o m p Γ ; Σ ⊢ c o m p o n e n t V : E l e m e n t \frac{\Gamma;\Sigma\vdash V:1\to A_{\mathrm{comp}}}{\Gamma;\Sigma\vdash\mathrm{component}\ V:\mathrm{Element}} Γ ; Σ ⊢ component V : Element Γ ; Σ ⊢ V : 1 → A comp
TV-Loc
ℓ : A ∈ Σ Γ ; Σ ⊢ ℓ : R e f A \frac{\ell:A\in\Sigma}{\Gamma;\Sigma\vdash\ell:\mathrm{Ref}\ A} Γ ; Σ ⊢ ℓ : Ref A ℓ : A ∈ Σ
TV-CompI
Γ ; Σ ⊢ V 1 : 1 → E l e m e n t Γ ; Σ ⊢ V 2 : R e f B o o l Γ ; Σ ⊢ V 3 : E l e m I n s t Γ ; Σ ⊢ c o m p I n s t ( V 1 , V 2 , V 3 ) : E l e m I n s t \frac{\Gamma;\Sigma\vdash V_1:1\to\mathrm{Element}\qquad\Gamma;\Sigma\vdash V_2:\mathrm{Ref\ Bool}\qquad\Gamma;\Sigma\vdash V_3:\mathrm{ElemInst}}{\Gamma;\Sigma\vdash\mathrm{compInst}(V_1,V_2,V_3):\mathrm{ElemInst}} Γ ; Σ ⊢ compInst ( V 1 , V 2 , V 3 ) : ElemInst Γ ; Σ ⊢ V 1 : 1 → Element Γ ; Σ ⊢ V 2 : Ref Bool Γ ; Σ ⊢ V 3 : ElemInst
TC-Ref
Γ ; Σ ⊢ V : A Γ ; Σ ⊢ r e f V : R e f A \frac{\Gamma;\Sigma\vdash V:A}{\Gamma;\Sigma\vdash\mathrm{ref}\ V:\mathrm{Ref}\ A} Γ ; Σ ⊢ ref V : Ref A Γ ; Σ ⊢ V : A
TC-Get
Γ ; Σ ⊢ V : R e f A Γ ; Σ ⊢ ! V : A \frac{\Gamma;\Sigma\vdash V:\mathrm{Ref}\ A}{\Gamma;\Sigma\vdash{!}V:A} Γ ; Σ ⊢ ! V : A Γ ; Σ ⊢ V : Ref A
TC-Set
Γ ; Σ ⊢ V : R e f A Γ ; Σ ⊢ W : A Γ ; Σ ⊢ V : = W : 1 \frac{\Gamma;\Sigma\vdash V:\mathrm{Ref}\ A\qquad\Gamma;\Sigma\vdash W:A}{\Gamma;\Sigma\vdash V:=W:1} Γ ; Σ ⊢ V := W : 1 Γ ; Σ ⊢ V : Ref A Γ ; Σ ⊢ W : A
Reduction Rules
σ ; M ⇝ N ; σ ′ \sigma;M\rightsquigarrow N;\sigma' σ ; M ⇝ N ; σ ′
σ ; r e f V ⇝ v a l ℓ ; σ , ℓ ↦ V , ( ℓ fresh ) E C - R e f \sigma;\mathrm{ref}\ V\rightsquigarrow\mathrm{val}\ \ell;\sigma,\ell\mapsto V,\quad(\ell\ \text{fresh}) \qquad\mathrm{EC\text{-}Ref} σ ; ref V ⇝ val ℓ ; σ , ℓ ↦ V , ( ℓ fresh ) EC - Ref
σ ; ! ℓ ⇝ v a l ( σ [ ℓ ] ) ; σ E C - G e t \sigma; {!}\ell\rightsquigarrow\mathrm{val}\bigl(\sigma[\ell]\bigr);\sigma\qquad\mathrm{EC\text{-}Get} σ ; ! ℓ ⇝ val ( σ [ ℓ ] ) ; σ EC - Get
σ ; ℓ : = V ⇝ v a l ( ) ; σ [ ℓ ↦ V ] E C - S e t \sigma;\ell:=V\rightsquigarrow\mathrm{val}();\sigma[\ell\mapsto V] \qquad\mathrm{EC\text{-}Set} σ ; ℓ := V ⇝ val ( ) ; σ [ ℓ ↦ V ] EC - Set
σ ; i n i t ( c o m p o n e n t V ) ⇝ l e t r r , f , x = V ( ) i n ( v a l c o m p I n s t ( r r , f , i n i t x ) ) ; σ E C - I n i t C o m p \sigma;\mathrm{init}(\mathrm{component}\ V)\rightsquigarrow
\mathrm{let}\ rr,f,x=V() \ \mathrm{in}\
(\mathrm{val}\ \mathrm{compInst}(rr,f,\mathrm{init}\ x));\sigma
\qquad\mathrm{EC\text{-}InitComp} σ ; init ( component V ) ⇝ let r r , f , x = V ( ) in ( val compInst ( r r , f , init x )) ; σ EC - InitComp
σ ; u p d a t e ( c o m p I n s t ( V 1 , V 2 , V 3 ) ) ⇝ l e t x = i f ! V 2 t h e n V 2 : = f a l s e ; i n i t ( V 1 ( ) ) e l s e u p d a t e V 3 i n ( v a l c o m p I n s t ( V 1 , V 2 , x ) ) ; σ E C - U p d a t e C o m p \sigma;\mathrm{update}(\mathrm{compInst}(V_1,V_2,V_3))\rightsquigarrow
\mathrm{let}\ x=\mathrm{if}\ {!}V_2
\ \mathrm{then}\ V_2:=\mathrm{false};\mathrm{init}(V_1())
\ \mathrm{else}\ \mathrm{update}\ V_3\ \mathrm{in}\
(\mathrm{val}\ \mathrm{compInst}(V_1,V_2,x));\sigma
\qquad\mathrm{EC\text{-}UpdateComp} σ ; update ( compInst ( V 1 , V 2 , V 3 )) ⇝ let x = if ! V 2 then V 2 := false ; init ( V 1 ( )) else update V 3 in ( val compInst ( V 1 , V 2 , x )) ; σ EC - UpdateComp
σ ; c l i c k i d ( c o m p I n s t ( V 1 , V 2 , V 3 ) ) ⇝ c l i c k i d V 3 ; σ E C - C l i c k C o m p \sigma;\mathrm{click}_{id}(\mathrm{compInst}(V_1,V_2,V_3))\rightsquigarrow
\mathrm{click}_{id}\ V_3;\sigma
\qquad\mathrm{EC\text{-}ClickComp} σ ; click i d ( compInst ( V 1 , V 2 , V 3 )) ⇝ click i d V 3 ; σ EC - ClickComp
Element has been instantiated into an ElemInst. From left to right, the arguments represent the rerendering function, the rerender flag, and the current sub-instance.
All other syntactic extensions concern references: ℓ \ell ℓ ranges over locations that are generated fresh at runtime, and our three new computations, ref V \operatorname{ref}\ V ref V , ! V !\ V ! V , and V : = W V := W V := W , create, retrieve, and update locations, respectively. Their typing rules are standard. Rule TV-Loc types a location and is the only place we use Σ \Sigma Σ in the term typing judgment. A store σ \sigma σ is a map from locations to values, and a store type Σ \Sigma Σ is a map from locations to types.
Canonicity. As with λ p u r e r e a c t \lambda^{\mathrm{react}}_{\mathrm{pure}} λ pure react (§ 3.1 ), elements and their instances—specifically, the component and compInst constructors—can be expressed as inductive datatypes. init is still a fold on elements, and update is still a fold on instances. Thus, although these new constructs and their rules may appear quite ad-hoc, we maintain that they are straightforwardly expressible in terms of more canonical constructs, and that the only truly new feature in λ r e f r e a c t \lambda^{\mathrm{react}}_{\mathrm{ref}} λ ref react is references.
Operational Semantics
Figure 5 (bottom) shows the reduction rules for λ r e f r e a c t \lambda^{\mathrm{react}}_{\mathrm{ref}} λ ref react . We extend both previous step judgments ⇝ \rightsquigarrow ⇝ and ⇝ ⊤ \rightsquigarrow_{\top} ⇝ ⊤ with a store σ \sigma σ , and amend all previous rules accordingly. The first three rules (EC-Ref, EC-Get, and EC-Set) implement the standard semantics for general references. The remaining rules add support for components and instances to the runtime: due to the size of the reduction rules, we present them using syntactic sugar. Rule EC-InitComp initializes a component component V V V . It evaluates the component’s function to return r r rr r r (the rendering function), f f f (the render flag), and x x x (the Element returned by the component) before instantiating x x x and creating a compInst. Rule EC-UpdateComp handles updating a component instance. Given a component instance compInst(V 1 , V 2 , V 3 V_1,V_2,V_3 V 1 , V 2 , V 3 ), the rule firstly dereferences the render flag V 2 V_2 V 2 . If this is set to true then the component must be rerendered, so the rule will reset the flag and reinitialize the element resulting from reinvoking the rendering function. If the component does not need rerendering, then the rule will propagate the update to the current realized element. Finally, rule EC-ClickComp propagates a click past a component instance and to its child instance.
Metatheory
λ r e f r e a c t \lambda^{\mathrm{react}}_{\mathrm{ref}} λ ref react enjoys syntactic type soundness with respect to both of its step judgments. As usual, we include only the statements for ⇝ ⊤ \rightsquigarrow_{\top} ⇝ ⊤ here. The store typing judgment Γ ; Σ ⊢ σ \Gamma;\Sigma\vdash\sigma Γ ; Σ ⊢ σ holds iff dom ( Σ ) = dom ( σ ) \operatorname{dom}(\Sigma)=\operatorname{dom}(\sigma) dom ( Σ ) = dom ( σ ) and, for all ℓ ∈ dom ( σ ) \ell\in\operatorname{dom}(\sigma) ℓ ∈ dom ( σ ) , we have Γ ; Σ ⊢ σ [ ℓ ] : Σ [ ℓ ] \Gamma;\Sigma\vdash\sigma[\ell] : \Sigma[\ell] Γ ; Σ ⊢ σ [ ℓ ] : Σ [ ℓ ] .
Theorem 5.1 (Type Soundness for ⇝ ⊤ \rightsquigarrow_{\top} ⇝ ⊤ ).
Preservation: If Γ ; Σ ⊢ M : E l e m I n s t \Gamma;\Sigma\vdash M : \mathrm{ElemInst} Γ ; Σ ⊢ M : ElemInst with Γ ; Σ ⊢ σ \Gamma;\Sigma\vdash\sigma Γ ; Σ ⊢ σ , and σ ; M ⇝ N ; σ ′ \sigma;M \rightsquigarrow N;\sigma' σ ; M ⇝ N ; σ ′ , then for some Σ ′ ⊇ Σ \Sigma' \supseteq\Sigma Σ ′ ⊇ Σ , we have that Γ ; Σ ′ ⊢ N : E l e m I n s t \Gamma;\Sigma' \vdash N : \mathrm{ElemInst} Γ ; Σ ′ ⊢ N : ElemInst and Γ ; Σ ′ ⊢ σ ′ \Gamma;\Sigma' \vdash\sigma' Γ ; Σ ′ ⊢ σ ′ .
Progress: If ∅ ; Σ ⊢ M : A \varnothing;\Sigma\vdash M : A ∅ ; Σ ⊢ M : A and ∅ ; Σ ⊢ σ \varnothing;\Sigma\vdash\sigma ∅ ; Σ ⊢ σ , then σ ; M ⇝ N ; σ ′ \sigma;M \rightsquigarrow N;\sigma' σ ; M ⇝ N ; σ ′ for some N N N and σ ′ \sigma' σ ′ .
Proof. By case-analysis on M ⇝ N M \rightsquigarrow N M ⇝ N and ∅ ⊢ M : A \varnothing\vdash M : A ∅ ⊢ M : A respectively, with appeal to Theorem 3.1 . □ \square □
A Translation from Hooks to References
In this section, we define a translation from λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react (the source language) to λ r e f r e a c t \lambda^{\mathrm{react}}_{\mathrm{ref}} λ ref react (the target language), thereby demonstrating the expressibility of hook-indexed state in terms of first-class references. We first define our metatypes (6.1) and the prerequisite machinery (6.2) before presenting the translation (6.3), proving its formal correctness (6.4), and then discussing its other properties (6.5).
Metatypes
As a presentation aid, we often provide the metatypes of the functions presented in this section. We construct metatypes via function arrows → \to → and products × \times × , as usual. We write f ( x ) = ⊥ f(x) = \bot f ( x ) = ⊥ if a function result f ( x ) f(x) f ( x ) is undefined and we subscript a type with ⊥ \bot ⊥ to indicate that it may be undefined. We use A ⇀ B A \rightharpoonup B A ⇀ B to abbreviate A → B ⊥ A \to B_{\bot} A → B ⊥ , which describes a partial function from A A A to B B B .
Syntactic categories of the source language are all prefixed with Hook. They include HookType for types, HookTypeCtx for type contexts, HookValue for values, HookComp for computations, HookBody for bodies, HookHeap for heaps, HookHeapCtx for heap contexts, HookPtr for pointers, HookLabel for labels, and HookID for identifiers. Syntactic categories of the target language are similarly prefixed with Ref, and are analogous. RefLoc refers to locations, RefStore refers to stores, and RefStoreCtx refers to store contexts. Notation x : A x : A x : A means that x x x has metatype A A A , and we use set inclusion X ⊆ A X \subseteq A X ⊆ A to say that all x ∈ X x \in X x ∈ X have x : A x : A x : A .
Machinery
Runtime Environment
Both the source and target languages dynamically generate information at runtime, namely identifiers, pointers, and locations. To show a semantic correspondence, we must not only be able to translate this dynamic information: we must be able to assert the equality of a fresh source-language construct with its fresh target-language counterpart. We achieve this by parameterizing our translations by a runtime environment ρ \rho ρ that witnesses the relation between dynamic constructs. The environment ρ \rho ρ consists of three partial functions: ρ i d \rho_{id} ρ i d to relate identifiers, ρ p \rho_p ρ p to relate rerender flags, and ρ ℓ \rho_\ell ρ ℓ to relate state cells. We overload ρ \rho ρ to refer to each of these functions unambiguously. It suffices to represent ρ \rho ρ as an inductively defined structure, where each function is defined with respect to the contents of the structure.
ρ : : = ∅ ∣ ρ , i d ↦ i d ′ ∣ ρ , p ↦ ℓ ∣ ρ , ( p , ℓ ) ↦ ℓ ′ \rho::= \varnothing\mid\rho, id \mapsto id' \mid\rho, p \mapsto\ell\mid\rho, (p,\ell) \mapsto\ell' ρ ::= ∅ ∣ ρ , i d ↦ i d ′ ∣ ρ , p ↦ ℓ ∣ ρ , ( p , ℓ ) ↦ ℓ ′
ρ i d : H o o k I D ⇀ R e f I D ρ p : H o o k P t r ⇀ R e f L o c ρ ℓ : H o o k P t r × H o o k L a b e l ⇀ R e f L o c \rho_{id} : \mathrm{HookID} \rightharpoonup\mathrm{RefID} \qquad\rho_p : \mathrm{HookPtr} \rightharpoonup\mathrm{RefLoc} \qquad\rho_\ell: \mathrm{HookPtr} \times\mathrm{HookLabel} \rightharpoonup\mathrm{RefLoc} ρ i d : HookID ⇀ RefID ρ p : HookPtr ⇀ RefLoc ρ ℓ : HookPtr × HookLabel ⇀ RefLoc
ρ i d ( i d ) ≔ { i d ′ i d ↦ i d ′ ∈ ρ ⊥ otherwise ρ p ( p ) ≔ { ℓ p ↦ ℓ ∈ ρ ⊥ otherwise ρ ℓ ( p , ℓ ) ≔ { ℓ ′ ( p , ℓ ) ↦ ℓ ′ ∈ ρ ⊥ otherwise \rho_{id}(id) \coloneqq
\begin{cases}
id' & id \mapsto id' \in\rho\\
\bot& \text{otherwise}
\end{cases}
\qquad
\rho_p(p) \coloneqq
\begin{cases}
\ell& p \mapsto\ell\in\rho\\
\bot& \text{otherwise}
\end{cases}
\qquad
\rho_\ell(p,\ell) \coloneqq
\begin{cases}
\ell' & (p,\ell) \mapsto\ell' \in\rho\\
\bot& \text{otherwise}
\end{cases} ρ i d ( i d ) : = { i d ′ ⊥ i d ↦ i d ′ ∈ ρ otherwise ρ p ( p ) : = { ℓ ⊥ p ↦ ℓ ∈ ρ otherwise ρ ℓ ( p , ℓ ) : = { ℓ ′ ⊥ ( p , ℓ ) ↦ ℓ ′ ∈ ρ otherwise
Environment ρ \rho ρ has metatype RunEnv, an alias for the product of the metatypes of its three parts.
Sufficiency. If an invocation of ρ \rho ρ within a translation results in ⊥ \bot ⊥ , we say the entire translation result is undefined, i.e. our translation functions are likewise partial. We therefore require a means of specifying when a runtime environment is sufficient to define a particular translation result.
Definition 6.1. For a set of identifiers I ⊆ H o o k I D I \subseteq\mathrm{HookID} I ⊆ HookID , define Π ; I ⊨ ρ \Pi; I \models\rho Π ; I ⊨ ρ to hold iff ρ \rho ρ is injective and:
i d ∈ I ⇒ ρ ( i d ) ≠ ⊥ p ∈ dom ( Π ) ⇒ ρ ( p ) ≠ ⊥ ℓ ∈ Π [ p ] ⇔ ρ ( p , ℓ ) ≠ ⊥ id \in I \Rightarrow\rho(id) \ne\bot
\qquad
p \in\operatorname{dom}(\Pi) \Rightarrow\rho(p) \ne\bot
\qquad
\ell\in\Pi[p] \Leftrightarrow\rho(p,\ell) \ne\bot i d ∈ I ⇒ ρ ( i d ) = ⊥ p ∈ dom ( Π ) ⇒ ρ ( p ) = ⊥ ℓ ∈ Π [ p ] ⇔ ρ ( p , ℓ ) = ⊥
Only the rightmost condition above requires bi-implication, since the freshness of identifiers and pointers is always given directly by the operational semantics, whereas that of pointer/label pairs must be deduced from the typing judgments.
We also define the function ids \operatorname{ids} ids on source-language terms and heaps to extract the set of identifiers in the term or heap. We elide the definition, which is standard, and trivial except at tagInst i d ( V , W ) \operatorname{tagInst}_{id}(V,W) tagInst i d ( V , W ) .
Location Variable Environment
Our body translation frequently generates fresh variables x ℓ x_\ell x ℓ that are let-bound to references and occur again later in the translation process. The translation of a static body can essentially be achieved by a label-variable mapping. However, this simple strategy is unable to reason about intermediate evaluation stages wherein x ℓ x_\ell x ℓ has already been bound and so should no longer occur free in the rest of the translation.
To reason about these variables, we define another environment δ \delta δ , which maps labels (and the distinguished rerender flag flag) to variables, without mention of a particular pointer ρ \rho ρ . We use δ \delta δ to specify two partial functions parameterized by ρ \rho ρ , such that if there is no variable in δ \delta δ corresponding to the input, then we invoke ρ \rho ρ appropriately. Intuitively, if a variable is in the range of δ \delta δ , it was bound previously in the translation; if not, then we have some raw location (given by ϱ \varrho ϱ ) instead. Environment δ \delta δ has metatype VarEnv, an alias for the product of the metatypes of its two parts.
δ : : = ∅ ∣ δ , f l a g ↦ x ∣ δ , ℓ ↦ x ℓ \delta::= \varnothing\mid\delta, \mathit{flag} \mapsto x \mid\delta, \ell\mapsto x_{\ell} δ ::= ∅ ∣ δ , flag ↦ x ∣ δ , ℓ ↦ x ℓ
δ ( p , ϱ ) : H o o k P t r ⊥ × R u n E n v ⇀ R e f V a l u e δ ( p , ℓ , ϱ ) : H o o k P t r ⊥ × H o o k L a b × R u n E n v ⇀ R e f V a l u e \delta(p,\varrho) : \mathrm{HookPtr}_{\perp} \times\mathrm{RunEnv} \rightharpoonup\mathrm{RefValue}
\qquad
\delta(p,\ell,\varrho) : \mathrm{HookPtr}_{\perp} \times\mathrm{HookLab} \times\mathrm{RunEnv} \rightharpoonup\mathrm{RefValue} δ ( p , ϱ ) : HookPtr ⊥ × RunEnv ⇀ RefValue δ ( p , ℓ , ϱ ) : HookPtr ⊥ × HookLab × RunEnv ⇀ RefValue
δ ( p , ϱ ) ≜ { x if f l a g ↦ x ∈ δ ϱ ( p ) otherwise δ ( p , ℓ , ϱ ) ≜ { x if ℓ ↦ x ∈ δ ϱ ( p , ℓ ) otherwise \delta(p,\varrho) \triangleq
\begin{cases}
x & \text{if } \mathit{flag} \mapsto x \in\delta\\
\varrho(p) & \text{otherwise}
\end{cases}
\qquad
\delta(p,\ell,\varrho) \triangleq
\begin{cases}
x & \text{if } \ell\mapsto x \in\delta\\
\varrho(p,\ell) & \text{otherwise}
\end{cases} δ ( p , ϱ ) ≜ { x ϱ ( p ) if flag ↦ x ∈ δ otherwise δ ( p , ℓ , ϱ ) ≜ { x ϱ ( p , ℓ ) if ℓ ↦ x ∈ δ otherwise
Sufficiency. As with ϱ \varrho ϱ , we require a notion of a sufficient δ \delta δ that leads to a well-defined translation. We also concern ourselves here with (target-language) well-typedness, and so we define δ \delta δ -sufficiency with respect to a label record L \mathcal{L} L . We can achieve well-definedness through either the contents of δ \delta δ or ϱ \varrho ϱ : in the former case, we have a variable (which should be typed by target-language context Γ \Gamma Γ ), and in the latter, we have a location (which will be typed by the translation of Π \Pi Π ).
Definition 6.2. Define Γ ; Π ⊨ p δ : L \Gamma\mathbin{;} \Pi\models_{p} \delta: \mathcal{L} Γ ; Π ⊨ p δ : L to hold iff:
for all ℓ : A ∈ L \ell: A \in\mathcal{L} ℓ : A ∈ L , either ℓ ↦ x ℓ ∈ δ \ell\mapsto x_{\ell} \in\delta ℓ ↦ x ℓ ∈ δ and x ℓ : R e f ⟦ A ⟧ ∈ Γ x_{\ell} : \mathrm{Ref}\ \llbracket A \rrbracket\in\Gamma x ℓ : Ref [ [ A ] ] ∈ Γ , or ℓ ∉ dom ( δ ) \ell\notin\operatorname{dom}(\delta) ℓ ∈ / dom ( δ ) and ℓ : A ∈ Π [ p ] \ell: A \in\Pi[p] ℓ : A ∈ Π [ p ] ,
and either f l a g ↦ x f ∈ δ \mathit{flag} \mapsto x_f \in\delta flag ↦ x f ∈ δ and x f : R e f B o o l ∈ Γ x_f : \mathrm{Ref}\ \mathrm{Bool} \in\Gamma x f : Ref Bool ∈ Γ , or f l a g ∉ dom ( δ ) \mathit{flag} \notin\operatorname{dom}(\delta) flag ∈ / dom ( δ ) and p ∈ dom ( Π ) p \in\operatorname{dom}(\Pi) p ∈ dom ( Π ) .
If p = ⊥ p = \perp p =⊥ , then the judgment may still hold if the contents of δ \delta δ are sufficient.
Translation
We can now present our translation in full. We overload the translation brackets ⟦ ⋅ ⟧ \llbracket\cdot\rrbracket [ [ ⋅ ] ] on each syntactic category of λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react . We omit the standard translation cases.
Types and Contexts. The translation on types is entirely standard, and is not parameterized by ϱ \varrho ϱ . The only non-trivial case strips effect annotations from function arrows, since λ r e f r e a c t \lambda^{\mathrm{react}}_{\mathrm{ref}} λ ref react has no effect system. The type context translation on Γ \Gamma Γ is defined pointwise on type contexts, and the phase context Φ \Phi Φ has no translation because it has no analog in λ r e f r e a c t \lambda^{\mathrm{react}}_{\mathrm{ref}} λ ref react .
Values, Computations, Bodies. The translation on values is given by the homomorphic extension of the following equations.
⟦ ⋅ ⟧ : H o o k V a l u e → R u n E n v ⇀ R e f V a l u e \llbracket\cdot\rrbracket: \mathrm{HookValue} \to\mathrm{RunEnv} \rightharpoonup\mathrm{RefValue} [ [ ⋅ ] ] : HookValue → RunEnv ⇀ RefValue
⟦ tagInst i d ( V , W ) ⟧ ϱ ≜ tagInst ϱ ( i d ) ( ⟦ V ⟧ ϱ , ⟦ W ⟧ ϱ ) \llbracket\operatorname{tagInst}_{id}(V,W) \rrbracket_{\varrho} \triangleq\operatorname{tagInst}_{\varrho(id)}(\llbracket V \rrbracket_{\varrho}, \llbracket W \rrbracket_{\varrho}) [ [ tagInst i d ( V , W ) ] ] ϱ ≜ tagInst ϱ ( i d ) ( [ [ V ] ] ϱ , [ [ W ] ] ϱ )
⟦ set p ℓ ⟧ ϱ ≜ λ x . ( ϱ ( p , ℓ ) : = x ; ϱ ( p ) : = t r u e ) \llbracket\operatorname{set}_{p}^{\ell} \rrbracket_{\varrho} \triangleq\lambda x.\bigl(\varrho(p,\ell) := x \mathbin{;} \varrho(p) := \mathrm{true}\bigr) [ [ set p ℓ ] ] ϱ ≜ λ x . ( ϱ ( p , ℓ ) := x ; ϱ ( p ) := true )
⟦ component { D } ⟧ ϱ ≜ component ( λ ( ) . let x = ref ( f a l s e ) in I ⟦ D ⟧ ( D , ⊥ , ϱ , f l a g ↦ x ) ) \llbracket\operatorname{component}\ \{D\} \rrbracket_{\varrho} \triangleq\operatorname{component}\bigl(\lambda().\operatorname{let}\ x = \operatorname{ref}(\mathrm{false})\ \operatorname{in}\ \mathcal{I}\llbracket D\rrbracket(D,\perp,\varrho,\mathit{flag} \mapsto x)\bigr) [ [ component { D } ] ] ϱ ≜ component ( λ ( ) . let x = ref ( false ) in I [ [ D ] ] ( D , ⊥ , ϱ , flag ↦ x ) )
⟦ compInst p ( ⌈ D ⌉ , V ) ⟧ ϱ ≜ val ( compInst ( λ ( ) . S ⟦ D ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , ⟦ V ⟧ ϱ ) ) \llbracket\operatorname{compInst}_{p}(\lceil D\rceil,V) \rrbracket_{\varrho} \triangleq\operatorname{val}\bigl(\operatorname{compInst}(\lambda().\mathcal{S}\llbracket D\rrbracket(p,\varrho,\varnothing),\varrho(p),\llbracket V\rrbracket_{\varrho})\bigr) [ [ compInst p (⌈ D ⌉ , V ) ] ] ϱ ≜ val ( compInst ( λ ( ) . S [ [ D ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , [ [ V ] ] ϱ ) )
For tags, we lookup i d id i d in ϱ \varrho ϱ to obtain the corresponding target-language identifier. Primitive setters become functions that set the appropriate location to the given value, determined by ϱ ( p , ℓ ) \varrho(p,\ell) ϱ ( p , ℓ ) , and also indicate that a rerender should be performed by setting location ϱ ( p ) \varrho(p) ϱ ( p ) . Components invoke the initial -phase body translation I ⟦ ⋅ ⟧ ( D , p , ϱ , δ ) \mathcal{I}\llbracket\cdot\rrbracket(D,p,\varrho,\delta) I [ [ ⋅ ] ] ( D , p , ϱ , δ ) . Notably, D D D is passed as parameter twice to this translation, which results in the code duplication discussed in § 1 : the bracketed D D D is translated in initial phase, wherein at base case, the parenthesized D D D is then translated in the successor phase. Beforehand, we also create a reference to hold a rerender flag, bound to variable x x x , and pass this to the body translation via δ \delta δ . Instances, our final notable values, contain the rerender flag ϱ ( p ) \varrho(p) ϱ ( p ) and invoke the successor -phase body translation S ⟦ ⋅ ⟧ ( p , ϱ , δ ) \mathcal{S}\llbracket\cdot\rrbracket(p,\varrho,\delta) S [ [ ⋅ ] ] ( p , ϱ , δ ) to obtain a rerender function.
For computations, the two most interesting cases concern body evaluation.
⟦ ⋅ ⟧ : H o o k C o m p → R u n E n v ⇀ R e f C o m p \llbracket\cdot\rrbracket: \mathrm{HookComp} \to\mathrm{RunEnv} \rightharpoonup\mathrm{RefComp} [ [ ⋅ ] ] : HookComp → RunEnv ⇀ RefComp
⟦ [ D 0 ] ψ I n i t D ⟧ ϱ ≜ let r f , x = I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) in val ( compInst ( r f , f , init x ) ) \llbracket[D_0]_{\psi}^{\mathrm{Init}}\ D \rrbracket_{\varrho} \triangleq\operatorname{let}\ \mathit{rf},x = \mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\varnothing)\ \operatorname{in}\ \operatorname{val}\bigl(\operatorname{compInst}(\mathit{rf},f,\operatorname{init}\ x)\bigr) [ [ [ D 0 ] ψ Init D ] ] ϱ ≜ let rf , x = I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) in val ( compInst ( rf , f , init x ) )
⟦ [ [ D 0 ] ↓ ψ S u c c D ] ⟧ ϱ ≜ val ( compInst ( λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , init ( S ⟦ D ⟧ ( p , ϱ , ∅ ) ) ) ) \llbracket[[D_0]\downarrow_{\psi}^{\mathrm{Succ}}\ D]\rrbracket_{\varrho} \triangleq\operatorname{val}\bigl(\operatorname{compInst}(\lambda().\mathcal{S}\llbracket D_0\rrbracket(p,\varrho,\varnothing),\varrho(p),\operatorname{init}\ (\mathcal{S}\llbracket D\rrbracket(p,\varrho,\varnothing)))\bigr) [ [ [[ D 0 ] ↓ ψ Succ D ] ] ] ϱ ≜ val ( compInst ( λ ( ) . S [ [ D 0 ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , init ( S [ [ D ] ] ( p , ϱ , ∅ ))) )
Initial-phase body evaluation ⌈ D 0 ⌉ ⇓ p I n i t D \lceil D_0 \rceil\mathrel{\Downarrow^{\mathrm{Init}}_p} D ⌈ D 0 ⌉ ⇓ p Init D invokes the initial-phase translation on D D D but parameterized by D 0 D_0 D 0 , and plumbs the results into an instance. Successor-phase body evaluation ⌈ D 0 ⌉ ⇓ p S u c c D \lceil D_0 \rceil\mathrel{\Downarrow^{\mathrm{Succ}}_p} D ⌈ D 0 ⌉ ⇓ p Succ D invokes the successor-phase translation twice : once on D 0 D_0 D 0 , representing the original rerender function, and once on D D D , representing the current evaluation state.
Finally, bodies are translated with two functions, corresponding to the two phases.
S ⟦ ⋅ ⟧ : HookBody → ( HookPtr ⊥ × RunEnv × VarEnv ) ⇀ RefComp \mathcal{S}\llbracket\cdot\rrbracket: \operatorname{HookBody} \to(\operatorname{HookPtr}_{\perp} \times\operatorname{RunEnv} \times\operatorname{VarEnv}) \rightharpoonup\operatorname{RefComp} S [ [ ⋅ ] ] : HookBody → ( HookPtr ⊥ × RunEnv × VarEnv ) ⇀ RefComp
S ⟦ val V ⟧ ( p , ϱ , δ ) ≜ val ⟦ V ⟧ ϱ S ⟦ let x = M in D ⟧ ( p , ϱ , δ ) ≜ let x = ⟦ M ⟧ ϱ in S ⟦ D ⟧ ( p , ϱ , δ ) S ⟦ let x , x s e t = useState ℓ V in D ⟧ ( p , ϱ , δ ) ≜ let x = ! δ ( p , ℓ , ϱ ) in let x s e t = val ( λ y . ( δ ( p , ℓ , ϱ ) : = y ; δ ( p , ϱ ) : = true ) ) in S ⟦ D ⟧ ( p , ϱ , δ ) \begin{aligned}
\mathcal{S}\llbracket\operatorname{val}\ V \rrbracket(p,\varrho,\delta) &\mathrel{\triangleq} \operatorname{val}\ \llbracket V \rrbracket_{\varrho}\\
\mathcal{S}\llbracket\operatorname{let}\ x=M\ \operatorname{in}\ D \rrbracket(p,\varrho,\delta) &\mathrel{\triangleq} \operatorname{let}\ x=\llbracket M \rrbracket_{\varrho}\ \operatorname{in}\ \mathcal{S}\llbracket D \rrbracket(p,\varrho,\delta)\\
\mathcal{S}\llbracket\operatorname{let}\ x,x_{\mathrm{set}}=\operatorname{useState}_{\ell}\ V\ \operatorname{in}\ D \rrbracket(p,\varrho,\delta) &\mathrel{\triangleq} \operatorname{let}\ x=!\delta(p,\ell,\varrho)\ \operatorname{in}\\
&\quad\operatorname{let}\ x_{\mathrm{set}}=\operatorname{val}\left(\lambda y.\left(\delta(p,\ell,\varrho):=y\ ;\ \delta(p,\varrho):=\operatorname{true}\right)\right)\ \operatorname{in}\\
&\quad\mathcal{S}\llbracket D \rrbracket(p,\varrho,\delta)
\end{aligned} S [ [ val V ] ] ( p , ϱ , δ ) S [ [ let x = M in D ] ] ( p , ϱ , δ ) S [ [ let x , x set = useState ℓ V in D ] ] ( p , ϱ , δ ) ≜ val [ [ V ] ] ϱ ≜ let x = [ [ M ] ] ϱ in S [ [ D ] ] ( p , ϱ , δ ) ≜ let x = ! δ ( p , ℓ , ϱ ) in let x set = val ( λ y . ( δ ( p , ℓ , ϱ ) := y ; δ ( p , ϱ ) := true ) ) in S [ [ D ] ] ( p , ϱ , δ )
I ⟦ ⋅ ⟧ : HookBody → ( HookBody × HookPtr ⊥ × RunEnv × VarEnv ) ⇀ RefComp \mathcal{I}\llbracket\cdot\rrbracket: \operatorname{HookBody} \to(\operatorname{HookBody} \times\operatorname{HookPtr}_{\perp} \times\operatorname{RunEnv} \times\operatorname{VarEnv}) \rightharpoonup\operatorname{RefComp} I [ [ ⋅ ] ] : HookBody → ( HookBody × HookPtr ⊥ × RunEnv × VarEnv ) ⇀ RefComp
I ⟦ val V ⟧ ( D 0 , p , ϱ , δ ) ≜ val ( λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , δ ) , δ ( p , ϱ ) , ⟦ V ⟧ ϱ ) I ⟦ let x = M in D ⟧ ( D 0 , p , ϱ , δ ) ≜ let x = ⟦ M ⟧ ϱ in I ⟦ D ⟧ ( D 0 , p , ϱ , δ ) I ⟦ let x , x s e t = useState ℓ V in D ⟧ ( D 0 , p , ϱ , δ ) ≜ let x ℓ = ref ( ⟦ V ⟧ ϱ ) in let x = ! x ℓ in let x s e t = val ( λ y . x ℓ : = y ; δ ( p , ϱ ) : = true ) in I ⟦ D ⟧ ( D 0 , p , ϱ , ( δ , ℓ ↦ x ℓ ) ) \begin{aligned}
\mathcal{I}\llbracket\operatorname{val}\ V \rrbracket(D_0,p,\varrho,\delta) &\mathrel{\triangleq} \operatorname{val}\left(\lambda().\mathcal{S}\llbracket D_0 \rrbracket(p,\varrho,\delta),\delta(p,\varrho),\llbracket V \rrbracket_{\varrho}\right)\\
\mathcal{I}\llbracket\operatorname{let}\ x=M\ \operatorname{in}\ D \rrbracket(D_0,p,\varrho,\delta) &\mathrel{\triangleq} \operatorname{let}\ x=\llbracket M \rrbracket_{\varrho}\ \operatorname{in}\ \mathcal{I}\llbracket D \rrbracket(D_0,p,\varrho,\delta)\\
\mathcal{I}\llbracket\operatorname{let}\ x,x_{\mathrm{set}}=\operatorname{useState}_{\ell}\ V\ \operatorname{in}\ D \rrbracket(D_0,p,\varrho,\delta) &\mathrel{\triangleq} \operatorname{let}\ x_{\ell}=\operatorname{ref}(\llbracket V \rrbracket_{\varrho})\ \operatorname{in}\\
&\quad\operatorname{let}\ x=!x_{\ell}\ \operatorname{in}\\
&\quad\operatorname{let}\ x_{\mathrm{set}}=\operatorname{val}\left(\lambda y.x_{\ell}:=y\ ;\ \delta(p,\varrho):=\operatorname{true}\right)\ \operatorname{in}\\
&\quad\mathcal{I}\llbracket D \rrbracket(D_0,p,\varrho,(\delta,\ell\mapsto x_{\ell}))
\end{aligned} I [ [ val V ] ] ( D 0 , p , ϱ , δ ) I [ [ let x = M in D ] ] ( D 0 , p , ϱ , δ ) I [ [ let x , x set = useState ℓ V in D ] ] ( D 0 , p , ϱ , δ ) ≜ val ( λ ( ) . S [ [ D 0 ] ] ( p , ϱ , δ ) , δ ( p , ϱ ) , [ [ V ] ] ϱ ) ≜ let x = [ [ M ] ] ϱ in I [ [ D ] ] ( D 0 , p , ϱ , δ ) ≜ let x ℓ = ref ( [ [ V ] ] ϱ ) in let x = ! x ℓ in let x set = val ( λ y . x ℓ := y ; δ ( p , ϱ ) := true ) in I [ [ D ] ] ( D 0 , p , ϱ , ( δ , ℓ ↦ x ℓ ))
Let-binding in both phases is standard, as is the value case in the successor phase. However, in the initial phase, alongside the given value we return two extra values. To obtain a rerender function, we invoke the successor-phase translation on the additional parameter D 0 D_0 D 0 and thunk the result. We also directly return the rerender flag, given by δ ( p , ϱ ) \delta(p,\varrho) δ ( p , ϱ ) .
For useState in the successor phase, we retrieve from the location δ ( p , ℓ , ϱ ) \delta(p,\ell,\varrho) δ ( p , ℓ , ϱ ) and bind it to x x x . By contrast, in the initial phase, x x x is (indirectly) bound to the initial value ⟦ V ⟧ ϱ \llbracket V \rrbracket_{\varrho} [ [ V ] ] ϱ by way of the reference bound to fresh variable x ℓ x_{\ell} x ℓ . As previously explained, this fresh variable is added to δ \delta δ in the continuation of the body translation for future reference. In either phase, we also define an appropriate setter function via the δ \delta δ -function, and bind it to x s e t x_{\mathrm{set}} x set .
Correctness
To demonstrate the correctness of our translation, we prove that our translation preserves types and that we maintain a tight operational correspondence [19 , 20 , 41 , 45 , 51 , 52 ] . This operational correspondence is a straightforward yet strong result: we do not have complications such as administrative redexes to account for, and so more semantic (and often more involved) notions of translation correctness [2 , 19 , 44 , 47 ] are unnecessary for our purposes.
Heaps and Heap Contexts. To reason about the metatheory of the translation we first need to relate λ h o o k \lambda_{\mathrm{hook}} λ hook heaps / heap contexts and λ r e f \lambda_{\mathrm{ref}} λ ref store / store contexts. The translation from λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react heaps to λ r e f r e a c t \lambda_{\mathrm{ref}}^{\mathrm{react}} λ ref react stores is given below. The expression ⟦ H [ p ] . rerender ⟧ \llbracket\mathcal{H}[p].\operatorname{rerender} \rrbracket [ [ H [ p ] . rerender ] ] invokes an obvious translation from source-language meta-booleans to target-language boolean values.
⟦ ⋅ ⟧ : HookHeap → RunEnv → RefStore \llbracket\cdot\rrbracket: \operatorname{HookHeap} \to\operatorname{RunEnv} \to\operatorname{RefStore} [ [ ⋅ ] ] : HookHeap → RunEnv → RefStore
⟦ H ⟧ ϱ ≜ ⋃ p ∈ H ( { ϱ ( p ) ↦ ⟦ H [ p ] . rerender ⟧ } ∪ ⋃ ℓ ∈ H [ p ] . st { ϱ ( p , ℓ ) ↦ ⟦ H [ p ] . st [ ℓ ] ⟧ ϱ } ) \llbracket\mathcal{H} \rrbracket_{\varrho} \triangleq\bigcup_{p\in\mathcal{H}}\left(\{\varrho(p)\mapsto\llbracket\mathcal{H}[p].\operatorname{rerender}\rrbracket\}\cup\bigcup_{\ell\in\mathcal{H}[p].\operatorname{st}}\{\varrho(p,\ell)\mapsto\llbracket\mathcal{H}[p].\operatorname{st}[\ell]\rrbracket_{\varrho}\}\right) [ [ H ] ] ϱ ≜ p ∈ H ⋃ { ϱ ( p ) ↦ [ [ H [ p ] . rerender ] ] } ∪ ℓ ∈ H [ p ] . st ⋃ { ϱ ( p , ℓ ) ↦ [ [ H [ p ] . st [ ℓ ] ] ] ϱ }
The translation on heap contexts is parameterized by ϱ \varrho ϱ , and is given as follows, wherein locations are assigned either type Bool (for rerender flags) or type ⟦ Π [ p ] [ ℓ ] ⟧ \llbracket\Pi[p][\ell]\rrbracket [ [ Π [ p ] [ ℓ ] ] ] (for state cells):
⟦ ⋅ ⟧ : HookHeapCtx → RunEnv → RefStoreCtx \llbracket\cdot\rrbracket: \operatorname{HookHeapCtx} \to\operatorname{RunEnv} \to\operatorname{RefStoreCtx} [ [ ⋅ ] ] : HookHeapCtx → RunEnv → RefStoreCtx
⟦ Π ⟧ ϱ ≜ ⋃ p ∈ Π ( { ϱ ( p ) ↦ Bool } ∪ ⋃ ℓ ∈ Π [ p ] { ϱ ( p , ℓ ) ↦ ⟦ Π [ p ] [ ℓ ] ⟧ } ) \llbracket\Pi\rrbracket_{\varrho} \triangleq\bigcup_{p\in\Pi}\left(\{\varrho(p)\mapsto\operatorname{Bool}\}\cup\bigcup_{\ell\in\Pi[p]}\{\varrho(p,\ell)\mapsto\llbracket\Pi[p][\ell]\rrbracket\}\right) [ [ Π ] ] ϱ ≜ p ∈ Π ⋃ { ϱ ( p ) ↦ Bool } ∪ ℓ ∈ Π [ p ] ⋃ { ϱ ( p , ℓ ) ↦ [ [ Π [ p ] [ ℓ ] ] ] }
Type Preservation
Well-typed constructs in λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react translate to well-typed constructs (of the same type) in λ r e f r e a c t \lambda_{\mathrm{ref}}^{\mathrm{react}} λ ref react . We prove four mutually recursive theorems on terms, as well as a fifth theorem on heaps. The statements on values, computations, and heaps are fairly standard: we require as an extra premise in each that our given ϱ \varrho ϱ is sufficient. For bodies, we prove that their translations have specific types, independent of the source-language type L \mathcal{L} L . Each body theorem uses L \mathcal{L} L to assert the sufficiency of δ \delta δ as an additional premise.
Note that all type preservation theorems ignore phase context Φ \Phi Φ and computational effects E E E , which both exist for specific source-language guarantees and have no target-language analog.
We show the most interesting theorem statement here: the case for bodies when ϕ = I n i t \phi= \mathrm{Init} ϕ = Init . All others and all proofs are located in Appendix § 14 .§ 1 .
Theorem 6.3 (Type preservation, bodies, initial). If
( i ) Γ ; Π ; Φ 1 ⊢ D : L , ( i i i ) Π ; ids ( D ) ∪ ids ( D 0 ) ⊨ ϱ , and ( i i ) Γ ; Π ; Φ 2 ⊢ D 0 : L 0 (where L ⊆ L 0 ) , ( i v ) Γ ; Π ⊨ p δ : ( L 0 ∖ L ) , \begin{aligned}
(i)\ &\Gamma\,;\,\Pi\,;\,\Phi_1 \vdash D : \mathcal{L}, \qquad
(iii)\ &\Pi\,;\,\operatorname{ids}(D)\cup\operatorname{ids}(D_0)\models\varrho,\ \text{and}\\
(ii)\ &\Gamma\,;\,\Pi\,;\,\Phi_2 \vdash D_0 : \mathcal{L}_0\ \text{(where }\mathcal{L}\subseteq\mathcal{L}_0\text{)}, \qquad
(iv)\ &\Gamma\,;\,\Pi\models_p\delta: (\mathcal{L}_0\setminus\mathcal{L}),
\end{aligned} ( i ) ( ii ) Γ ; Π ; Φ 1 ⊢ D : L , ( iii ) Γ ; Π ; Φ 2 ⊢ D 0 : L 0 (where L ⊆ L 0 ) , ( i v ) Π ; ids ( D ) ∪ ids ( D 0 ) ⊨ ϱ , and Γ ; Π ⊨ p δ : ( L 0 ∖ L ) , then ⟦ Γ ⟧ , Γ ; ⟦ Π ⟧ ϱ ⊢ I ⟦ D ⟧ ( D 0 , p , ϱ , δ ) : A c o m p \llbracket\Gamma\rrbracket,\Gamma\,;\,\llbracket\Pi\rrbracket_\varrho\vdash I\llbracket D\rrbracket(D_0,p,\varrho,\delta) : A_{\mathrm{comp}} [ [ Γ ] ] , Γ ; [ [ Π ] ] ϱ ⊢ I [ [ D ] ] ( D 0 , p , ϱ , δ ) : A comp .
Proof. By mutual induction on the typing derivation (i) alongside Theorems B.3 (values), B.4 (computations), and B.5 (bodies at successor phase). □
This theorem guarantees that the translation is well-defined in the following sense.
Definition 6.4 (Well-definedness). Call the result of a translation function ⟦ ⋅ ⟧ ϱ \llbracket\cdot\rrbracket_\varrho [ [ ⋅ ] ] ϱ well-defined iff it is a syntactically well-formed term in λ r e f r e a c t \lambda_{\mathrm{ref}}^{\mathrm{react}} λ ref react .
By definition of our translation functions, for a result to be well-defined, it suffices that all instances of ϱ ( i d ) \varrho(id) ϱ ( i d ) , ϱ ( p ) \varrho(p) ϱ ( p ) , and ϱ ( p , ℓ ) \varrho(p,\ell) ϱ ( p , ℓ ) that appear in the result are well-defined, that is, ≠ ⊥ \ne\bot = ⊥ .
Well-definedness is an obvious corollary of well-typedness in the target language. Therefore, for a translation to be well-defined on e.g. a value ⟦ V ⟧ ϱ \llbracket V\rrbracket_\varrho [ [ V ] ] ϱ , by Theorem B.3 (type preservation), it suffices to have that Γ ; Π ; Φ ⊢ V : A \Gamma\,;\,\Pi\,;\,\Phi\vdash V:A Γ ; Π ; Φ ⊢ V : A and Π ; ids ( V ) ⊨ ϱ \Pi\,;\,\operatorname{ids}(V)\models\varrho Π ; ids ( V ) ⊨ ϱ .
Simulation
We must now show that the translation is semantics-preserving: roughly, the property that if a term (e.g. M M M ) takes a step to N N N in λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react , then its translation ⟦ M ⟧ \llbracket M\rrbracket [ [ M ] ] steps to the translation ⟦ N ⟧ \llbracket N\rrbracket [ [ N ] ] in λ r e f r e a c t \lambda_{\mathrm{ref}}^{\mathrm{react}} λ ref react . However, several technical details serve to obscure the essence of this idea.
As well-definedness of our translation functions is contingent on a runtime relation ϱ \varrho ϱ , we must have as premise that ϱ \varrho ϱ is sufficient. Since this sufficiency is defined with respect to Π \Pi Π , it must be Π \Pi Π types the source-language term (and heap) in question. Moreover, we require that ϱ \varrho ϱ grows as we step (according to a partial order given by ⊑ \sqsubseteq ⊑ ), as does Π \Pi Π . To apply these theorems transitively, we must ensure that our new ϱ ′ \varrho' ϱ ′ is sufficient with respect to our new Π ′ \Pi' Π ′ , and in turn that Π ′ \Pi' Π ′ types the new term and heap. Therefore, the structure of our proofs mirrors that of λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react type preservation.
We present only the main statement for ⇝ \rightsquigarrow ⇝ here. The premises and conclusions not found in the corresponding preservation statement are typeset in blue. As usual, all other statements and all proofs can be found in Appendix § 14 .§ 2 .
Theorem 6.5 (Simulation, computations). If we have
( i ) Γ ; Π ; Φ H ; Φ M ⊢ H ; M : A ! M u t , ( i i ) Π ; ids ( M ) ∪ ids ( H ) ⊨ ϱ , and ( i i i ) H ; M ⇝ N ; H ′ , ( i ) Φ M ⊑ Φ H ⊑ f r e s h Φ N ⇝ Φ H ′ , ( i i ) Π ⊑ Φ N ⇝ Φ H ′ Π ′ , ( i i i ) Γ ; Π ′ ; Φ H ′ ; Φ N ⊢ N : A ! M u t , ( i v ) Π ′ ; ids ( N ) ∪ ids ( H ′ ) ⊨ ϱ ′ , and ( v ) ⟦ H ⟧ ϱ ; ⟦ M ⟧ ϱ ⇝ ⟦ N ⟧ ϱ ′ ; ⟦ H ′ ⟧ ϱ ′ . \begin{aligned}
(i)\ &\Gamma\,;\,\Pi\,;\,\Phi_H\,;\,\Phi_M\vdash\mathcal{H}\,;\,M:A\,!\,\mathrm{Mut},\\
(ii)\ &\Pi\,;\,\operatorname{ids}(M)\cup\operatorname{ids}(\mathcal{H})\models\varrho,\ \text{and}\\
(iii)\ &\mathcal{H}\,;\,M\rightsquigarrow N\,;\,\mathcal{H}',
\end{aligned}
\qquad
\begin{aligned}
(i)\ &\Phi_M\sqsubseteq\Phi_H\sqsubseteq_{\mathrm{fresh}}\Phi_N\rightsquigarrow\Phi_H',\\
(ii)\ &\Pi\sqsubseteq_{\Phi_N\rightsquigarrow\Phi_H'}\Pi',\\
(iii)\ &\Gamma\,;\,\Pi'\,;\,\Phi_H'\,;\,\Phi_N\vdash N:A\,!\,\mathrm{Mut},\\
(iv)\ &\Pi'\,;\,\operatorname{ids}(N)\cup\operatorname{ids}(\mathcal{H}')\models\varrho',\ \text{and}\\
(v)\ &\llbracket\mathcal{H}\rrbracket_\varrho\,;\,\llbracket M\rrbracket_\varrho\rightsquigarrow\llbracket N\rrbracket_{\varrho'}\,;\,\llbracket\mathcal{H}'\rrbracket_{\varrho'}.
\end{aligned} ( i ) ( ii ) ( iii ) Γ ; Π ; Φ H ; Φ M ⊢ H ; M : A ! Mut , Π ; ids ( M ) ∪ ids ( H ) ⊨ ϱ , and H ; M ⇝ N ; H ′ , ( i ) ( ii ) ( iii ) ( i v ) ( v ) Φ M ⊑ Φ H ⊑ fresh Φ N ⇝ Φ H ′ , Π ⊑ Φ N ⇝ Φ H ′ Π ′ , Γ ; Π ′ ; Φ H ′ ; Φ N ⊢ N : A ! Mut , Π ′ ; ids ( N ) ∪ ids ( H ′ ) ⊨ ϱ ′ , and [ [ H ] ] ϱ ; [ [ M ] ] ϱ ⇝ [ [ N ] ] ϱ ′ ; [ [ H ′ ] ] ϱ ′ . then for some Φ H ′ \Phi_H' Φ H ′ , Φ N \Phi_N Φ N , Π ′ \Pi' Π ′ , and ϱ ′ ⊒ ϱ \varrho'\sqsupseteq\varrho ϱ ′ ⊒ ϱ , we get:
Proof. By induction on H ; M ⇝ N ; H ′ \mathcal{H}\,;\,M\rightsquigarrow N\,;\,\mathcal{H}' H ; M ⇝ N ; H ′ , with appeal to Lemmas B.28 (bodies for ϕ = I n i t \phi=\mathrm{Init} ϕ = Init ) and B.27 (bodies for ϕ = S u c c \phi=\mathrm{Succ} ϕ = Succ ). □
As the semantics of the target language is deterministic we immediately obtain a backwards simulation result too [27 ] (a target-language step must lie along the unique path given by the simulation of one step in the source language, thus showing that translated terms do not “go astray”). Hence there is a tight operational correspondence between the source and target languages.
Discussion
Compositionality. The definition of our translation is entirely compositional [13 , 19 ] , except for one small deviation: when we translate a component, we parameterize the Init-phase translation by the body twice . The first parameter serves as the structural basis for the translation as normal. The second parameter remains entirely untouched until it is translated for a second time in Succ-phase: thus, the val V V V case in the Init-phase translation violates compositionality.
One can make the translation formally compositional using standard techniques such as having the translation of bodies return a pair of terms, one for Init-phase and another for Succ-phase, and using a higher-order translation to avoid introducing administrative redexes [10 ] . We choose not to follow such a path here as it makes the definition of the translation somewhat more complex.
Locality. We distinguish two senses in which the word "local" has been used in the literature to describe translations. We call the weaker sense feature-local , and it applies with respect to a particular feature , which we take to be a group of related constructs and their type formers. For instance, the "product feature" consists of the type A × B A \times B A × B , pairs ( V , W ) (V, W) ( V , W ) , and projections fst and snd. Feature-locality then means that the translation is a homomorphism over constructs which are not part of the feature in question [24 , 30 ] . We call the stronger sense macro-local , which is synonymous with macro-expressiveness as originally formulated by Felleisen [13 ] . Macro-locality implies feature-locality and additionally requires that the translations on features are specified by a fixed context, parameterized only by the translations of the subterms. These notions coincide for unparameterized translations but may diverge for parameterized ones, wherein a translation context may involve the parameters. For instance:
A CPS translation [10 , 45 ] is not feature-local (and so not macro-local), since we must thread a continuation through every computation in the language.
A translation from named variables to de Bruijn indices [11 ] is feature-local but not macro-local. Translating variables requires “non-local” information about any surrounding binders, but unrelated features (e.g. application, products if we add them, etc.) are unaffected.
Translating let x = M x = M x = M in N N N into ( λ x . N ) M (\lambda x.N)\,M ( λ x . N ) M , as in [13 ] , is macro-local (and so feature-local).
Our translation is clearly not macro-local: for instance, when translating components, δ \delta δ is used to thread “non-local” information between phases. However, the translation is feature-local, so long as we take our “feature” to consist of component values (and their instances), setters, component evaluation computations, and the syntactic category of bodies.
Duplication. A drawback of the translation is the duplication of code. The source language allows the same component body D D D to be interpreted in both phases, but to reflect this behavior in the target language, we translate D D D twice, once per phase. A programmer seeking to replicate source-language behavior in the target language would repeat themselves frequently.
It is in theory possible to remove this duplication by parameterizing target-language components appropriately (e.g. having them take as argument a “phase” and the necessary context to run under that phase). We choose not to do so in order to avoid obscuring the essence of the translation with (even) more plumbing.
Abstraction. The useState construct supports UI state in quite a general way, but also abstracts over implementation details. For instance, setters in λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react encapsulate the rerender flag, whereas a programmer working in the λ r e f r e a c t \lambda_{\mathrm{ref}}^{\mathrm{react}} λ ref react has direct access to the flag, and so can manipulate it “incorrectly”, as in the following example:
let flag = ref(false) in ...
let setX = λy. (xLoc := y ; flag := true) in ...
<div onClick={λ().setX (x+1); flag := false}>{x}</div>
By manually setting flag := false in the event handler, a subsequent update will not rerender the component, despite its state having changed. In contrast, the encapsulation in λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react prevents us from rendering stale state in this way: the only time the rerender flag can be set to ff is in rule EC-UpdateCompT, once a rerender has already begun. Our translation thus does not preserve full abstraction , in the sense that translated terms can be observably distinguished by target-language contexts (where these contexts need not be in the translation image themselves) [1 , 2 , 25 ] .
Extensions
We show how λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react can be extended to capture additional features and semantic details from React beyond those of § 5 . In particular, we address reconciliation (7.1), useEffect (7.2), and custom hooks (7.3). We only sketch the necessary adjustments, and briefly indicate how our translation approach might likewise be adapted to model the new behavior in λ r e f r e a c t \lambda_{\mathrm{ref}}^{\mathrm{react}} λ ref react .
Reconciliation
React’s runtime involves a process called reconciliation , where it will diff the old and new trees and only reinitialize the parts that have changed [26 , 35 ] . Reconciliation helps performance but also affects the preservation of state. When a component instance is updated in λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react , which lacks reconciliation, its sub-elements are always freshly reinitialized, discarding their state. Consider the following NestedCounter component that wraps the stateful Counter example seen previously:
let NestedCounter = component { let x, setX = useState(0) in
<div onClick={λ().setX (x+1)}>{x}<Counter/></div> }
The inner counter will increment as normal on click, but when the outer counter is incremented, the inner counter will reset to 0. In contrast, a reconciliation semantics will preserve the inner counter’s state, even when the outer counter’s state changes.
Extension Approach. Extending λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react with reconciliation requires carrying the prior element contents during rerendering so that, when finished, the semantics can choose whether to reinitialize. Thus the body-evaluation construct ⌈ D 0 ⌉ ⇓ ψ ϕ D \lceil D_0 \rceil\mathrel{\Downarrow}_{\psi}^{\phi} D ⌈ D 0 ⌉ ⇓ ψ ϕ D becomes ⌈ D 0 ⌉ ⇓ ψ ϕ ( V o l d , D ) \lceil D_0 \rceil\mathrel{\Downarrow}_{\psi}^{\phi} (V_{\mathrm{old}},D) ⌈ D 0 ⌉ ⇓ ψ ϕ ( V old , D ) , with the V o l d V_{\mathrm{old}} V old providing the prior contents. When rerendering terminates at a value ⌈ D 0 ⌉ ⇓ ψ ϕ ( V o l d , v a l V n e w ) \lceil D_0 \rceil\mathrel{\Downarrow}_{\psi}^{\phi} (V_{\mathrm{old}},\mathop{\mathrm{val}} V_{\mathrm{new}}) ⌈ D 0 ⌉ ⇓ ψ ϕ ( V old , val V new ) , it triggers a reconcile process that compares V o l d V_{\mathrm{old}} V old with V n e w V_{\mathrm{new}} V new , either initializing new instances or preserving the identity of tags/components shallowly and recursing to their children.
Translation Approach. The translation poses no new problems: the extension has essentially only added some data and some primitive-recursive functions. Like the other runtime computations, we treat reconcile as primitive in the target-language semantics, since it can be encoded straightforwardly in a language with recursion and appropriate destructors.
The useEffect Hook
React provides another primitive hook, useEffect, to synchronize an application with non-React code, e.g. the DOM or an external API. The useEffect hook wraps a computation M M M , which is (confusingly) named an “Effect”: this capitalized use of the word “effect” should not be confused with the effects tracked in our type system (Pure and Mut). The Effect is executed after rendering. A common use case is to dispatch an asynchronous function, so that the long-running task does not block rendering, as in the following JavaScript snippet:
const DataView = ({ dataID }) => { const x, setX = useState(null);
useEffect(() => { const startFetch = async () => { const data = await fetchData(dataID);
setX(data); };
startFetch(); }); }
When a setter is called in an Effect, React rerenders the component to display the most recent state. However, if the setter is called unconditionally, we risk an infinite loop, wherein this rerender dispatches another Effect, which triggers another rerender, and so on. Nevertheless, to express useful code like the example above, we must permit the use of setters inside Effects, and so our semantics must capture this looping behavior.
Extension Approach. We introduce an effect queue Q ‾ : : = M ‾ \overline{Q} ::= \overline{M} Q ::= M , which is initially empty, to our runtime configuration for bodies. Our new programmer-level construct, useEffect { M ‾ } \{\overline{M}\} { M } in D D D , adds the effect M ‾ : 1 ! M u t \overline{M} : 1 ! \mathit{Mut} M : 1 ! Mut to the queue (where + + + is meta-append):
⟨ H ; Q ; u s e E f f e c t { M ‾ } i n D ⟩ ⇝ φ p ⟨ H ; Q + [ M ‾ ] ; D ⟩ \langle\mathcal{H}; Q; \mathop{\mathrm{useEffect}}\{\overline{M}\}\mathop{\mathrm{in}}D\rangle\mathrel{\rightsquigarrow_{\varphi}^{p}} \langle\mathcal{H}; Q + [\overline{M}]; D\rangle ⟨ H ; Q ; useEffect { M } in D ⟩ ⇝ φ p ⟨ H ; Q + [ M ] ; D ⟩
We also extend our runtime constructs for body-evaluation and component instances to capture this queue. To traverse the element tree and flush all queues, we add a new runtime computation c o m m i t : E l e m I n s t → E l e m I n s t \mathop{\mathrm{commit}} : \mathit{ElemInst} \to\mathit{ElemInst} commit : ElemInst → ElemInst , with the following relevant rules:
H ; c o m m i t c o m p I n s t p ( D , M : : Q , V ) ⇝ ( M ; c o m m i t c o m p I n s t p ( D , Q , V ) ) ; H \mathcal{H};\mathop{\mathrm{commit}}\mathop{\mathrm{compInst}}_{p}(D,M::Q,V)\rightsquigarrow(M;\mathop{\mathrm{commit}}\mathop{\mathrm{compInst}}_{p}(D,Q,V));\mathcal{H} H ; commit compInst p ( D , M :: Q , V ) ⇝ ( M ; commit compInst p ( D , Q , V )) ; H
H ; c o m m i t c o m p I n s t p ( D , [ ] , V ) ⇝ c o m p I n s t p ( D , [ ] , c o m m i t V ) ; H \mathcal{H};\mathop{\mathrm{commit}}\mathop{\mathrm{compInst}}_{p}(D,[],V)\rightsquigarrow\mathop{\mathrm{compInst}}_{p}(D,[],\mathop{\mathrm{commit}}V);\mathcal{H} H ; commit compInst p ( D , [ ] , V ) ⇝ compInst p ( D , [ ] , commit V ) ; H
Finally, to ensure committed state changes are rendered, we add a check runtime construct which repeatedly rerenders its argument until no flags have been flipped in the process.
H ; c h e c k V ⇝ c h e c k ( c o m m i t ( u p d a t e V ) ) ; H ( i f ∃ p ∈ H . H [ p ] . r e r e n d e r = t t ) \mathcal{H};\mathop{\mathrm{check}}V\rightsquigarrow\mathop{\mathrm{check}}(\mathop{\mathrm{commit}}(\mathop{\mathrm{update}}V));\mathcal{H}\qquad(\mathop{\mathrm{if}}\ \exists p\in\mathcal{H}.\mathcal{H}[p].\mathit{rerender}=\mathit{tt}) H ; check V ⇝ check ( commit ( update V )) ; H ( if ∃ p ∈ H . H [ p ] . rerender = tt )
H ; c h e c k V ⇝ v a l V ; H ( i f ∀ p ∈ H . H [ p ] . r e r e n d e r = f f ) \mathcal{H};\mathop{\mathrm{check}}V\rightsquigarrow\mathop{\mathrm{val}}V;\mathcal{H}\qquad(\mathop{\mathrm{if}}\ \forall p\in\mathcal{H}.\mathcal{H}[p].\mathit{rerender}=\mathit{ff}) H ; check V ⇝ val V ; H ( if ∀ p ∈ H . H [ p ] . rerender = ff )
Translation Approach. Effects M M M translate as thunks, λ ( ) . M \lambda().M λ ( ) . M , and bodies into state-passing style , the state being a list of effects. Then useEffect translates as an enqueue on this state, and the final queue is saved into an (extended) compInst constructor. Runtime computations commit and check then behave analogously to the source language.
Custom Hooks
To support modularity, React allows programmers to define “custom hooks”, which amount to higher-order hooks . Custom hooks are functions which may invoke other primitive or custom hooks in sequence, as long as those invocations obey the top-level restriction with respect to the custom-hook definition. For example, we can abstract over the stateful logic in our Counter components by creating a custom useCounterState hook that exposes a specialized setter to increment the counter.
const useCounterState = () => {
const [x, setX] = useState(0);
const incrX = () => { setX(x + 1); };
return [x, incrX]; }
const TwoCounters = () => {
const [x, incrX] = useCounterState();
const [y, incrY] = useCounterState();
... }
Extension Approach. In the untyped setting, custom hooks are merely functions that may call other hooks [26 ] . Ensuring that custom hooks are safe is more complicated.
Our previous shortcut of identifying useState calls with static labels no longer works: otherwise, the two calls to useCounterState above would share state! We now let L \mathcal{L} L be a type-level list, where the list order reflects the state initialization order. State labels are allocated dynamically via a counter n n n that starts at 0, which we add to our body-evaluation configuration: this counter corresponds to an index in L \mathcal{L} L , so that our setp n ^{n}_{p} p n takes type L [ n ] \mathcal{L}[n] L [ n ] . For instance, the useState rule when ϕ = I n i t \phi= \mathit{Init} ϕ = Init would be as follows, with the significant changes greyed:
⟨ H ; n ; u s e S t a t e V ⟩ ⇝ p I n i t ⟨ H ∣ H [ p ] . s t [ n ] = V ; n + 1 ; ( V , s e t p n ) ⟩ \langle\mathcal{H};n;\mathop{\mathrm{useState}}V\rangle\mathrel{\rightsquigarrow_{p}^{\mathit{Init}}}\langle\mathcal{H}\mid\mathcal{H}[p].\mathit{st}[n]=V;n+1;(V,\mathop{\mathrm{set}}_{p}^{n})\rangle ⟨ H ; n ; useState V ⟩ ⇝ p Init ⟨ H ∣ H [ p ] . st [ n ] = V ; n + 1 ; ( V , set p n )⟩
We replace our syntactic category of component bodies with the type Hook L A \mathcal{L}\ A L A , which denotes a hook that returns type A A A and initializes state according to L \mathcal{L} L . Equipped with a standard operational semantics for return/bind, Hook forms a graded monad [17 , 18 , 23 , 43 ] , graded by the list monoid L \mathcal{L} L . We add useState as a primitive operation with type A → M u t H o o k [ A ] ( A × ( A → M u t 1 ) ) A \xrightarrow{\mathrm{Mut}} \mathop{\mathrm{Hook}} [A]\ (A \times(A \xrightarrow{\mathrm{Mut}} 1)) A Mut Hook [ A ] ( A × ( A Mut 1 )) , and we adapt our component constructor to take a hook of underlying type Element (and any grade). The grade of a hook decreases during evaluation, but we can state preservation with respect to the heap type as before.
Γ ; Π ; Φ ⊢ M : H o o k L E l e m e n t ! P u r e Γ ; Π ; Φ ⊢ c o m p o n e n t { M } : E l e m e n t \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash M : \mathop{\mathrm{Hook}}\ \mathcal{L}\ \mathrm{Element}\ !\ \mathrm{Pure}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash\mathrm{component}\ \{M\} : \mathrm{Element}} Γ ; Π ; Φ ⊢ component { M } : Element Γ ; Π ; Φ ⊢ M : Hook L Element ! Pure
Γ ; Π ; Φ ⊢ M : A ! E Γ ; Π ; Φ ⊢ r e t u r n M : H o o k ε A ! E \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash M : A\ !\ E}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash\mathrm{return}\ M : \mathop{\mathrm{Hook}}\ \varepsilon\ A\ !\ E} Γ ; Π ; Φ ⊢ return M : Hook ε A ! E Γ ; Π ; Φ ⊢ M : A ! E
Γ ; Π ; Φ ⊢ M : H o o k L 1 A ! E Γ , x : A ; Π ; Φ ⊢ N : H o o k L 2 B ! E Γ ; Π ; Φ ⊢ b i n d x ← M i n N : H o o k ( L 1 ∘ L 2 ) B ! E \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash M : \mathop{\mathrm{Hook}}\ L_1\ A\ !\ E \qquad\Gamma, x : A \mathbin{;} \Pi\mathbin{;} \Phi\vdash N : \mathop{\mathrm{Hook}}\ L_2\ B\ !\ E}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash\mathrm{bind}\ x \mathrel{\leftarrow} M\ \mathrm{in}\ N : \mathop{\mathrm{Hook}}\ (L_1 \circ L_2)\ B\ !\ E} Γ ; Π ; Φ ⊢ bind x ← M in N : Hook ( L 1 ∘ L 2 ) B ! E Γ ; Π ; Φ ⊢ M : Hook L 1 A ! E Γ , x : A ; Π ; Φ ⊢ N : Hook L 2 B ! E
Translation Approach. Our approach to translating custom hooks is similar to that of components. Every hook is first translated in Init-phase, and must return its Succ-phase interpretation alongside its return value. A hook M M M which invokes a custom hook N N N (in a bind) in Init-phase then receives N N N ’s Succ-phase interpretation, which must in turn be invoked appropriately in M M M ’s own Succ-phase interpretation. The rerender flag is still only generated at the top of a component, but we must pass it as a parameter to any custom hooks, since it must be in scope of any useState calls.
Related Work
Madsen et al. [31 ] introduced a small-step semantics to model an earlier class-based version of React. Their semantics models component lifecycles and React’s reconciliation process, but they treat state through a SetState primitive that predates hooks.
Closest to our work is React-tRace [26 ] , a detailed semantics for React hooks that aims to faithfully model React’s behaviour. Although we reuse some surface syntax and several technical ideas (e.g., separating the Init and Succ phases), our goal is different: to distil a well-behaved language that captures the essence of hook-indexed state and to characterise its expressiveness via a translation to first-class references. There are therefore many technical differences between λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react and React-tRace.
First, our stratified syntax and type-and-effect system rule out many erroneous programs that React-tRace must model. This enables significant simplifications, allowing us to use a substitution-based (rather than environment-based) semantics and to omit React’s retry behaviour. Since our focus is the expressiveness of state hooks, we also de-emphasize reconciliation and useEffect, though we outline extensions that incorporate both. Finally, our semantics uses small-step evaluation for expressions, whereas React-tRace uses a big-step relation.
Flapjax [39 ] is an early reactive web language with support for signals (time-varying values) and event streams from functional reactive programming (FRP) [12 ] . Flapjax propagates signal changes to the DOM, but has a more imperative flavor because it predates reconciliation-based approaches.
Chlipala [5 ] and Fowler et al. [16 ] describe related approaches to reactive web programming where users can create views of a mutable data source, compose views monadically, and embed views into a declarative description of a web page. Updates to the data source are propagated through a dataflow graph and are eventually reflected in the web page. This is a different model to hook-indexed state and neither work includes a formal semantics.
Elm [8 ] is a functional web programming language. Early versions of Elm [9 ] used an applicative form of FRP that disallowed higher-order signals in order to avoid memory leaks. Elm later abandoned FRP [7 ] and adopted a simpler architecture known as The Elm Architecture or Model-View-Update (MVU). MVU involves a simple event loop: a model is rendered by a view function, and the materialized view can produce messages that are processed by an update function to produce an updated model. In general, MVU is simpler than React, but can lead to larger and more monolithic data models. Fowler [15 ] formalizes MVU as a core calculus, λ M V U \lambda_{\mathrm{MVU}} λ MVU , and shows how it can be extended to incorporate linear resources. The functional IO system presented by Felleisen et al. [14 ] also implements a form of MVU that works with external events (e.g., mouse movements).
Crichton and Krishnamurthi [6 ] introduce a taxonomy of document languages : programming languages designed to produce structured text. Their article calculus, based on System F, can represent hierarchically-structured documents (including HTML) and is given a translational semantics to data types similar to our tag and text constructs. The reactive extension to the calculus supports MVU-style components that include initialization, update, and rendering functions. Their design elegantly represents reactive documents in a functional language but does not model state hooks: instead, state updates are defined with respect to a pre-defined list of events.
When it comes to understanding a feature such as state via translation, there exist multiple methodologies in the literature. Pottier [46 ] demonstrates that System F with first-class references is expressible in a calculus with recursive kinds. He defines both languages and their semantics separately, and then proves that his translation preserves types and is a simulation. By contrast, when O’Hearn and Reynolds [42 ] translate fragments of Algol into a linear λ \lambda λ -calculus, they do not give their Algol fragments a direct semantics: instead, their source languages are given semantics via translation . Both methodologies have their place; our work adopts the former approach.
Conclusion
We have proposed λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react , a core calculus that captures the essence of hook-indexed state in the style of React’s hooks and components. By endowing λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react with a type system and proving it sound, we offer a blueprint for how language designers may soundly adapt React’s hook-indexed state into their own languages. We have also defined a local translation from λ h o o k r e a c t \lambda^{\mathrm{react}}_{\mathrm{hook}} λ hook react into a more canonical language, λ r e f r e a c t \lambda^{\mathrm{react}}_{\mathrm{ref}} λ ref react , with components based on ML-style first-class references. We have thereby shown that hook-indexed state can be expressed in terms of first-class references, although the translation duplicates code and lowers the level of abstraction. Designers of languages with state that is scoped to re-instantiable blocks, and whose changes must be observed (e.g., to trigger rerendering or propagate updates), now have a principled basis for choosing between useState, ML-style references, and alternatives yet to be devised.
Disclosure of Use of AI in Research
We used AI to brainstorm names for hook-indexed state, and to suggest how to tighten a couple of weak sentences in the conclusion. AI was not used during the research itself.
Data Availability Statement
Our work has no associated artifacts.
References
A Lambda-Hook-View Proofs
Presentation. We denote deductions via inversion (in a bottom-up derivation) with a label above the conclusion, e.g.:
( 1 ) some judgment \frac{(1)}{\text{some judgment}} some judgment ( 1 )
Comparatively, we denote the use of deductions (in a top-down derivation) with a label besides the use, e.g.:
some judgment ( 1 ) ( 1 ) \frac{\text{some judgment}}{\phantom{(1)}}\ (1) ( 1 ) some judgment ( 1 )
To split up large derivations, we may also label subconclusions on the left, e.g.:
⋯ ( 1 ) some judgment \frac{\cdots}{(1)\ \text{some judgment}} ( 1 ) some judgment ⋯
We then may use (1) as a premise in a larger derivation.
Oftentimes when deriving a subconclusion, it is briefer to use an unspecified context, which we specify when using the subconclusion. For instance, we might derive the following (for some unspecified/partially specified Γ 1 \Gamma_1 Γ 1 ):
⋯ ( 1 ) Γ 1 ⊢ some judgment \frac{\cdots}{(1)\ \Gamma_1 \vdash\text{some judgment}} ( 1 ) Γ 1 ⊢ some judgment ⋯
We can then invoke (1) while specifying Γ 1 \Gamma_1 Γ 1 as so:
[ ( 1 ) , Γ 1 = Γ , x : A ] Γ ⊢ some judgment \frac{[(1),\ \Gamma_1=\Gamma,\ x:A]}{\Gamma\vdash\text{some judgment}} Γ ⊢ some judgment [( 1 ) , Γ 1 = Γ , x : A ]
Derived Rules
For the derived forms (often relating to fold) which appear in our semantics, it is often convenient to use derived rules in lieu of their lengthier primitive counterparts. Here, we present each such rule alongside its derivation.
Map. We have map V W ≜ fold ( λ x . λ a c c . V x : : a c c ) [ ] W \operatorname{map}\ V\ W \triangleq\operatorname{fold}\ (\lambda x.\lambda acc.V\ x :: acc)\ []\ W map V W ≜ fold ( λ x . λa cc . V x :: a cc ) [ ] W , where the right-hand lambda desugars to λ x . val λ a c c . let y = V x in val y : : a c c \lambda x.\operatorname{val}\ \lambda acc.\operatorname{let}\ y=V\ x\ \operatorname{in}\ \operatorname{val}\ y :: acc λ x . val λa cc . let y = V x in val y :: a cc . The derived typing rule is given as follows:
Γ ; Π ; Φ 1 ⊢ V : A → E B Γ ; Π ; Φ 2 ⊢ W : List A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ map V W : List B ! E TC-Map \frac{
\Gamma;\Pi;\Phi_1 \vdash V:A \xrightarrow{E} B
\qquad
\Gamma;\Pi;\Phi_2 \vdash W:\operatorname{List}\ A
}{
\Gamma;\Pi;\Phi_1 \bowtie\Phi_2 \vdash\operatorname{map}\ V\ W:\operatorname{List}\ B\ !\ E
}
\quad\text{TC-Map} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ map V W : List B ! E Γ ; Π ; Φ 1 ⊢ V : A E B Γ ; Π ; Φ 2 ⊢ W : List A TC-Map
We derive this rule via intermediate derivations (1)–(3) as follows for E = Pure E=\operatorname{Pure} E = Pure . A derivation for E = Mut E=\operatorname{Mut} E = Mut can be straightforwardly obtained by appropriately invoking TC-Sub throughout. We employ a (standard) weakening lemma on Γ \Gamma Γ .
\frac{\Gamma_1;\Pi;\Phi_1 \vdash V:A \mathrel{\xrightarrow{\mathrm{Pure}}} B \qquad\Gamma_1;\Pi;\varnothing\vdash x:A}{\Gamma_1;\Pi;\Phi_1 \vdash V\ x:B\ !\ \mathrm{Pure}}
\quad\mathrm{TC\mathchar`-App}
\frac{\Gamma_2;\Pi;\varnothing\vdash y:B \qquad\Gamma_2;\Pi;\varnothing\vdash acc:\mathrm{List}\ B}{\Gamma_2;\Pi;\varnothing\vdash y::acc:\mathrm{List}\ B}
\quad\mathrm{TV\mathchar`-Cons}
\frac{\Gamma_2;\Pi;\varnothing\vdash y::acc:\mathrm{List}\ B}{\Gamma_2;\Pi;\varnothing\vdash\mathrm{val}\ y::acc:\mathrm{List}\ B\ !\ \mathrm{Pure}}
\quad\mathrm{TC\mathchar`-Val}
\frac{
\left[(1),\ \Gamma_1=\Gamma,\ x:A,\ acc:\mathrm{List}\ B\right]
\qquad
\left[(2),\ \Gamma_2=\Gamma,\ x:A,\ acc:\mathrm{List}\ B,\ y:B\right]
}{
\Gamma,\ x:A,\ acc:\mathrm{List}\ B;\Pi;\Phi_1
\vdash\mathrm{let}\ y=V\ x\ \mathrm{in}\ \mathrm{val}\ y::acc:\mathrm{List}\ B\ !\ \mathrm{Pure}
}
\quad\mathrm{TC\mathchar`-Let}
\frac{
\Gamma,\ x:A;\Pi;\Phi_1
\vdash\lambda acc.\mathrm{let}\ y=V\ x\ \mathrm{in}\ \mathrm{val}\ y::acc:\mathrm{List}\ B
}{
\Gamma,\ x:A;\Pi;\Phi_1
\vdash\lambda acc.\mathrm{let}\ y=V\ x\ \mathrm{in}\ \mathrm{val}\ y::acc:
\mathrm{Pure}\mathrel{\longrightarrow}\mathrm{List}\ B
}
\quad\mathrm{TV\mathchar`-Lam}
\frac{
\Gamma,\ x:A;\Pi;\Phi_1
\vdash\lambda acc.\mathrm{let}\ y=V\ x\ \mathrm{in}\ \mathrm{val}\ y::acc:
\mathrm{Pure}\mathrel{\longrightarrow}\mathrm{List}\ B
}{
\Gamma,\ x:A;\Pi;\Phi_1
\vdash\mathrm{val}\ \lambda acc.\mathrm{let}\ y=V\ x\ \mathrm{in}\ \mathrm{val}\ y::acc:
\mathrm{Pure}\mathrel{\longrightarrow}\mathrm{List}\ B\ !\ \mathrm{Pure}
}
\quad\mathrm{TC\mathchar`-Val}
\frac{
\Gamma;\Pi;\Phi_1
\vdash\lambda x.\mathrm{val}\ \lambda acc.\mathrm{let}\ y=V\ x\ \mathrm{in}\ \mathrm{val}\ y::acc:
A\mathrel{\xrightarrow{\mathrm{Pure}}}\mathrm{List}\ B\mathrel{\xrightarrow{\mathrm{Pure}}}\mathrm{List}\ B
}{
\Gamma;\Pi;\Phi_1
\vdash\lambda x.\mathrm{val}\ \lambda acc.\mathrm{let}\ y=V\ x\ \mathrm{in}\ \mathrm{val}\ y::acc:
A\mathrel{\xrightarrow{\mathrm{Pure}}}\mathrm{List}\ B\mathrel{\xrightarrow{\mathrm{Pure}}}\mathrm{List}\ B
}
\quad\mathrm{TV\mathchar`-Lam}
\frac{
\Gamma;\Pi;\varnothing\vdash[\ ]:\mathrm{List}\ B
\qquad
\Gamma;\Pi;\Phi_2\vdash W:\mathrm{List}\ A
}{
\Gamma;\Pi;\Phi_1\mathbin{\mathsf{Z}}\Phi_2
\vdash\mathrm{fold}\ (\lambda x.\cdots)\ [\ ]\ W:\mathrm{List}\ B\ !\ \mathrm{Pure}
}
\quad\mathrm{TC\mathchar`-Fold}
List Initialization. We have i n i t s V ≜ m a p ( λ x . i n i t x ) V \mathrm{inits}\ V\mathrel{\triangleq}\mathrm{map}\ (\lambda x.\mathrm{init}\ x)\ V inits V ≜ map ( λ x . init x ) V . The derived typing rule is given as follows:
\frac{\Gamma;\Pi;\Phi\vdash V:\mathrm{List}\ \mathrm{Element}}
{\Gamma;\Pi;\Phi\vdash\mathrm{inits}\ V:\mathrm{List}\ \mathrm{ElemInst}\ !\ \mathrm{Mut}}
\quad\mathrm{TC\mathchar`-Inits}
We derive this rule using the previously derived rule TC-Map as follows:
\frac{
\Gamma,\ x:\mathrm{Element};\Pi;\varnothing\vdash x:\mathrm{Element}
}{
\Gamma,\ x:\mathrm{Element};\Pi;\varnothing\vdash\mathrm{init}\ x:\mathrm{ElemInst}\ !\ \mathrm{Mut}
}
\quad\mathrm{TC\mathchar`-Init}
\frac{
\Gamma,\ x:\mathrm{Element};\Pi;\varnothing\vdash\mathrm{init}\ x:\mathrm{ElemInst}\ !\ \mathrm{Mut}
}{
\Gamma;\Pi;\varnothing\vdash\lambda x.\mathrm{init}\ x:
\mathrm{Element}\mathrel{\xrightarrow{\mathrm{Mut}}}\mathrm{ElemInst}
}
\quad\mathrm{TV\mathchar`-Lam}
\frac{
\Gamma;\Pi;\Phi\vdash V:\mathrm{List}\ \mathrm{Element}
\qquad
\Gamma;\Pi;\varnothing\vdash\lambda x.\mathrm{init}\ x:
\mathrm{Element}\mathrel{\xrightarrow{\mathrm{Mut}}}\mathrm{ElemInst}
}{
\Gamma;\Pi;\Phi\vdash\mathrm{map}\ (\lambda x.\mathrm{init}\ x)\ V:
\mathrm{List}\ \mathrm{ElemInst}\ !\ \mathrm{Mut}
}
\quad\mathrm{TC\mathchar`-Map}
List Updating. We have u p d a t e s V ≜ m a p ( λ x . u p d a t e x ) V \mathrm{updates}\ V\mathrel{\triangleq}\mathrm{map}\ (\lambda x.\mathrm{update}\ x)\ V updates V ≜ map ( λ x . update x ) V . The derived typing rule is given as follows:
\frac{\Gamma;\Pi;\Phi\vdash V:\mathrm{List}\ \mathrm{ElemInst}}
{\Gamma;\Pi;\Phi\vdash\mathrm{updates}\ V:\mathrm{List}\ \mathrm{ElemInst}\ !\ \mathrm{Mut}}
\quad\mathrm{TC\mathchar`-Updates}
We derive this rule using the previously derived rule TC-Map as follows:
Γ , x : E l e m I n s t ; Π ; ∅ ⊢ x : E l e m I n s t T V - V a r \frac{\Gamma, x : \mathrm{ElemInst}; \Pi; \varnothing\vdash x : \mathrm{ElemInst}}{\mathrm{TV\text{-}Var}} TV - Var Γ , x : ElemInst ; Π ; ∅ ⊢ x : ElemInst
Γ , x : E l e m I n s t ; Π ; ∅ ⊢ update x : E l e m I n s t ! M u t T C - I n i t \frac{\Gamma, x : \mathrm{ElemInst}; \Pi; \varnothing\vdash\operatorname{update} x : \mathrm{ElemInst}\ !\ \mathrm{Mut}}{\mathrm{TC\text{-}Init}} TC - Init Γ , x : ElemInst ; Π ; ∅ ⊢ update x : ElemInst ! Mut
Γ ; Π ; ∅ ⊢ λ x . update x : E l e m I n s t → M u t E l e m I n s t T V - L a m Γ ; Π ; Φ ⊢ V : L i s t E l e m I n s t \frac{\Gamma; \Pi; \varnothing\vdash\lambda x.\operatorname{update} x : \mathrm{ElemInst}\xrightarrow{\mathrm{Mut}}\mathrm{ElemInst}}{\mathrm{TV\text{-}Lam}}
\qquad
\Gamma; \Pi; \Phi\vdash V : \mathrm{List}\ \mathrm{ElemInst} TV - Lam Γ ; Π ; ∅ ⊢ λ x . update x : ElemInst Mut ElemInst Γ ; Π ; Φ ⊢ V : List ElemInst
Γ ; Π ; ∅ ⊢ λ x . update x : E l e m I n s t → M u t E l e m I n s t Γ ; Π ; Φ ⊢ V : L i s t E l e m I n s t Γ ; Π ; Φ ⊢ map ( λ x . update x ) V : L i s t E l e m I n s t ! M u t T C - M a p \frac{\Gamma; \Pi; \varnothing\vdash\lambda x.\operatorname{update} x : \mathrm{ElemInst}\xrightarrow{\mathrm{Mut}}\mathrm{ElemInst}
\qquad
\Gamma; \Pi; \Phi\vdash V : \mathrm{List}\ \mathrm{ElemInst}}
{\Gamma; \Pi; \Phi\vdash\operatorname{map}\;(\lambda x.\operatorname{update} x)\;V : \mathrm{List}\ \mathrm{ElemInst}\ !\ \mathrm{Mut}}
\quad\mathrm{TC\text{-}Map} Γ ; Π ; Φ ⊢ map ( λ x . update x ) V : List ElemInst ! Mut Γ ; Π ; ∅ ⊢ λ x . update x : ElemInst Mut ElemInst Γ ; Π ; Φ ⊢ V : List ElemInst TC - Map
Iteration. We have iter V W ≜ fold ( λ x . λ ( ) . V x ) ( ) W \operatorname{iter}\ V\ W \triangleq\operatorname{fold}\;(\lambda x.\lambda().V\ x)\;()\;W iter V W ≜ fold ( λ x . λ ( ) . V x ) ( ) W , where λ ( ) . M \lambda().M λ ( ) . M is shorthand for a function which does not bind a variable in M M M . The derived typing rule is given as follows:
Γ ; Π ; Φ 1 ⊢ V : A → E 1 Γ ; Π ; Φ 2 ⊢ W : L i s t A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ iter V W : 1 ! E T C - I t e r \frac{\Gamma; \Pi; \Phi_1 \vdash V : A \xrightarrow{E} 1
\qquad
\Gamma; \Pi; \Phi_2 \vdash W : \mathrm{List}\ A}
{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\operatorname{iter}\ V\ W : 1\ !\ E}
\quad\mathrm{TC\text{-}Iter} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ iter V W : 1 ! E Γ ; Π ; Φ 1 ⊢ V : A E 1 Γ ; Π ; Φ 2 ⊢ W : List A TC - Iter
We derive this rule via intermediate derivations (1)-(3) as follows for E = P u r e E = \mathrm{Pure} E = Pure . A derivation for E = M u t E = \mathrm{Mut} E = Mut can be straightforwardly obtained by appropriately invoking TC-Sub throughout.
Γ , x : A ; Π ; Φ 1 ⊢ V : A → P u r e 1 Γ , x : A ; Π ; ∅ ⊢ x : A T V - V a r Γ , x : A ; Π ; Φ 1 ⊢ V x : 1 ! P u r e T C - L e t \frac{\Gamma, x : A; \Pi; \Phi_1 \vdash V : A \xrightarrow{\mathrm{Pure}} 1
\qquad
\frac{\Gamma, x : A; \Pi; \varnothing\vdash x : A}{\mathrm{TV\text{-}Var}}}
{\Gamma, x : A; \Pi; \Phi_1 \vdash V\ x : 1\ !\ \mathrm{Pure}}
\quad\mathrm{TC\text{-}Let} Γ , x : A ; Π ; Φ 1 ⊢ V x : 1 ! Pure Γ , x : A ; Π ; Φ 1 ⊢ V : A Pure 1 TV - Var Γ , x : A ; Π ; ∅ ⊢ x : A TC - Let
Γ , x : A ; Π ; Φ 1 ⊢ λ ( ) . V x : 1 → P u r e 1 T V - L a m \frac{\Gamma, x : A; \Pi; \Phi_1 \vdash\lambda().V\ x : 1 \xrightarrow{\mathrm{Pure}} 1}{\mathrm{TV\text{-}Lam}} TV - Lam Γ , x : A ; Π ; Φ 1 ⊢ λ ( ) . V x : 1 Pure 1
Γ , x : A ; Π ; Φ 1 ⊢ val λ ( ) . V x : 1 → P u r e 1 ! P u r e T C - V a l \frac{\Gamma, x : A; \Pi; \Phi_1 \vdash\operatorname{val}\ \lambda().V\ x : 1 \xrightarrow{\mathrm{Pure}} 1\ !\ \mathrm{Pure}}{\mathrm{TC\text{-}Val}} TC - Val Γ , x : A ; Π ; Φ 1 ⊢ val λ ( ) . V x : 1 Pure 1 ! Pure
( 1 ) Γ ; Π ; Φ 1 ⊢ λ x . val λ ( ) . V x : A → P u r e 1 → P u r e 1 T V - L a m (1)\quad
\Gamma; \Pi; \Phi_1 \vdash\lambda x.\operatorname{val}\ \lambda().V\ x :
A \xrightarrow{\mathrm{Pure}} 1 \xrightarrow{\mathrm{Pure}} 1
\quad\mathrm{TV\text{-}Lam} ( 1 ) Γ ; Π ; Φ 1 ⊢ λ x . val λ ( ) . V x : A Pure 1 Pure 1 TV - Lam
Γ ; Π ; ∅ ⊢ ( ) : 1 T V - U n i t Γ ; Π ; Φ 2 ⊢ W : L i s t A \frac{\Gamma; \Pi; \varnothing\vdash() : 1}{\mathrm{TV\text{-}Unit}}
\qquad
\Gamma; \Pi; \Phi_2 \vdash W : \mathrm{List}\ A TV - Unit Γ ; Π ; ∅ ⊢ ( ) : 1 Γ ; Π ; Φ 2 ⊢ W : List A
Γ ; Π ; ∅ ⊢ ( ) : 1 Γ ; Π ; Φ 2 ⊢ W : L i s t A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ fold ( λ x . ⋯ ) ( ) W : 1 ! P u r e T C - F o l d \frac{\Gamma; \Pi; \varnothing\vdash() : 1
\qquad
\Gamma; \Pi; \Phi_2 \vdash W : \mathrm{List}\ A}
{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\operatorname{fold}\;(\lambda x.\cdots)\;()\;W : 1\ !\ \mathrm{Pure}}
\quad\mathrm{TC\text{-}Fold} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ fold ( λ x . ⋯ ) ( ) W : 1 ! Pure Γ ; Π ; ∅ ⊢ ( ) : 1 Γ ; Π ; Φ 2 ⊢ W : List A TC - Fold
List Click-Search. We have clicks i d V ≜ iter ( λ x . click i d x ) V \operatorname{clicks}_{id}\ V \triangleq\operatorname{iter}\;(\lambda x.\operatorname{click}_{id}\ x)\;V clicks i d V ≜ iter ( λ x . click i d x ) V . The derived typing rule is given as follows:
Γ ; Π ; Φ ⊢ V : L i s t E l e m I n s t Γ ; Π ; Φ ⊢ clicks i d V : 1 ! M u t T C - C l i c k s \frac{\Gamma; \Pi; \Phi\vdash V : \mathrm{List}\ \mathrm{ElemInst}}
{\Gamma; \Pi; \Phi\vdash\operatorname{clicks}_{id}\ V : 1\ !\ \mathrm{Mut}}
\quad\mathrm{TC\text{-}Clicks} Γ ; Π ; Φ ⊢ clicks i d V : 1 ! Mut Γ ; Π ; Φ ⊢ V : List ElemInst TC - Clicks
We derive this rule using the previously derived rule TC-Iter as follows:
Γ , x : E l e m I n s t ; Π ; ∅ ⊢ x : E l e m I n s t T V - V a r \frac{\Gamma, x : \mathrm{ElemInst}; \Pi; \varnothing\vdash x : \mathrm{ElemInst}}{\mathrm{TV\text{-}Var}} TV - Var Γ , x : ElemInst ; Π ; ∅ ⊢ x : ElemInst
Γ , x : E l e m I n s t ; Π ; ∅ ⊢ click i d x : 1 ! M u t T C - I n i t \frac{\Gamma, x : \mathrm{ElemInst}; \Pi; \varnothing\vdash\operatorname{click}_{id}\ x : 1\ !\ \mathrm{Mut}}{\mathrm{TC\text{-}Init}} TC - Init Γ , x : ElemInst ; Π ; ∅ ⊢ click i d x : 1 ! Mut
Γ ; Π ; ∅ ⊢ λ x . click i d x : E l e m I n s t → M u t 1 T V - L a m \frac{\Gamma; \Pi; \varnothing\vdash\lambda x.\operatorname{click}_{id}\ x :
\mathrm{ElemInst}\xrightarrow{\mathrm{Mut}}1}{\mathrm{TV\text{-}Lam}} TV - Lam Γ ; Π ; ∅ ⊢ λ x . click i d x : ElemInst Mut 1
Γ ; Π ; ∅ ⊢ λ x . click i d x : E l e m I n s t → M u t 1 Γ ; Π ; Φ ⊢ V : L i s t E l e m I n s t Γ ; Π ; Φ ⊢ iter ( λ x . click i d x ) V : 1 ! M u t T C - I t e r \frac{\Gamma; \Pi; \varnothing\vdash\lambda x.\operatorname{click}_{id}\ x :
\mathrm{ElemInst}\xrightarrow{\mathrm{Mut}}1
\qquad
\Gamma; \Pi; \Phi\vdash V : \mathrm{List}\ \mathrm{ElemInst}}
{\Gamma; \Pi; \Phi\vdash\operatorname{iter}\;(\lambda x.\operatorname{click}_{id}\ x)\;V : 1\ !\ \mathrm{Mut}}
\quad\mathrm{TC\text{-}Iter} Γ ; Π ; Φ ⊢ iter ( λ x . click i d x ) V : 1 ! Mut Γ ; Π ; ∅ ⊢ λ x . click i d x : ElemInst Mut 1 Γ ; Π ; Φ ⊢ V : List ElemInst TC - Iter
List Click-Run. We have runClicks V ≜ iter ( λ x . runClick x ) V \operatorname{runClicks}\ V \triangleq\operatorname{iter}\;(\lambda x.\operatorname{runClick}\ x)\;V runClicks V ≜ iter ( λ x . runClick x ) V . The derived typing rule is given as follows:
\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash V : \mathrm{List}\ \mathrm{Attr}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash\operatorname{runClicks}\ V : 1\mathbin{!}\mathrm{Mut}}
\quad\textsc{TC-RunClicks}
We derive this rule using the previously derived rule \textsc{TC-Iter} as follows:
\frac{}{\Gamma, x : \mathrm{Attr} \mathbin{;} \Pi\mathbin{;} \varnothing\vdash x : \mathrm{Attr}}
\quad\textsc{TV-Var}
\frac{\Gamma, x : \mathrm{Attr} \mathbin{;} \Pi\mathbin{;} \varnothing\vdash x : \mathrm{Attr}}{\Gamma, x : \mathrm{Attr} \mathbin{;} \Pi\mathbin{;} \varnothing\vdash\operatorname{runClick}\ x : 1\mathbin{!}\mathrm{Mut}}
\quad\textsc{TC-Init}
\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \varnothing\vdash\lambda x.\operatorname{runClick}\ x : \mathrm{Attr}\mathrel{\overset{\mathrm{Mut}}{\longrightarrow}}1}{}
\quad\textsc{TV-Lam}
\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \varnothing\vdash\lambda x.\operatorname{runClick}\ x : \mathrm{Attr}\mathrel{\overset{\mathrm{Mut}}{\longrightarrow}}1
\qquad
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash V : \mathrm{List}\ \mathrm{Attr}}
{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash\operatorname{iter}\ (\lambda x.\operatorname{runClick}\ x)\ V : 1\mathbin{!}\mathrm{Mut}}
\quad\textsc{TC-Iter}
Weakening
We have standard weakening results on Γ \Gamma Γ and on Φ \Phi Φ (for Succ -phase pointers only). Our weakening result for Π \Pi Π is comparatively non-standard, since arbitrarily weakening on Π \Pi Π would be unsound: for example, extending Π [ p ] \Pi[p] Π [ p ] in rule \textsc{TC-EvalI} might violate the premise that Π [ p ] ∩ L = ∅ \Pi[p] \cap\mathcal{L} = \varnothing Π [ p ] ∩ L = ∅ . To sidestep this issue, we only permit weakening Π \Pi Π at pointers which are initial-phase and unrelated to the term , both of which can be determined by Φ \Phi Φ .
When weakening typing judgments involving some Φ \Phi Φ , if we have Π ⊑ Φ ′ Π ′ \Pi\sqsubseteq_{\Phi'} \Pi' Π ⊑ Φ ′ Π ′ , we require that Φ ⋈ Φ ′ \Phi\bowtie\Phi' Φ ⋈ Φ ′ is defined, implying that Φ \Phi Φ and Φ ′ \Phi' Φ ′ are sufficiently disjoint : in particular, we get that, if p ∈ dom ( Φ ) p \in\operatorname{dom}(\Phi) p ∈ dom ( Φ ) , then Π [ p ] = Π ′ [ p ] \Pi[p] = \Pi'[p] Π [ p ] = Π ′ [ p ] .
Lemma A.1 (Π-weakening, values). If
Γ ; Π ; Φ ⊢ V : A \Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash V : A Γ ; Π ; Φ ⊢ V : A ,
Π ⊑ Φ ′ Π ′ \Pi\sqsubseteq_{\Phi'} \Pi' Π ⊑ Φ ′ Π ′ , and
Φ ⋈ Φ ′ \Phi\bowtie\Phi' Φ ⋈ Φ ′ is defined,
then Γ ; Π ′ ; Φ ⊢ V : A \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi\vdash V : A Γ ; Π ′ ; Φ ⊢ V : A .
Proof. By mutual induction on the derivation of the typing judgment (i) alongside Lemmas A.2 and A.3.
Case TV-Var: We have
\frac{x : A \in\Gamma\qquad\operatorname{Succ}(\Phi)}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash x : A}
\quad\textsc{TV-Var}
\frac{x : A \in\Gamma\qquad\operatorname{Succ}(\Phi)}{\Gamma\mathbin{;} \Pi' \mathbin{;} \Phi\vdash x : A}
\quad\textsc{TV-Var}
Cases TV-Unit, TV-Str, TV-True, TV-False, and TV-Nil are similarly immediately rederivable.
Case TV-Pair: We have
\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash V : A
\qquad
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash W : B}
{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \bowtie\Phi_2 \vdash(V,W) : A \times B}
\quad\textsc{TV-Pair}
By inductive hypothesis on (1), (3), and premise ( i i ) (ii) ( ii ) , we get (5) that Γ ; Π ′ ; Φ 1 ⊢ V : A \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_1 \vdash V : A Γ ; Π ′ ; Φ 1 ⊢ V : A .
Likewise, by inductive hypothesis on (2), (4), and premise ( i i ) (ii) ( ii ) , we get (6) that Γ ; Π ′ ; Φ 2 ⊢ W : B \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_2 \vdash W : B Γ ; Π ′ ; Φ 2 ⊢ W : B .
We derive the conclusion as follows:
Γ ; Π ′ ; Φ 1 ⊢ V : A Γ ; Π ′ ; Φ 2 ⊢ W : B Γ ; Π ′ ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B T V - P a i r \frac{\Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_1 \vdash V : A \qquad\Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_2 \vdash W : B}{\Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_1 \bowtie\Phi_2 \vdash(V,W) : A \times B}\ \mathrm{TV\text{-}Pair} Γ ; Π ′ ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B Γ ; Π ′ ; Φ 1 ⊢ V : A Γ ; Π ′ ; Φ 2 ⊢ W : B TV - Pair
Cases TV-Cons, TV-Attr, TV-OnClick, TV-Text, TV-Tag, TV-TextI, and TV-TagI can be shown analogously by inductive hypothesis.
Case TV-Lam: We have
Γ , x : A ; Π ; Φ ⊢ M : B ! E Succ ( Φ ) Γ ; Π ; Φ ⊢ λ x . M : A → B T V - L a m \frac{\Gamma, x : A \mathbin{;} \Pi\mathbin{;} \Phi\vdash M : B\,!\,E \qquad\operatorname{Succ}(\Phi)}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash\lambda x.M : A \mathbin{\to} B}\ \mathrm{TV\text{-}Lam} Γ ; Π ; Φ ⊢ λ x . M : A → B Γ , x : A ; Π ; Φ ⊢ M : B ! E Succ ( Φ ) TV - Lam
By mutual inductive hypothesis (Lemma A.2 ) on (1) and premises ( i i ) (ii) ( ii ) and ( i i i ) (iii) ( iii ) , we get (3) that Γ , x : A ; Π ′ ; Φ ⊢ M : B ! E \Gamma, x : A \mathbin{;} \Pi' \mathbin{;} \Phi\vdash M : B\,!\,E Γ , x : A ; Π ′ ; Φ ⊢ M : B ! E .
We derive the conclusion as follows:
Γ , x : A ; Π ′ ; Φ ⊢ e : B ! E Succ ( Φ ) Γ ; Π ′ ; Φ ⊢ λ x . M : A → E B T V - L a m \frac{\Gamma, x : A \mathbin{;} \Pi' \mathbin{;} \Phi\vdash e : B\,!\,E \qquad\operatorname{Succ}(\Phi)}{\Gamma\mathbin{;} \Pi' \mathbin{;} \Phi\vdash\lambda x.M : A \mathbin{\xrightarrow{E}} B}\ \mathrm{TV\text{-}Lam} Γ ; Π ′ ; Φ ⊢ λ x . M : A E B Γ , x : A ; Π ′ ; Φ ⊢ e : B ! E Succ ( Φ ) TV - Lam
Case TV-Comp: We have
Γ ; Π ; Φ ⊢ D : L Γ ; Π ; Φ ⊢ component { D } : E l e m e n t T V - C o m p \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash D : \mathcal{L}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash\operatorname{component}\{D\} : \mathrm{Element}}\ \mathrm{TV\text{-}Comp} Γ ; Π ; Φ ⊢ component { D } : Element Γ ; Π ; Φ ⊢ D : L TV - Comp
By mutual inductive hypothesis (Lemma A.3 ) on (1) and premise ( i i ) (ii) ( ii ) , we get (2) that Γ ; Π ′ ; Φ ⊢ D : L \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi\vdash D : \mathcal{L} Γ ; Π ′ ; Φ ⊢ D : L .
We derive the conclusion as follows:
Γ ; Π ′ ; Φ ⊢ D : L Γ ; Π ′ ; Φ ⊢ component { D } : E l e m e n t T V - C o m p \frac{\Gamma\mathbin{;} \Pi' \mathbin{;} \Phi\vdash D : \mathcal{L}}{\Gamma\mathbin{;} \Pi' \mathbin{;} \Phi\vdash\operatorname{component}\{D\} : \mathrm{Element}}\ \mathrm{TV\text{-}Comp} Γ ; Π ′ ; Φ ⊢ component { D } : Element Γ ; Π ′ ; Φ ⊢ D : L TV - Comp
Case TV-CompI: We have
Γ ; Π ; Φ ⊢ D : Π [ p ] Φ [ p ] = Succ Γ ; Π ; Φ ⊢ V : E l e m I n s t Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ compInst p ( ⌈ D ⌉ , V ) : E l e m I n s t T V - C o m p I \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash D : \Pi[p] \qquad\Phi[p] = \operatorname{Succ} \qquad\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash V : \mathrm{ElemInst}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \bowtie\Phi_2 \vdash\operatorname{compInst}_p(\lceil D\rceil,V) : \mathrm{ElemInst}}\ \mathrm{TV\text{-}CompI} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ compInst p (⌈ D ⌉ , V ) : ElemInst Γ ; Π ; Φ ⊢ D : Π [ p ] Φ [ p ] = Succ Γ ; Π ; Φ ⊢ V : ElemInst TV - CompI
By (2) and premise ( i i i ) (iii) ( iii ) , either Φ ′ [ p ] = Succ \Phi'[p] = \operatorname{Succ} Φ ′ [ p ] = Succ or p ∉ dom ( Φ ′ ) p \notin\operatorname{dom}(\Phi') p ∈ / dom ( Φ ′ ) . In either case, premise ( i i ) (ii) ( ii ) then gives us (4) that Π ′ [ p ] = Π [ p ] \Pi'[p] = \Pi[p] Π ′ [ p ] = Π [ p ] .
By mutual inductive hypothesis (Lemma A.3 ) on (1) and premise ( i i ) (ii) ( ii ) , we get that Γ ; Π ′ ⊢ D : Π [ p ] \Gamma\mathbin{;} \Pi' \vdash D : \Pi[p] Γ ; Π ′ ⊢ D : Π [ p ] . By (4), we equivalently have (5) that Γ ; Π ′ ⊢ D : Π ′ [ p ] \Gamma\mathbin{;} \Pi' \vdash D : \Pi'[p] Γ ; Π ′ ⊢ D : Π ′ [ p ] .
By inductive hypothesis on (3) and premises ( i i ) (ii) ( ii ) and ( i i i ) (iii) ( iii ) , we get (6) that Γ ; Π ′ ; Φ ⊢ V : E l e m I n s t \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi\vdash V : \mathrm{ElemInst} Γ ; Π ′ ; Φ ⊢ V : ElemInst .
• We derive the conclusion as follows:
Γ ; Π ′ ⊢ D : Π ′ [ p ] ( 5 ) Φ [ p ] = Succ ( 2 ) Γ ; Π ′ ; Φ + V : ElemInst ( 6 ) Γ ; Π ′ ; Φ ⊢ compInst p ( ⌈ D ⌉ , V ) : ElemInst T V - C o m p I \frac{\Gamma;\Pi' \vdash D:\Pi'[p]\ (5)\qquad\Phi[p]=\operatorname{Succ}\ (2)\qquad\Gamma;\Pi';\Phi+V:\operatorname{ElemInst}\ (6)}
{\Gamma;\Pi';\Phi\vdash\operatorname{compInst}_{p}(\lceil D\rceil,V):\operatorname{ElemInst}}\ \mathrm{TV\text{-}CompI} Γ ; Π ′ ; Φ ⊢ compInst p (⌈ D ⌉ , V ) : ElemInst Γ ; Π ′ ⊢ D : Π ′ [ p ] ( 5 ) Φ [ p ] = Succ ( 2 ) Γ ; Π ′ ; Φ + V : ElemInst ( 6 ) TV - CompI
Case TV-Setter: We have
ℓ : A ∈ Π ′ [ p ] ( 1 ) Succ ( Φ ) ( 2 ) Γ ; Π ′ ; Φ ⊢ set p ℓ : A → M u t 1 T V - S e t t e r \frac{\ell:A\in\Pi'[p]\ (1)\qquad\operatorname{Succ}(\Phi)\ (2)}
{\Gamma;\Pi';\Phi\vdash\operatorname{set}^{\ell}_{p}:A\mathrel{\xrightarrow{\mathrm{Mut}}}1}\ \mathrm{TV\text{-}Setter} Γ ; Π ′ ; Φ ⊢ set p ℓ : A Mut 1 ℓ : A ∈ Π ′ [ p ] ( 1 ) Succ ( Φ ) ( 2 ) TV - Setter
• By (1) and premise (ii), we get (3) that ℓ : A ∈ Π ′ [ p ] \ell:A\in\Pi'[p] ℓ : A ∈ Π ′ [ p ] (regardless of whether p ∈ dom ( Φ ′ ) p\in\operatorname{dom}(\Phi') p ∈ dom ( Φ ′ ) ). • We derive the conclusion as follows:
ℓ : A ∈ Π ′ [ p ] ( 3 ) Succ ( Φ ) ( 2 ) Γ ; Π ′ ; Φ ⊢ set p ℓ : A → M u t 1 T V - S e t t e r \frac{\ell:A\in\Pi'[p]\ (3)\qquad\operatorname{Succ}(\Phi)\ (2)}
{\Gamma;\Pi';\Phi\vdash\operatorname{set}^{\ell}_{p}:A\mathrel{\xrightarrow{\mathrm{Mut}}}1}\ \mathrm{TV\text{-}Setter} Γ ; Π ′ ; Φ ⊢ set p ℓ : A Mut 1 ℓ : A ∈ Π ′ [ p ] ( 3 ) Succ ( Φ ) ( 2 ) TV - Setter
□ \square □
Lemma A.2 (Π-weakening, computations). If
(i) Γ ; Π ; Φ ⊢ M : A ! E \Gamma;\Pi;\Phi\vdash M:A!E Γ ; Π ; Φ ⊢ M : A ! E ,
(ii) Π ⊑ Φ ′ Π ′ \Pi\sqsubseteq_{\Phi'}\Pi' Π ⊑ Φ ′ Π ′ , and
(iii) Φ ⋈ Φ ′ \Phi\bowtie\Phi' Φ ⋈ Φ ′ is defined,
then Γ ; Π ′ ; Φ ⊢ M : A ! E \Gamma;\Pi';\Phi\vdash M:A!E Γ ; Π ′ ; Φ ⊢ M : A ! E .
Proof. By mutual induction on the derivation of the typing judgment (i) alongside Lemmas A.1 and A.3.
Case TC-Val: We have
Γ ; Π ; Φ ⊢ V : A ( 1 ) Γ ; Π ; Φ ⊢ val V : A ! Pure T C - V a l \frac{\Gamma;\Pi;\Phi\vdash V:A\ (1)}
{\Gamma;\Pi;\Phi\vdash\operatorname{val}\ V:A!\operatorname{Pure}}\ \mathrm{TC\text{-}Val} Γ ; Π ; Φ ⊢ val V : A ! Pure Γ ; Π ; Φ ⊢ V : A ( 1 ) TC - Val • By mutual inductive hypothesis (Lemma A.1) on (1) and premises (ii) and (iii), we get (2) that Γ ; Π ′ ; Φ ⊢ V : A \Gamma;\Pi';\Phi\vdash V:A Γ ; Π ′ ; Φ ⊢ V : A . • We derive the conclusion as follows:
Γ ; Π ′ ; Φ ⊢ V : A ( 3 ) Γ ; Π ′ ; Φ ⊢ val V : A ! Pure T C - V a l \frac{\Gamma;\Pi';\Phi\vdash V:A\ (3)}
{\Gamma;\Pi';\Phi\vdash\operatorname{val}\ V:A!\operatorname{Pure}}\ \mathrm{TC\text{-}Val} Γ ; Π ′ ; Φ ⊢ val V : A ! Pure Γ ; Π ′ ; Φ ⊢ V : A ( 3 ) TC - Val Cases TC-App, TC-If, TC-Fst, TC-Snd, TC-Fold, TC-Init, TC-Click, TC-RunClick, and TC-Update can be shown analogously by mutual inductive hypothesis.
Case TC-Let: We have
Γ ; Π ; Φ 1 ⊢ M : A ! E ( 1 ) Γ , x : A 1 ; Π ; Φ 2 ⊢ N : B ! E ( 2 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in N : B ! E T C - L e t \frac{\Gamma;\Pi;\Phi_1\vdash M:A!E\ (1)\qquad\Gamma,x:A_1;\Pi;\Phi_2\vdash N:B!E\ (2)}
{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash\operatorname{let}\ x=M\ \operatorname{in}\ N:B!E}\ \mathrm{TC\text{-}Let} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in N : B ! E Γ ; Π ; Φ 1 ⊢ M : A ! E ( 1 ) Γ , x : A 1 ; Π ; Φ 2 ⊢ N : B ! E ( 2 ) TC - Let • From premise (iii) and definition of ⋈ \bowtie ⋈ , it follows that (3) Φ 1 ⋈ Φ ′ \Phi_1\bowtie\Phi' Φ 1 ⋈ Φ ′ is defined and (4) Φ 2 ⋈ Φ ′ \Phi_2\bowtie\Phi' Φ 2 ⋈ Φ ′ is defined. • By inductive hypothesis on (1), (3), and premise (ii), we get (5) that Γ ; Π ′ ; Φ 1 ⊢ M : A ! E \Gamma;\Pi';\Phi_1\vdash M:A!E Γ ; Π ′ ; Φ 1 ⊢ M : A ! E .
Likewise, by inductive hypothesis on (2), (4), and premise ( i i ) (ii) ( ii ) , we get (6) that Γ , x : A ; Π ′ ; Φ 2 ⊢ N : B ! E \Gamma, x : A; \Pi'; \Phi_2 \vdash N : B ! E Γ , x : A ; Π ′ ; Φ 2 ⊢ N : B ! E .
Γ ; Π ′ ; Φ 1 ⊢ M : A ! E Γ , x : A ; Π ′ ; Φ 2 ⊢ N : B ! E Γ ; Π ′ ; Φ 1 ⊕ Φ 2 ⊢ l e t x = M i n N : B ! E TC-Let \frac{\Gamma; \Pi'; \Phi_1 \vdash M : A ! E \qquad\Gamma, x : A; \Pi'; \Phi_2 \vdash N : B ! E}{\Gamma; \Pi'; \Phi_1 \oplus\Phi_2 \vdash\mathop{\mathrm{let}}\ x = M\ \mathop{\mathrm{in}}\ N : B ! E}
\quad\text{TC-Let} Γ ; Π ′ ; Φ 1 ⊕ Φ 2 ⊢ let x = M in N : B ! E Γ ; Π ′ ; Φ 1 ⊢ M : A ! E Γ , x : A ; Π ′ ; Φ 2 ⊢ N : B ! E TC-Let
Case TC-Sub: We have
Γ ; Π ; Φ ⊢ M : A ! P u r e Γ ; Π ; Φ ⊢ M : A ! M u t TC-Sub \frac{\Gamma; \Pi; \Phi\vdash M : A ! \mathrm{Pure}}{\Gamma; \Pi; \Phi\vdash M : A ! \mathrm{Mut}}
\quad\text{TC-Sub} Γ ; Π ; Φ ⊢ M : A ! Mut Γ ; Π ; Φ ⊢ M : A ! Pure TC-Sub
Γ ; Π ′ ; Φ ⊢ M : A ! P u r e Γ ; Π ′ ; Φ ⊢ M : A ! M u t TC-Sub \frac{\Gamma; \Pi'; \Phi\vdash M : A ! \mathrm{Pure}}{\Gamma; \Pi'; \Phi\vdash M : A ! \mathrm{Mut}}
\quad\text{TC-Sub} Γ ; Π ′ ; Φ ⊢ M : A ! Mut Γ ; Π ′ ; Φ ⊢ M : A ! Pure TC-Sub
Case TC-EvalI: We have
Γ ; Π ⊢ D 0 : L ⊎ Π [ p ] Γ ; Π ⊢ D : L S u c c ( Φ ) Γ ; Π ; Φ , p : I n i t ⊢ ⌈ D 0 ⌉ p I n i t D : E l e m I n s t ! M u t TC-EvalI \frac{\Gamma; \Pi\vdash D_0 : \mathcal{L} \uplus\Pi[p] \qquad\Gamma; \Pi\vdash D : \mathcal{L} \qquad\mathrm{Succ}(\Phi)}{\Gamma; \Pi; \Phi, p : \mathrm{Init} \vdash\lceil D_0 \rceil^{\mathrm{Init}}_p D : \mathrm{ElemInst} ! \mathrm{Mut}}
\quad\text{TC-EvalI} Γ ; Π ; Φ , p : Init ⊢ ⌈ D 0 ⌉ p Init D : ElemInst ! Mut Γ ; Π ⊢ D 0 : L ⊎ Π [ p ] Γ ; Π ⊢ D : L Succ ( Φ ) TC-EvalI
By mutual inductive hypothesis (Lemma A.3) on (1) and premise ( i i ) (ii) ( ii ) , we get that Γ ; Π ′ ⊢ D 0 : L ⊎ Π [ p ] \Gamma; \Pi' \vdash D_0 : \mathcal{L} \uplus\Pi[p] Γ ; Π ′ ⊢ D 0 : L ⊎ Π [ p ] . By (4), this is equivalent to (5) that Γ ; Π ′ ⊢ D 0 : L ⊎ Π ′ [ p ] \Gamma; \Pi' \vdash D_0 : \mathcal{L} \uplus\Pi'[p] Γ ; Π ′ ⊢ D 0 : L ⊎ Π ′ [ p ] .
Γ ; Π ′ ⊢ D 0 : L ⊎ Π ′ [ p ] Γ ; Π ′ ⊢ D : L S u c c ( Φ ) Γ ; Π ′ ; Φ , p : I n i t ⊢ ⌈ D 0 ⌉ p ϕ D : E l e m I n s t ! M u t TC-EvalI \frac{\Gamma; \Pi' \vdash D_0 : \mathcal{L} \uplus\Pi'[p] \qquad\Gamma; \Pi' \vdash D : \mathcal{L} \qquad\mathrm{Succ}(\Phi)}{\Gamma; \Pi'; \Phi, p : \mathrm{Init} \vdash\lceil D_0 \rceil^{\phi}_p D : \mathrm{ElemInst} ! \mathrm{Mut}}
\quad\text{TC-EvalI} Γ ; Π ′ ; Φ , p : Init ⊢ ⌈ D 0 ⌉ p ϕ D : ElemInst ! Mut Γ ; Π ′ ⊢ D 0 : L ⊎ Π ′ [ p ] Γ ; Π ′ ⊢ D : L Succ ( Φ ) TC-EvalI
Case TC-EvalS: We have
Γ ; Π ⊢ D 0 : Π [ p ] Γ ; Π ⊢ D : L L ⊆ Π [ p ] S u c c ( Φ ) Γ ; Π ; Φ , p : S u c c ⊢ ⌈ D 0 ⌉ p S u c c D : E l e m I n s t ! M u t TC-EvalS \frac{\Gamma; \Pi\vdash D_0 : \Pi[p] \qquad\Gamma; \Pi\vdash D : \mathcal{L} \qquad\mathcal{L} \subseteq\Pi[p] \qquad\mathrm{Succ}(\Phi)}{\Gamma; \Pi; \Phi, p : \mathrm{Succ} \vdash\lceil D_0 \rceil^{\mathrm{Succ}}_p D : \mathrm{ElemInst} ! \mathrm{Mut}}
\quad\text{TC-EvalS} Γ ; Π ; Φ , p : Succ ⊢ ⌈ D 0 ⌉ p Succ D : ElemInst ! Mut Γ ; Π ⊢ D 0 : Π [ p ] Γ ; Π ⊢ D : L L ⊆ Π [ p ] Succ ( Φ ) TC-EvalS
Since we start with Φ , p : S u c c \Phi, p : \mathrm{Succ} Φ , p : Succ , by premise ( i i i ) (iii) ( iii ) , either Φ ′ [ p ] = S u c c \Phi'[p] = \mathrm{Succ} Φ ′ [ p ] = Succ or p ∉ dom ( Φ ′ ) p \notin\operatorname{dom}(\Phi') p ∈ / dom ( Φ ′ ) . In either case, premise ( i i ) (ii) ( ii ) then gives us (5) that Π ′ [ p ] = Π [ p ] \Pi'[p] = \Pi[p] Π ′ [ p ] = Π [ p ] .
By mutual inductive hypothesis (Lemma A.3) on (1) and premise ( i i ) (ii) ( ii ) , we get that Γ ; Π ′ ⊢ D 0 : Π [ p ] \Gamma; \Pi' \vdash D_0 : \Pi[p] Γ ; Π ′ ⊢ D 0 : Π [ p ] . By (5), this is equivalent to (6) that Γ ; Π ′ ⊢ D 0 : Π ′ [ p ] \Gamma; \Pi' \vdash D_0 : \Pi'[p] Γ ; Π ′ ⊢ D 0 : Π ′ [ p ] .
Γ ; Π ′ ⊢ D 0 : Π ′ [ p ] Γ ; Π ′ ⊢ D : L L ⊆ Π ′ [ p ] Succ ( Φ ) Γ ; Π ′ ; Φ , p : Succ ⊢ ⌈ D 0 ⌉ ↓ p Succ D : ElemInst ! Mut TC-EvalS \frac{\Gamma;\Pi' \vdash D_0 : \Pi'[p]\quad\Gamma;\Pi' \vdash D : \mathcal{L}\quad\mathcal{L}\subseteq\Pi'[p]\quad\operatorname{Succ}(\Phi)}
{\Gamma;\Pi';\Phi,p:\operatorname{Succ}\vdash\lceil D_0\rceil^{\operatorname{Succ}}_{\downarrow p}D:\operatorname{ElemInst}\ !\ \operatorname{Mut}}
\quad\operatorname{TC-EvalS} Γ ; Π ′ ; Φ , p : Succ ⊢ ⌈ D 0 ⌉ ↓ p Succ D : ElemInst ! Mut Γ ; Π ′ ⊢ D 0 : Π ′ [ p ] Γ ; Π ′ ⊢ D : L L ⊆ Π ′ [ p ] Succ ( Φ ) TC-EvalS
Lemma A.3 (Π-weakening, bodies). If
Γ ; Π ; Φ ⊢ D : L \Gamma;\Pi;\Phi\vdash D:\mathcal{L} Γ ; Π ; Φ ⊢ D : L ,
Π ⊑ Φ ′ Π ′ \Pi\sqsubseteq_{\Phi'}\Pi' Π ⊑ Φ ′ Π ′ , and
Φ ⋈ Φ ′ \Phi\bowtie\Phi' Φ ⋈ Φ ′ is defined,
then Γ ; Π ′ ; Φ ⊢ D : L \Gamma;\Pi';\Phi\vdash D:\mathcal{L} Γ ; Π ′ ; Φ ⊢ D : L .
Proof. By mutual induction on the derivation of the typing judgment (i) alongside Lemmas A.1 and A.2.
Case TB-Val: We have
Γ ; Π ; Φ ⊢ V : Element Γ ; Π ; Φ ⊢ val V : ∅ TB-Val \frac{\Gamma;\Pi;\Phi\vdash V:\operatorname{Element}}
{\Gamma;\Pi;\Phi\vdash\operatorname{val}\ V:\varnothing}
\quad\operatorname{TB-Val} Γ ; Π ; Φ ⊢ val V : ∅ Γ ; Π ; Φ ⊢ V : Element TB-Val
By mutual inductive hypothesis (Lemma A.1) on (1) and premises (ii) and (iii), we get (2) that Γ ; Π ′ ; Φ ⊢ V : Element \Gamma;\Pi';\Phi\vdash V:\operatorname{Element} Γ ; Π ′ ; Φ ⊢ V : Element .
We derive the conclusion as follows:
Γ ; Π ′ ; Φ ⊢ V : Element Γ ; Π ′ ; Φ ⊢ val V : ∅ TB-Val \frac{\Gamma;\Pi';\Phi\vdash V:\operatorname{Element}}
{\Gamma;\Pi';\Phi\vdash\operatorname{val}\ V:\varnothing}
\quad\operatorname{TB-Val} Γ ; Π ′ ; Φ ⊢ val V : ∅ Γ ; Π ′ ; Φ ⊢ V : Element TB-Val
Case TB-Let: We have
Γ ; Π ; Φ 1 ⊢ M : A ! Pure Γ , x : A ; Π ; Φ 2 ⊢ D : L Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in D : L TB-Let \frac{\Gamma;\Pi;\Phi_1\vdash M:A\ !\ \operatorname{Pure}\qquad\Gamma,x:A;\Pi;\Phi_2\vdash D:\mathcal{L}}
{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash\operatorname{let}\ x=M\ \operatorname{in}\ D:\mathcal{L}}
\quad\operatorname{TB-Let} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in D : L Γ ; Π ; Φ 1 ⊢ M : A ! Pure Γ , x : A ; Π ; Φ 2 ⊢ D : L TB-Let
From premise (iii) and definition of ⋈ \bowtie ⋈ , it follows that (3) Φ 1 ⋈ Φ ′ \Phi_1\bowtie\Phi' Φ 1 ⋈ Φ ′ is defined and (4) that Φ 2 ⋈ Φ ′ \Phi_2\bowtie\Phi' Φ 2 ⋈ Φ ′ is defined.
By mutual inductive hypothesis on (1), (3), and premise (ii), we get (5) that Γ ; Π ′ ; Φ 1 ⊢ M : A ! Pure \Gamma;\Pi';\Phi_1\vdash M:A\ !\ \operatorname{Pure} Γ ; Π ′ ; Φ 1 ⊢ M : A ! Pure .
By inductive hypothesis on (2), (4), and premise (ii), we get (6) that Γ , x : A ; Π ′ ; Φ 2 ⊢ D : L \Gamma,x:A;\Pi';\Phi_2\vdash D:\mathcal{L} Γ , x : A ; Π ′ ; Φ 2 ⊢ D : L .
We derive the conclusion as follows:
Γ ; Π ′ ; Φ 1 ⊢ M : A ! Pure Γ , x : A ; Π ′ ; Φ 2 ⊢ D : L Γ ; Π ′ ; Φ 1 ⋈ Φ 2 ⊢ let x = M in D : L TB-Let \frac{\Gamma;\Pi';\Phi_1\vdash M:A\ !\ \operatorname{Pure}\qquad\Gamma,x:A;\Pi';\Phi_2\vdash D:\mathcal{L}}
{\Gamma;\Pi';\Phi_1\bowtie\Phi_2\vdash\operatorname{let}\ x=M\ \operatorname{in}\ D:\mathcal{L}}
\quad\operatorname{TB-Let} Γ ; Π ′ ; Φ 1 ⋈ Φ 2 ⊢ let x = M in D : L Γ ; Π ′ ; Φ 1 ⊢ M : A ! Pure Γ , x : A ; Π ′ ; Φ 2 ⊢ D : L TB-Let
Case TB-State: We have
Γ ; Π ; Φ 1 ⊢ V : A Γ , x : A , x s e t : A → Mut 1 ; Π ; Φ 2 ⊢ D : L ℓ ∉ dom ( L ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x s e t = useState ℓ V in D : L , ℓ : A TB-State \frac{\Gamma;\Pi;\Phi_1\vdash V:A\qquad\Gamma,x:A,x_{\mathrm{set}}:A\xrightarrow{\operatorname{Mut}}1;\Pi;\Phi_2\vdash D:\mathcal{L}\qquad\ell\notin\operatorname{dom}(\mathcal{L})}
{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash\operatorname{let}\ x,x_{\mathrm{set}}=\operatorname{useState}^{\ell}\ V\ \operatorname{in}\ D:\mathcal{L},\ell:A}
\quad\operatorname{TB-State} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x set = useState ℓ V in D : L , ℓ : A Γ ; Π ; Φ 1 ⊢ V : A Γ , x : A , x set : A Mut 1 ; Π ; Φ 2 ⊢ D : L ℓ ∈ / dom ( L ) TB-State
By mutual inductive hypothesis (Lemma A.1) on (1), (4), and premise (ii), we get (6) that Γ ; Π ′ ; ∅ ⊢ V : A \Gamma; \Pi' ; \varnothing\vdash V : A Γ ; Π ′ ; ∅ ⊢ V : A .
By inductive hypothesis on (2), (5), and premise (ii), we get (7) that Γ , x : A , x s e t : A → M u t 1 ; Π ′ ⊢ D : L \Gamma, x : A, x_{\mathrm{set}} : A \xrightarrow{\mathrm{Mut}} 1 ; \Pi' \vdash D : \mathcal{L} Γ , x : A , x set : A Mut 1 ; Π ′ ⊢ D : L .
Γ ; Π ′ ; Φ 1 ⊢ V : A (6) Γ , x : A , x s e t : A → M u t 1 ; Π ′ ; Φ 2 ⊢ D : L (7) ℓ ∉ dom ( L ) (3) Γ ; Π ′ ; Φ 1 ⋈ Φ 2 ⊢ let x , x s e t = useState ℓ V in D : L , ℓ : A TB-Let \begin{aligned}
&\Gamma; \Pi' ; \Phi_1 \vdash V : A && \text{(6)}\\
&\Gamma, x : A, x_{\mathrm{set}} : A \xrightarrow{\mathrm{Mut}} 1 ; \Pi' ; \Phi_2 \vdash D : \mathcal{L} && \text{(7)}\\
&\ell\notin\operatorname{dom}(\mathcal{L}) && \text{(3)}\\
&\Gamma; \Pi' ; \Phi_1 \bowtie\Phi_2 \vdash\operatorname{let} x, x_{\mathrm{set}} = \operatorname{useState}^{\ell} V \operatorname{in} D : \mathcal{L}, \ell: A && \text{TB-Let}
\end{aligned} Γ ; Π ′ ; Φ 1 ⊢ V : A Γ , x : A , x set : A Mut 1 ; Π ′ ; Φ 2 ⊢ D : L ℓ ∈ / dom ( L ) Γ ; Π ′ ; Φ 1 ⋈ Φ 2 ⊢ let x , x set = useState ℓ V in D : L , ℓ : A (6) (7) (3) TB-Let
We have some further lemmas regarding Φ \Phi Φ :
Lemma A.4. If Γ ; Π ; Φ ⊢ V : A \Gamma; \Pi; \Phi\vdash V : A Γ ; Π ; Φ ⊢ V : A , then Succ ( Φ ) \operatorname{Succ}(\Phi) Succ ( Φ ) .
Proof. By induction on the derivation of the typing judgment. If the value in question has no subvalues, then we always have Succ ( Φ ) \operatorname{Succ}(\Phi) Succ ( Φ ) explicitly. Otherwise, the conclusion follows by inductive hypothesis.
Lemma A.5. If Γ ; Π ; Φ ⊢ M : A ! Pure \Gamma; \Pi; \Phi\vdash M : A ! \operatorname{Pure} Γ ; Π ; Φ ⊢ M : A ! Pure , then Succ ( Φ ) \operatorname{Succ}(\Phi) Succ ( Φ ) .
Proof. By induction on the derivation of the typing judgment. We appeal to some combination of the inductive hypothesis and Lemma A.4.
In particular, since our premise requires a Pure effect, rule TC-EvalI, which introduces a Init-phase pointer, can never occur since it also introduces a Mut effect.
Lemma A.6. If Γ ; Π ; Φ ⊢ D : L \Gamma; \Pi; \Phi\vdash D : \mathcal{L} Γ ; Π ; Φ ⊢ D : L , then Succ ( Φ ) \operatorname{Succ}(\Phi) Succ ( Φ ) .
Proof. By induction on the derivation of the typing judgment. In case TB-Let, we have explicitly that the subcomputation has Succ ( Φ ) \operatorname{Succ}(\Phi) Succ ( Φ ) . In the other cases, we appeal to Lemma A.4.
Lemma A.7. If Γ ; Π ; Φ ⊢ V : A \Gamma; \Pi; \Phi\vdash V : A Γ ; Π ; Φ ⊢ V : A or Γ ; Π ; Φ ⊢ D : L \Gamma; \Pi; \Phi\vdash D : \mathcal{L} Γ ; Π ; Φ ⊢ D : L or Γ ; Π ; Φ ⊢ M : A ! Pure \Gamma; \Pi; \Phi\vdash M : A ! \operatorname{Pure} Γ ; Π ; Φ ⊢ M : A ! Pure , then Succ ( Φ ) \operatorname{Succ}(\Phi) Succ ( Φ ) .
Proof. Corollary of Lemmas A.4, A.5, and A.6.
Lemma A.8. If Γ ; Π ; Φ ⊨ H \Gamma; \Pi; \Phi\models\mathcal{H} Γ ; Π ; Φ ⊨ H , then Succ ( Φ ) \operatorname{Succ}(\Phi) Succ ( Φ ) .
Proof. By definition, there exist some Φ i \Phi_i Φ i such that Φ = ⋈ i = 1 n Φ i \Phi= \bowtie_{i=1}^{n} \Phi_i Φ = ⋈ i = 1 n Φ i and Γ ; Π ; Φ i ⊢ H [ p ] . st [ ℓ ] : Π [ p ] [ ℓ ] \Gamma; \Pi; \Phi_i \vdash\mathcal{H}[p].\operatorname{st}[\ell] : \Pi[p][\ell] Γ ; Π ; Φ i ⊢ H [ p ] . st [ ℓ ] : Π [ p ] [ ℓ ] for all n n n elements in H \mathcal{H} H , each identified by a ( p , ℓ ) (p,\ell) ( p , ℓ ) pair. Lemma A.4 tells us that all such Φ i \Phi_i Φ i have Succ ( Φ i ) \operatorname{Succ}(\Phi_i) Succ ( Φ i ) , so it follows that Succ ( Φ ) \operatorname{Succ}(\Phi) Succ ( Φ ) .
Lemma A.9 (Φ \Phi Φ -weakening, values). If
(i) Γ ; Π ; Φ ⊢ V : A \Gamma; \Pi; \Phi\vdash V : A Γ ; Π ; Φ ⊢ V : A and
(ii) Succ ( Φ ′ ) \operatorname{Succ}(\Phi') Succ ( Φ ′ ) ,
then Γ ; Π ; Φ ⋈ Φ ′ ⊢ V : A \Gamma; \Pi; \Phi\bowtie\Phi' \vdash V : A Γ ; Π ; Φ ⋈ Φ ′ ⊢ V : A .
Proof. By induction on the derivation of the typing judgment (i).
Lemma A.10 (Φ \Phi Φ -weakening, computations). If
(i) Γ ; Π ; Φ ⊢ M : A ! E \Gamma; \Pi; \Phi\vdash M : A ! E Γ ; Π ; Φ ⊢ M : A ! E ,
(ii) Succ ( Φ ′ ) \operatorname{Succ}(\Phi') Succ ( Φ ′ ) , and
(iii) Φ ⋈ Φ ′ \Phi\bowtie\Phi' Φ ⋈ Φ ′ is defined,
then Γ ; Π ; Φ ◃ Φ ′ ⊢ M : A ! E \Gamma\mathbin{;} \Pi\mathbin{;} \Phi\triangleleft\Phi' \vdash M : A ! E Γ ; Π ; Φ ◃ Φ ′ ⊢ M : A ! E .
Proof. By induction on the derivation of the typing judgment (i).
Lemma A.11 (Φ-weakening, bodies). If
Γ ; Π ; Φ ⊢ D : L \Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash D : \mathcal{L} Γ ; Π ; Φ ⊢ D : L ,
Succ ( Φ ′ ) \operatorname{Succ}(\Phi') Succ ( Φ ′ ) , and
Φ ◃ Φ ′ \Phi\triangleleft\Phi' Φ ◃ Φ ′ is defined, then Γ ; Π ; Φ ◃ Φ ′ ⊢ D : L \Gamma\mathbin{;} \Pi\mathbin{;} \Phi\triangleleft\Phi' \vdash D : \mathcal{L} Γ ; Π ; Φ ◃ Φ ′ ⊢ D : L .
Proof. By induction on the derivation of the typing judgment (i).
Progress
We begin with a standard canonical forms lemma:
Lemma A.12 (Canonical forms). If ∅ ; Π ; Φ ⊢ V : A \emptyset\mathbin{;} \Pi\mathbin{;} \Phi\vdash V : A ∅ ; Π ; Φ ⊢ V : A , then:
if A = 1 A = 1 A = 1 , then V = ( ) V = () V = ( ) .
if A = S t r A = \mathrm{Str} A = Str , then V = s V = s V = s .
if A = B o o l A = \mathrm{Bool} A = Bool , then V = t r u e V = \mathrm{true} V = true or V = f a l s e V = \mathrm{false} V = false .
if A = A 1 → A 2 A = A_1 \to A_2 A = A 1 → A 2 , then V = λ x . M V = \lambda x.M V = λ x . M or V = set p ℓ V = \operatorname{set}_{p}^{\ell} V = set p ℓ .
if A = A 1 × A 2 A = A_1 \times A_2 A = A 1 × A 2 , then V = ( V 1 , V 2 ) V = (V_1,V_2) V = ( V 1 , V 2 ) .
if A = L i s t B A = \mathrm{List}\ B A = List B , then V = [ ] V = [] V = [ ] or V = V 1 : : V 2 V = V_1 :: V_2 V = V 1 :: V 2 .
if A = E l e m e n t A = \mathrm{Element} A = Element , then V = t e x t W V = \mathrm{text}\ W V = text W or V = t a g ( V 1 , V 2 ) V = \mathrm{tag}(V_1,V_2) V = tag ( V 1 , V 2 ) or V = c o m p o n e n t { D } V = \mathrm{component}\ \{D\} V = component { D } .
if A = A t t r A = \mathrm{Attr} A = Attr , then V = a t t r ( V 1 , V 2 ) V = \mathrm{attr}(V_1,V_2) V = attr ( V 1 , V 2 ) or v = o n C l i c k W v = \mathrm{onClick}\ W v = onClick W .
if A = E l e m I n s t A = \mathrm{ElemInst} A = ElemInst , then V = t e x t I n s t W V = \mathrm{textInst}\ W V = textInst W or V = t a g I n s t i d ( V 1 , V 2 ) V = \mathrm{tagInst}_{id}(V_1,V_2) V = tagInst i d ( V 1 , V 2 ) or V = c o m p I n s t p ( ⌈ D ⌉ , W ) V = \mathrm{compInst}_{p}(\lceil D\rceil,W) V = compInst p (⌈ D ⌉ , W ) .
Proof. By case-analysis on the derivation of the typing judgment. Since Γ = ∅ \Gamma= \emptyset Γ = ∅ , rule TV-Var is impossible.
We then proceed to proofs of progress for the three mutually-defined step judgments.
Theorem A.13 (Progress for ⇝ \rightsquigarrow ⇝ ). If ∅ ; Π ; Φ H ; Φ D ⊢ H ; M : A ! E \emptyset\mathbin{;} \Pi\mathbin{;} \Phi_H \mathbin{;} \Phi_D \vdash\mathcal{H} \mathbin{;} M : A ! E ∅ ; Π ; Φ H ; Φ D ⊢ H ; M : A ! E , then either:
(i) M = val V M = \operatorname{val}\ V M = val V or
(ii) H ; M ⇝ N ; H ′ \mathcal{H} \mathbin{;} M \rightsquigarrow N \mathbin{;} \mathcal{H}' H ; M ⇝ N ; H ′ for some N N N and H ′ \mathcal{H}' H ′ .
Proof. By definition of the premise, we have
(i) ∅ ; Π ; Φ M ⊢ M : A ! E \emptyset\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash M : A ! E ∅ ; Π ; Φ M ⊢ M : A ! E and
(ii) ∅ ; Π ; Φ H ⊨ H \emptyset\mathbin{;} \Pi\mathbin{;} \Phi_H \models\mathcal{H} ∅ ; Π ; Φ H ⊨ H .
We proceed by mutual induction on the derivation of the computation typing judgment (i) alongside Lemmas A.14 and A.15.
Case TC-Val: We trivially satisfy conclusion (i).
∅ ; Π ; Φ M ⊢ V : A ∅ ; Π ; Φ M ⊢ val V : A ! P u r e T C - V a l \begin{gathered}
\emptyset\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash V : A \\
\hline
\emptyset\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash\operatorname{val}\ V : A ! \mathrm{Pure}
\end{gathered}
\quad\mathrm{TC\text{-}Val} ∅ ; Π ; Φ M ⊢ V : A ∅ ; Π ; Φ M ⊢ val V : A ! Pure TC - Val
Case TC-Let: We have
\frac{
\begin{gathered}
\varnothing;\Pi;\Phi_1 \vdash M:A!E \qquad x:A;\Pi;\Phi_2 \vdash N:B!E
\end{gathered}
}{
\varnothing;\Pi;\Phi_1 \bowtie\Phi_2 \vdash\operatorname{let} x=M\operatorname{ in}N:B!E
}\ \mathrm{TC\mathchar`-Let}
By inductive hypothesis on (1) and premise (ii), we have two subcases: either (a) M = val V M=\operatorname{val} V M = val V or (b) H ; M ⇝ M ′ ; H ′ \mathcal{H};M\rightsquigarrow M';\mathcal{H}' H ; M ⇝ M ′ ; H ′ .
In subcase (a), rule EC-Val says that H ; let x = val V in N ⇝ N [ V / x ] ; H \mathcal{H};\operatorname{let} x=\operatorname{val} V\operatorname{ in}N\rightsquigarrow N[V/x];\mathcal{H} H ; let x = val V in N ⇝ N [ V / x ] ; H .
In subcase (b), we derive a step as follows:
\frac{\mathcal{H};M\rightsquigarrow M';\mathcal{H}'}{\mathcal{H};\operatorname{let} x=M\operatorname{ in}N\rightsquigarrow\operatorname{let} x=M'\operatorname{ in}N;\mathcal{H}'}\ \mathrm{EC\mathchar`-Let}
Case TC-App: We have
\frac{
\begin{gathered}
\varnothing;\Pi;\Phi_1\vdash V:A\xrightarrow{E}B \qquad\varnothing;\Pi;\Phi_2\vdash W:A_1
\end{gathered}
}{
\varnothing;\Pi;\Phi_1\bowtie\Phi_2\vdash VW:B!E
}\ \mathrm{TC\mathchar`-App}
By Lemma A.12 (canonical forms) on (1), we have two subcases: either (a) V = λ x . N V=\lambda x.N V = λ x . N or (b) V = set p ℓ V=\operatorname{set}^{\ell}_{p} V = set p ℓ .
In subcase (a), we apply EC-App to get H ; ( λ x . N ) V ⇝ N [ V / x ] ; H \mathcal{H};(\lambda x.N)V\rightsquigarrow N[V/x];\mathcal{H} H ; ( λ x . N ) V ⇝ N [ V / x ] ; H .
In subcase (b), we continue our bottom-up derivation:
\frac{\ell:A\in\Pi[p]\qquad\operatorname{Succ}(\Phi_1)}{\varnothing;\Pi;\Phi_1\vdash\operatorname{set}^{\ell}_{p}:A\xrightarrow{\mathrm{Mut}}B}\ \mathrm{TV\mathchar`-Set}
From (2) and premise (ii), we know that ℓ ∈ dom ( H [ p ] . st ) \ell\in\operatorname{dom}(\mathcal{H}[p].\operatorname{st}) ℓ ∈ dom ( H [ p ] . st ) .
Thus, H ′ = H ∣ H [ p ] . st [ ℓ ] = V \mathcal{H}'=\mathcal{H}\mid\mathcal{H}[p].\operatorname{st}[\ell]=V H ′ = H ∣ H [ p ] . st [ ℓ ] = V and H [ p ] . rerender = tt \mathcal{H}[p].\operatorname{rerender}=\operatorname{tt} H [ p ] . rerender = tt is well-defined.
We can therefore apply EC-AppSet to get H ; set p ℓ V ⇝ val ( ) ; H ′ \mathcal{H};\operatorname{set}^{\ell}_{p}V\rightsquigarrow\operatorname{val} (); \mathcal{H}' H ; set p ℓ V ⇝ val ( ) ; H ′ .
Thus, in either subcase we take a step, satisfying conclusion (ii).
Case TC-If: We have
\frac{
\begin{gathered}
\varnothing;\Pi;\Phi_1\vdash V:\operatorname{Bool}\qquad
\varnothing;\Pi;\Phi_2\vdash M:A!E\qquad
\varnothing;\Pi;\Phi_2\vdash N:A!E
\end{gathered}
}{
\varnothing;\Pi;\Phi_1\bowtie\Phi_2\vdash\operatorname{if}\ V\ \operatorname{then}\ M\ \operatorname{else}\ N:A!E
}\ \mathrm{TC\mathchar`-If}
By Lemma A.12 (canonical forms) on (1), we have two subcases: either (a) V = true V=\operatorname{true} V = true or (b) V = false V=\operatorname{false} V = false .
In subcase (a), we apply EC-IfT to get H ; if true then M else N ⇝ M ; H \mathcal{H};\operatorname{if}\ \operatorname{true}\ \operatorname{then}\ M\ \operatorname{else}\ N\rightsquigarrow M;\mathcal{H} H ; if true then M else N ⇝ M ; H .
In subcase (b), we apply EC-IfF to get H ; if false then M else N ⇝ N ; H \mathcal{H};\operatorname{if}\ \operatorname{false}\ \operatorname{then}\ M\ \operatorname{else}\ N\rightsquigarrow N;\mathcal{H} H ; if false then M else N ⇝ N ; H .
Thus, in either subcase we take a step, satisfying conclusion (ii).
Case TC-Fst: We have
\frac{\varnothing;\Pi;\Phi_M\vdash V:A\times B}{\varnothing;\Pi;\Phi_M\vdash\operatorname{fst}V:A!\operatorname{Pure}}\ \mathrm{TC\mathchar`-Fst}
By Lemma A.12 (canonical forms) on (1), we have that V = ( V 1 , V 2 ) V = (V_1,V_2) V = ( V 1 , V 2 ) .
Rule EC-Fst then tells us that H ; fst ( V 1 , V 2 ) ⇝ val V 1 ; H \mathcal{H} ; \operatorname{fst}\ (V_1,V_2) \leadsto\operatorname{val}\ V_1 ; \mathcal{H} H ; fst ( V 1 , V 2 ) ⇝ val V 1 ; H , satisfying conclusion (ii).
Case TC-Snd: Analogous to the above case, via EC-Snd.
Case TC-Fold: We have
∅ ; Π ; Φ 1 ⊢ V 1 : A → E B → E B ∅ ; Π ; Φ 2 ⊢ V 2 : B ∅ ; Π ; Φ 3 ⊢ V 3 : List A ∅ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ fold V 1 V 2 V 3 : B ! Mut (1) \frac{\begin{gathered}
\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash V_1 : A \xrightarrow{E} B \xrightarrow{E} B \qquad
\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash V_2 : B \qquad
\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_3 \vdash V_3 : \operatorname{List} A
\end{gathered}}{\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_1 \bowtie\Phi_2 \bowtie\Phi_3 \vdash\operatorname{fold}\ V_1\ V_2\ V_3 : B\ !\ \operatorname{Mut}} \tag*{(1)} ∅ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ fold V 1 V 2 V 3 : B ! Mut ∅ ; Π ; Φ 1 ⊢ V 1 : A E B E B ∅ ; Π ; Φ 2 ⊢ V 2 : B ∅ ; Π ; Φ 3 ⊢ V 3 : List A (1)
By Lemma A.12 (canonical forms) on (1), we have two subcases: either (a) V 3 = [ ] V_3 = [] V 3 = [ ] or (b) V 3 = V h : : V t V_3 = V_h :: V_t V 3 = V h :: V t .
In subcase (a), we apply EC-FdN to get H ; fold V 1 V 2 [ ] ⇝ val V 2 ; H \mathcal{H} ; \operatorname{fold}\ V_1\ V_2\ [] \leadsto\operatorname{val}\ V_2 ; \mathcal{H} H ; fold V 1 V 2 [ ] ⇝ val V 2 ; H .
In subcase (v), we apply EC-FdC to get H ; fold V 1 V 2 ( V h : : V t ) ⇝ V 1 V h ( fold V 1 V 2 V t ) ; H \mathcal{H} ; \operatorname{fold}\ V_1\ V_2\ (V_h :: V_t) \leadsto V_1\ V_h\ (\operatorname{fold}\ V_1\ V_2\ V_t) ; \mathcal{H} H ; fold V 1 V 2 ( V h :: V t ) ⇝ V 1 V h ( fold V 1 V 2 V t ) ; H .
Thus, in either subcase we take a step, satisfying conclusion (ii).
Case TC-Sub: We have
∅ ; Π ; Φ M ⊢ M : A ! Pure ∅ ; Π ; Φ M ⊢ M : A ! Mut (2) \frac{\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash M : A\ !\ \operatorname{Pure}}{\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash M : A\ !\ \operatorname{Mut}} \tag*{(2)} ∅ ; Π ; Φ M ⊢ M : A ! Mut ∅ ; Π ; Φ M ⊢ M : A ! Pure (2)
Case TC-EvalI: We have
∅ ; Π ; Φ 1 ⊢ D 0 : L ⊎ Π [ p ] ∅ ; Π ; Φ 2 ⊢ D : L ∅ ; Π ; Φ 1 ⋈ Φ 2 , p : Init ⊢ ⌈ D 0 ⌉ ↓ p Init D : ElemInst ! Mut (3) \frac{\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash D_0 : L \uplus\Pi[p] \qquad\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash D : L}{\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_1 \bowtie\Phi_2, p : \operatorname{Init} \vdash\lceil D_0\rceil\mathrel{\downarrow^{\operatorname{Init}}_p} D : \operatorname{ElemInst}\ !\ \operatorname{Mut}} \tag*{(3)} ∅ ; Π ; Φ 1 ⋈ Φ 2 , p : Init ⊢ ⌈ D 0 ⌉ ↓ p Init D : ElemInst ! Mut ∅ ; Π ; Φ 1 ⊢ D 0 : L ⊎ Π [ p ] ∅ ; Π ; Φ 2 ⊢ D : L (3)
By (1), we have (3) that p ∈ dom ( Π ) p \in\operatorname{dom}(\Pi) p ∈ dom ( Π ) .
By mutual inductive hypothesis (Theorem A.14 ) on (2), (3), and premise (ii), we have two subcases: either (a) D = val V D = \operatorname{val}\ V D = val V or (b) H ; D ⇝ p Init D ′ ; H ′ \mathcal{H} ; D \mathrel{\leadsto^{\operatorname{Init}}_p} D' ; \mathcal{H}' H ; D ⇝ p Init D ′ ; H ′ .
In subcase (a), we apply EC-EvalDone to get
H ; ⌈ D 0 ⌉ ↓ p Init val V ⇝ let x = init V in val compInst p ( ⌈ D 0 ⌉ , x ) ; H . \mathcal{H} ; \lceil D_0\rceil\mathrel{\downarrow^{\operatorname{Init}}_p} \operatorname{val}\ V \leadsto\operatorname{let}\ x = \operatorname{init}\ V\ \operatorname{in}\ \operatorname{val}\ \operatorname{compInst}_p(\lceil D_0\rceil,x) ; \mathcal{H}. H ; ⌈ D 0 ⌉ ↓ p Init val V ⇝ let x = init V in val compInst p (⌈ D 0 ⌉ , x ) ; H .
H ; D ⇝ p Init D ′ ; H ′ H ; ⌈ D 0 ⌉ ↓ p Init D ⇝ ⌈ D 0 ⌉ ↓ p Init D ′ ; H ′ \frac{\mathcal{H} ; D \mathrel{\leadsto^{\operatorname{Init}}_p} D' ; \mathcal{H}'}{\mathcal{H} ; \lceil D_0\rceil\mathrel{\downarrow^{\operatorname{Init}}_p} D \leadsto\lceil D_0\rceil\mathrel{\downarrow^{\operatorname{Init}}_p} D' ; \mathcal{H}'} H ; ⌈ D 0 ⌉ ↓ p Init D ⇝ ⌈ D 0 ⌉ ↓ p Init D ′ ; H ′ H ; D ⇝ p Init D ′ ; H ′
Case TC-EvalS: We have
∅ ; Π ; Φ 1 ⊢ D 0 : Π [ p ] ∅ ; Π ; Φ 2 ⊢ D : L L ⊆ Π [ p ] ( Φ 1 ⋈ Φ 2 ) [ p ] = Succ ∅ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ⌈ D 0 ⌉ ↓ p Succ D : ElemInst ! Mut (4) \frac{\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash D_0 : \Pi[p] \qquad\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash D : L \qquad L \subseteq\Pi[p] \qquad(\Phi_1 \bowtie\Phi_2)[p] = \operatorname{Succ}}{\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_1 \bowtie\Phi_2 \vdash\lceil D_0\rceil\mathrel{\downarrow^{\operatorname{Succ}}_p} D : \operatorname{ElemInst}\ !\ \operatorname{Mut}} \tag*{(4)} ∅ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ⌈ D 0 ⌉ ↓ p Succ D : ElemInst ! Mut ∅ ; Π ; Φ 1 ⊢ D 0 : Π [ p ] ∅ ; Π ; Φ 2 ⊢ D : L L ⊆ Π [ p ] ( Φ 1 ⋈ Φ 2 ) [ p ] = Succ (4)
By mutual inductive hypothesis (Theorem A.15 ) on (1), (2), and premise (ii), we have two subcases: either (a) D = val V D = \operatorname{val}\ V D = val V or (b) H ; D ⇝ p Succ D ′ ; H ′ \mathcal{H} ; D \mathrel{\leadsto^{\operatorname{Succ}}_p} D' ; \mathcal{H}' H ; D ⇝ p Succ D ′ ; H ′ .
In subcase (a), we apply EC-EvalDone to get
H ; ⌈ D 0 ⌉ ↓ p Succ val V ⇝ let x = init V in val compInst p ( ⌈ D 0 ⌉ , x ) ; H . \mathcal{H} ; \lceil D_0\rceil\mathrel{\downarrow^{\operatorname{Succ}}_p} \operatorname{val}\ V \leadsto\operatorname{let}\ x = \operatorname{init}\ V\ \operatorname{in}\ \operatorname{val}\ \operatorname{compInst}_p(\lceil D_0\rceil,x) ; \mathcal{H}. H ; ⌈ D 0 ⌉ ↓ p Succ val V ⇝ let x = init V in val compInst p (⌈ D 0 ⌉ , x ) ; H .
H ; D ⇝ p S u c c D ′ ; H ′ H ; ⌈ D 0 ⌉ ⇓ p S u c c D ⇝ ⌈ D 0 ⌉ ⇓ p S u c c D ′ ; H ′ E C - E v a l \frac{\mathcal{H} \mathbin{;} D \mathrel{\leadsto}_{p}^{\mathrm{Succ}} D' \mathbin{;} \mathcal{H}'}{\mathcal{H} \mathbin{;} \lceil D_0 \rceil\mathord{\Downarrow}_{p}^{\mathrm{Succ}} D \mathrel{\leadsto} \lceil D_0 \rceil\mathord{\Downarrow}_{p}^{\mathrm{Succ}} D' \mathbin{;} \mathcal{H}'}
\quad\mathrm{EC\text{-}Eval} H ; ⌈ D 0 ⌉ ⇓ p Succ D ⇝ ⌈ D 0 ⌉ ⇓ p Succ D ′ ; H ′ H ; D ⇝ p Succ D ′ ; H ′ EC - Eval
Case TC-Init: We have
∅ ; Π ; Φ M ⊢ V : E l e m e n t ∅ ; Π ; Φ M ⊢ i n i t V : E l e m I n s t ! M u t T C - I n i t \frac{
\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash V : \mathrm{Element}
}{
\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash\mathrm{init}\ V : \mathrm{ElemInst}\ !\ \mathrm{Mut}
}
\quad\mathrm{TC\text{-}Init} ∅ ; Π ; Φ M ⊢ init V : ElemInst ! Mut ∅ ; Π ; Φ M ⊢ V : Element TC - Init
By Lemma A.12 (canonical forms) on (1), we have three subcases: either (a) V = t e x t W V = \mathrm{text}\ W V = text W , (b) V = t a g ( V 1 , V 2 ) V = \mathrm{tag}(V_1,V_2) V = tag ( V 1 , V 2 ) , or (c) V = c o m p o n e n t D V = \mathrm{component}\ D V = component D .
In subcase (a), we apply EC-InitText to get H ; i n i t t e x t W ⇝ v a l t e x t I n s t W ; H \mathcal{H} \mathbin{;} \mathrm{init}\ \mathrm{text}\ W \mathrel{\leadsto} \mathrm{val}\ \mathrm{textInst}\ W \mathbin{;} \mathcal{H} H ; init text W ⇝ val textInst W ; H .
In subcase (b), we apply EC-InitTag to get H ; i n i t t a g ( V 1 , V 2 ) ⇝ l e t x = i n i t s V 2 i n v a l t a g I n s t i d ( V 1 , x ) ; H \mathcal{H} \mathbin{;} \mathrm{init}\ \mathrm{tag}(V_1,V_2) \mathrel{\leadsto} \mathrm{let}\ x = \mathrm{inits}\ V_2\ \mathrm{in}\ \mathrm{val}\ \mathrm{tagInst}_{id}(V_1,x) \mathbin{;} \mathcal{H} H ; init tag ( V 1 , V 2 ) ⇝ let x = inits V 2 in val tagInst i d ( V 1 , x ) ; H for a fresh i d id i d .
In subcase (c), we apply EC-InitComp to get H ; i n i t c o m p o n e n t { D } ⇝ ⌈ D ⌉ ⇓ p I n i t D ; H ′ \mathcal{H} \mathbin{;} \mathrm{init}\ \mathrm{component}\ \{D\} \mathrel{\leadsto} \lceil D \rceil\mathord{\Downarrow}_{p}^{\mathrm{Init}} D \mathbin{;} \mathcal{H}' H ; init component { D } ⇝ ⌈ D ⌉ ⇓ p Init D ; H ′ for some H ′ \mathcal{H}' H ′ and a fresh p p p .
Thus, in any subcase we take a step, satisfying conclusion ( i i ) (ii) ( ii ) .
Case TC-Click: We have
∅ ; Π ; Φ M ⊢ V : E l e m I n s t ∅ ; Π ; Φ M ⊢ c l i c k i d V : 1 ! M u t T C - C l i c k \frac{
\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash V : \mathrm{ElemInst}
}{
\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash\mathrm{click}_{id}\ V : 1\ !\ \mathrm{Mut}
}
\quad\mathrm{TC\text{-}Click} ∅ ; Π ; Φ M ⊢ click i d V : 1 ! Mut ∅ ; Π ; Φ M ⊢ V : ElemInst TC - Click
By Lemma A.12 (canonical forms) on (1), we have three subcases: either (a) V = t e x t I n s t W V = \mathrm{textInst}\ W V = textInst W , (b) V = t a g I n s t i d ′ ( V 1 , V 2 ) V = \mathrm{tagInst}_{id'}(V_1,V_2) V = tagInst i d ′ ( V 1 , V 2 ) , or (c) V = c o m p I n s t p ( ⌈ D ⌉ , W ) V = \mathrm{compInst}_{p}(\lceil D \rceil,W) V = compInst p (⌈ D ⌉ , W ) .
In subcase (a), we apply EC-ClickText to get H ; c l i c k i d t e x t I n s t W ⇝ v a l ( ) ; H \mathcal{H} \mathbin{;} \mathrm{click}_{id}\ \mathrm{textInst}\ W \mathrel{\leadsto} \mathrm{val}\ () \mathbin{;} \mathcal{H} H ; click i d textInst W ⇝ val ( ) ; H .
In subcase (b), we further subcase on whether i d = i d ′ id = id' i d = i d ′ :
If so, then EC-ClickTagT gives that H ; c l i c k i d t a g I n s t i d ( V 1 , V 2 ) ⇝ r u n C l i c k s V 1 ; c l i c k s i d V 2 ; H \mathcal{H} \mathbin{;} \mathrm{click}_{id}\ \mathrm{tagInst}_{id}(V_1,V_2) \mathrel{\leadsto} \mathrm{runClicks}\ V_1 \mathbin{;} \mathrm{clicks}_{id}\ V_2 \mathbin{;} \mathcal{H} H ; click i d tagInst i d ( V 1 , V 2 ) ⇝ runClicks V 1 ; clicks i d V 2 ; H .
If not, then EC-ClickTagF gives that H ; c l i c k i d t a g I n s t i d ′ ( V 1 , V 2 ) ⇝ c l i c k s i d V 2 ; H \mathcal{H} \mathbin{;} \mathrm{click}_{id}\ \mathrm{tagInst}_{id'}(V_1,V_2) \mathrel{\leadsto} \mathrm{clicks}_{id}\ V_2 \mathbin{;} \mathcal{H} H ; click i d tagInst i d ′ ( V 1 , V 2 ) ⇝ clicks i d V 2 ; H .
In subcase (c), EC-ClickComp gives that H ; c l i c k i d c o m p I n s t p ( ⌈ D ⌉ , W ) ⇝ c l i c k i d W ; H \mathcal{H} \mathbin{;} \mathrm{click}_{id}\ \mathrm{compInst}_{p}(\lceil D \rceil,W) \mathrel{\leadsto} \mathrm{click}_{id}\ W \mathbin{;} \mathcal{H} H ; click i d compInst p (⌈ D ⌉ , W ) ⇝ click i d W ; H .
Thus, in any subcase we take a step, satisfying conclusion ( i i ) (ii) ( ii ) .
Case TC-RunClick: We have
∅ ; Π ; Φ M ⊢ V : A t t r ∅ ; Π ; Φ M ⊢ r u n C l i c k V : 1 ! M u t T C - R u n C l i c k \frac{
\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash V : \mathrm{Attr}
}{
\varnothing\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash\mathrm{runClick}\ V : 1\ !\ \mathrm{Mut}
}
\quad\mathrm{TC\text{-}RunClick} ∅ ; Π ; Φ M ⊢ runClick V : 1 ! Mut ∅ ; Π ; Φ M ⊢ V : Attr TC - RunClick
By Lemma A.12 (canonical forms) on (1), we have two subcases: either (a) V = a t t r ( V 1 , V 2 ) V = \mathrm{attr}(V_1,V_2) V = attr ( V 1 , V 2 ) or (b) V = o n C l i c k W V = \mathrm{onClick}\ W V = onClick W .
In subcase (a), we apply EC-RunAttr to get H ; r u n C l i c k a t t r ( V 1 , V 2 ) ⇝ v a l ( ) ; H \mathcal{H} \mathbin{;} \mathrm{runClick}\ \mathrm{attr}(V_1,V_2) \mathrel{\leadsto} \mathrm{val}\ () \mathbin{;} \mathcal{H} H ; runClick attr ( V 1 , V 2 ) ⇝ val ( ) ; H .
In subcase (v), we apply EC-RunClick to get H ; r u n C l i c k o n C l i c k W ⇝ W ( ) ; H \mathcal{H} \mathbin{;} \mathrm{runClick}\ \mathrm{onClick}\ W \mathrel{\leadsto} W\ () \mathbin{;} \mathcal{H} H ; runClick onClick W ⇝ W ( ) ; H .
Thus, in either subcase we take a step, satisfying conclusion ( i i ) (ii) ( ii ) .
Case TC-Update: We have
\frac{
\frac{(1)}
{\emptyset\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash V : \operatorname{ElemInst}}
}{
\emptyset\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash\operatorname{update}\ V : \operatorname{ElemInst}\ !\ \operatorname{Mut}
}
\quad\textsc{TC-Update}
By Lemma A.12 (canonical forms) on (1), we have three subcases: either (a) V = textInst W V = \operatorname{textInst}\ W V = textInst W , (b) V = tagInst i d ( V 1 , V 2 ) V = \operatorname{tagInst}_{id}(V_1,V_2) V = tagInst i d ( V 1 , V 2 ) , or (c) V = compInst p ( ⌈ D ⌉ , W ) V = \operatorname{compInst}_{p}(\lceil D\rceil,W) V = compInst p (⌈ D ⌉ , W ) .
In subcase (a), \textsc{EC-UpdateText} gives that H ; update textInst W ⇝ val textInst W ; H \mathcal{H}\mathbin{;}\operatorname{update}\ \operatorname{textInst}\ W \rightsquigarrow\operatorname{val}\ \operatorname{textInst}\ W\mathbin{;}\mathcal{H} H ; update textInst W ⇝ val textInst W ; H .
In subcase (b), we apply \textsc{EC-UpdateTag} to get H ; update tagInst i d ( V 1 , V 2 ) ⇝ let x = updates V 2 in val tagInst i d ( V 1 , x ) ; H \mathcal{H}\mathbin{;}\operatorname{update}\ \operatorname{tagInst}_{id}(V_1,V_2) \rightsquigarrow\operatorname{let}\ x = \operatorname{updates}\ V_2\ \operatorname{in}\ \operatorname{val}\ \operatorname{tagInst}_{id}(V_1,x)\mathbin{;}\mathcal{H} H ; update tagInst i d ( V 1 , V 2 ) ⇝ let x = updates V 2 in val tagInst i d ( V 1 , x ) ; H .
In subcase (c), we continue derivation from (1) as follows (where Φ M = Φ 1 ⋈ Φ 2 \Phi_M = \Phi_1 \bowtie\Phi_2 Φ M = Φ 1 ⋈ Φ 2 ):
\frac{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash D : \Pi[p]
\qquad
\Phi_M[p] = \operatorname{Succ}
\qquad
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash W : \operatorname{ElemInst}
}{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash\operatorname{compInst}_{p}(\lceil D\rceil,W) : \operatorname{ElemInst}
}
\quad\textsc{TV-CompI}
(2) gives that Π [ p ] \Pi[p] Π [ p ] is defined. Then by premise (ii), we know that H [ p ] . rerender \mathcal{H}[p].\operatorname{rerender} H [ p ] . rerender is defined. We further subcase on the value of H [ p ] . rerender \mathcal{H}[p].\operatorname{rerender} H [ p ] . rerender :
If H [ p ] . rerender = tt \mathcal{H}[p].\operatorname{rerender} = \operatorname{tt} H [ p ] . rerender = tt , we apply \textsc{EC-UpdateCompT} to get H ; update compInst p ( ⌈ D ⌉ , W ) ⇝ ⌈ D ⌉ ⇓ p Succ D ; H ′ \mathcal{H}\mathbin{;}\operatorname{update}\ \operatorname{compInst}_{p}(\lceil D\rceil,W) \rightsquigarrow\lceil D\rceil\mathrel{\Downarrow_{p}^{\operatorname{Succ}}} D\mathbin{;}\mathcal{H}' H ; update compInst p (⌈ D ⌉ , W ) ⇝ ⌈ D ⌉ ⇓ p Succ D ; H ′ for some H ′ \mathcal{H}' H ′ .
If instead H [ p ] . rerender = ff \mathcal{H}[p].\operatorname{rerender} = \operatorname{ff} H [ p ] . rerender = ff , we apply \textsc{EC-UpdateCompF} to get H ; update compInst p ( ⌈ D ⌉ , W ) ⇝ let x = update W in val compInst p ( ⌈ D ⌉ , x ) ; H \mathcal{H}\mathbin{;}\operatorname{update}\ \operatorname{compInst}_{p}(\lceil D\rceil,W) \rightsquigarrow\operatorname{let}\ x = \operatorname{update}\ W\ \operatorname{in}\ \operatorname{val}\ \operatorname{compInst}_{p}(\lceil D\rceil,x)\mathbin{;}\mathcal{H} H ; update compInst p (⌈ D ⌉ , W ) ⇝ let x = update W in val compInst p (⌈ D ⌉ , x ) ; H .
Thus, in any subcase we take a step, satisfying conclusion (ii).
Theorem A.14 (Progress for ⇝ p Init \rightsquigarrow_{p}^{\operatorname{Init}} ⇝ p Init ). If
(i) ∅ ; Π ; Φ H ; Φ D ⊢ H ; D : L \emptyset\mathbin{;} \Pi\mathbin{;} \Phi_H \mathbin{;} \Phi_D \vdash\mathcal{H}\mathbin{;}D : \mathcal{L} ∅ ; Π ; Φ H ; Φ D ⊢ H ; D : L and
(ii) p ∈ dom ( Π ) p \in\operatorname{dom}(\Pi) p ∈ dom ( Π ) ,
then either:
(i) D = val V D = \operatorname{val}\ V D = val V or
(ii) H ; D ⇝ p Init D ′ ; H ′ \mathcal{H}\mathbin{;}D \rightsquigarrow_{p}^{\operatorname{Init}} D'\mathbin{;}\mathcal{H}' H ; D ⇝ p Init D ′ ; H ′ for some D ′ D' D ′ and H ′ \mathcal{H}' H ′ .
Proof. By definition of premise (i), we have subpremises
(i-a) ∅ ; Π ; Φ D ⊢ D : L \emptyset\mathbin{;} \Pi\mathbin{;} \Phi_D \vdash D : \mathcal{L} ∅ ; Π ; Φ D ⊢ D : L and
(i-b) ∅ ; Π ; Φ H ⊨ H \emptyset\mathbin{;} \Pi\mathbin{;} \Phi_H \models\mathcal{H} ∅ ; Π ; Φ H ⊨ H .
We proceed by mutual induction on the derivation of the body typing judgment (i-a) alongside Lemmas A.13 and A.15.
Case TB-Val: We immediately satisfy conclusion (i).
\frac{
\emptyset\mathbin{;} \Pi\mathbin{;} \Phi_D \vdash V : \operatorname{Element}
}{
\emptyset\mathbin{;} \Pi\mathbin{;} \Phi_D \vdash\operatorname{val}\ V : \emptyset
}
\quad\textsc{TB-Val}
Case TB-Let: We have
\frac{
\emptyset\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash M : A\ !\ \operatorname{Pure}
\qquad
x : A \mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash D : \mathcal{L}
}{
\emptyset\mathbin{;} \Pi\mathbin{;} \Phi_1 \bowtie\Phi_2 \vdash\operatorname{let}\ x = M\ \operatorname{in}\ D : \mathcal{L}
}
\quad\textsc{TB-Let}
By mutual inductive hypothesis (Theorem A.13 ) on (1) and premise (i-b), we have two subcases: either (a) M = val V M = \operatorname{val} V M = val V or (b) H ; M ⇝ N ; H ′ \mathcal{H} ; M \leadsto N ; \mathcal{H}' H ; M ⇝ N ; H ′ .
In subcase (a), we apply EB-VAL to get H ; let x = val V in D ⇝ Init p D [ V / x ] ; H \mathcal{H} ; \operatorname{let}\ x = \operatorname{val} V\ \operatorname{in}\ D \mathrel{\overset{\operatorname{Init}}{\leadsto}_{p}} D[V/x] ; \mathcal{H} H ; let x = val V in D ⇝ Init p D [ V / x ] ; H .
In subcase (b), we derive a step as follows:
H ; M ⇝ N ; H ′ H ; let x = M in D ⇝ Init p let x = N in D ; H ′ \begin{aligned}
&\mathcal{H} ; M \leadsto N ; \mathcal{H}' \\
&\mathcal{H} ; \operatorname{let}\ x = M\ \operatorname{in}\ D \mathrel{\overset{\operatorname{Init}}{\leadsto}_{p}} \operatorname{let}\ x = N\ \operatorname{in}\ D ; \mathcal{H}'
\end{aligned} H ; M ⇝ N ; H ′ H ; let x = M in D ⇝ Init p let x = N in D ; H ′
EB-LET
Case TB-STATE: We have
∅ ; Π ; Φ 1 ⊢ V : A x : A , x s e t : A ⟶ M u t 1 ; Π ; Φ 2 ⊢ D : L ℓ ∉ dom ( L ) ∅ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x s e t = useState ℓ V in D : L , ℓ : A \frac{\varnothing; \Pi; \Phi_{1} \vdash V : A \qquad x : A, x_{\mathrm{set}} : A \mathrel{\overset{\mathrm{Mut}}{\longrightarrow}} 1 ; \Pi; \Phi_{2} \vdash D : \mathcal{L} \qquad\ell\notin\operatorname{dom}(\mathcal{L})}{\varnothing; \Pi; \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{let}\ x, x_{\mathrm{set}} = \operatorname{useState}^{\ell}\ V\ \operatorname{in}\ D : \mathcal{L}, \ell: A} ∅ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x set = useState ℓ V in D : L , ℓ : A ∅ ; Π ; Φ 1 ⊢ V : A x : A , x set : A ⟶ Mut 1 ; Π ; Φ 2 ⊢ D : L ℓ ∈ / dom ( L )
TB-STATE
Say H ′ = H ∣ H [ p ] . st [ ℓ ] ↦ V \mathcal{H}' = \mathcal{H}\mid\mathcal{H}[p].\operatorname{st}[\ell] \mapsto V H ′ = H ∣ H [ p ] . st [ ℓ ] ↦ V . H ′ \mathcal{H}' H ′ is only well-defined if p ∈ dom ( H ) p \in\operatorname{dom}(\mathcal{H}) p ∈ dom ( H ) : this is given by premise (ii).
We can then apply EB-STATEI to satisfy conclusion (ii):
H ; let x , x s e t = useState ℓ V in D ⇝ Init p D [ V / x , set p ℓ / x s e t ] ; H ′ \mathcal{H} ; \operatorname{let}\ x, x_{\mathrm{set}} = \operatorname{useState}^{\ell}\ V\ \operatorname{in}\ D \mathrel{\overset{\operatorname{Init}}{\leadsto}_{p}} D[V/x,\operatorname{set}_{p}^{\ell}/x_{\mathrm{set}}] ; \mathcal{H}' H ; let x , x set = useState ℓ V in D ⇝ Init p D [ V / x , set p ℓ / x set ] ; H ′
Theorem A.15 (Progress for ⇝ p Succ \leadsto_{p}^{\operatorname{Succ}} ⇝ p Succ ). If
(i) ∅ ; Π ; Φ ⊢ H ; D : L \varnothing; \Pi; \Phi\vdash\mathcal{H} ; D : \mathcal{L} ∅ ; Π ; Φ ⊢ H ; D : L and
(ii) L ⊆ Π [ p ] \mathcal{L} \subseteq\Pi[p] L ⊆ Π [ p ] ,
then either:
(i) D = val V D = \operatorname{val} V D = val V or
(ii) H ; D ⇝ p Succ D ′ ; H ′ \mathcal{H} ; D \leadsto_{p}^{\operatorname{Succ}} D' ; \mathcal{H}' H ; D ⇝ p Succ D ′ ; H ′ for some D ′ D' D ′ and H ′ \mathcal{H}' H ′ .
Proof. By definition of premise (i), we have subpremises
(i-a) ∅ ; Π ; Φ D ⊢ D : L \varnothing; \Pi; \Phi_{D} \vdash D : \mathcal{L} ∅ ; Π ; Φ D ⊢ D : L and
(i-b) ∅ ; Π ; Φ H ⊨ H \varnothing; \Pi; \Phi_{H} \models\mathcal{H} ∅ ; Π ; Φ H ⊨ H .
We proceed by mutual induction on the derivation of the body typing judgment (i-a) alongside Lemmas A.13 and A.14.
Cases TB-VAL and TB-LET are shown analogously to Theorem A.14 (progress for ⇝ p Init \leadsto_{p}^{\operatorname{Init}} ⇝ p Init ).
Case TB-STATE: We have
∅ ; Π ; Φ 1 ⊢ V : A x : A , x s e t : A ⟶ M u t 1 ; Π ; Φ 2 ⊢ D : L ℓ ∉ dom ( L ) ∅ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x s e t = useState ℓ V in D : L , ℓ : A \frac{\varnothing; \Pi; \Phi_{1} \vdash V : A \qquad x : A, x_{\mathrm{set}} : A \mathrel{\overset{\mathrm{Mut}}{\longrightarrow}} 1 ; \Pi; \Phi_{2} \vdash D : \mathcal{L} \qquad\ell\notin\operatorname{dom}(\mathcal{L})}{\varnothing; \Pi; \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{let}\ x, x_{\mathrm{set}} = \operatorname{useState}^{\ell}\ V\ \operatorname{in}\ D : \mathcal{L}, \ell: A} ∅ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x set = useState ℓ V in D : L , ℓ : A ∅ ; Π ; Φ 1 ⊢ V : A x : A , x set : A ⟶ Mut 1 ; Π ; Φ 2 ⊢ D : L ℓ ∈ / dom ( L )
TB-STATE
H ; let x , x s e t = useState ℓ V in D ⇝ Succ p D [ H [ p ] . st [ ℓ ] / x , set p ℓ / x s e t ] ; H \mathcal{H} ; \operatorname{let}\ x, x_{\mathrm{set}} = \operatorname{useState}^{\ell}\ V\ \operatorname{in}\ D \mathrel{\overset{\operatorname{Succ}}{\leadsto}_{p}} D[\mathcal{H}[p].\operatorname{st}[\ell]/x,\operatorname{set}_{p}^{\ell}/x_{\mathrm{set}}] ; \mathcal{H} H ; let x , x set = useState ℓ V in D ⇝ Succ p D [ H [ p ] . st [ ℓ ] / x , set p ℓ / x set ] ; H
To do so, it suffices to show that H [ p ] . st [ ℓ ] \mathcal{H}[p].\operatorname{st}[\ell] H [ p ] . st [ ℓ ] is well-defined.
Premise (ii), alongside the type of the body, tells us that ℓ : A ∈ Π [ p ] \ell: A \in\Pi[p] ℓ : A ∈ Π [ p ] . Then by premise (i-b), we have that Γ ; Π ; Φ 3 ⊢ H [ p ] . st [ ℓ ] : A \Gamma; \Pi; \Phi_{3} \vdash\mathcal{H}[p].\operatorname{st}[\ell] : A Γ ; Π ; Φ 3 ⊢ H [ p ] . st [ ℓ ] : A , i.e. H [ p ] . st [ ℓ ] \mathcal{H}[p].\operatorname{st}[\ell] H [ p ] . st [ ℓ ] is well-defined.
We can thus apply EB-STATEs, satisfying conclusion (ii), and we are done.
We may now prove progress for the top-level step judgment using the above results:
Theorem 4.3 (Progress for ⇝ ⊤ \rightsquigarrow_{\top} ⇝ ⊤ ). If ∅ ; Π ; Φ H ; Φ M ⊢ H ; M : A ! E \varnothing;\Pi;\Phi_H;\Phi_M \vdash H;M:A!E ∅ ; Π ; Φ H ; Φ M ⊢ H ; M : A ! E , then H ; M ⇝ ⊤ N ; H ′ H;M\rightsquigarrow_{\top}N;H' H ; M ⇝ ⊤ N ; H ′ for some N N N and H ′ H' H ′ .
Proof.
By Theorem A.13 (progress for ⇝ \rightsquigarrow ⇝ ) on the premise, we either have (a) M = val V M=\operatorname{val}V M = val V or (b) H ; M ⇝ N ; H ′ H;M\rightsquigarrow N;H' H ; M ⇝ N ; H ′ .
In case (a), we apply rule ET-Event to get that H ; val V ⇝ ⊤ click i d V ; update V ; H H;\operatorname{val}V\rightsquigarrow_{\top}\operatorname{click}_{id}\ V;\operatorname{update}\ V;H H ; val V ⇝ ⊤ click i d V ; update V ; H .
In case (b), we derive a step as follows:
H ; M ⇝ N ; H ′ H ; M ⇝ ⊤ N ; H ′ ET-Lift \frac{H;M\rightsquigarrow N;H'}{H;M\rightsquigarrow_{\top}N;H'}\quad\text{ET-Lift} H ; M ⇝ ⊤ N ; H ′ H ; M ⇝ N ; H ′ ET-Lift
Preservation
We begin with a couple of auxiliary lemmas regarding typing contexts.
Lemma A.16. If Φ = Φ 1 ⋈ Φ 2 \Phi=\Phi_1\bowtie\Phi_2 Φ = Φ 1 ⋈ Φ 2 and Φ 1 ⊑ f r e s h Φ 1 ′ \Phi_1\sqsubseteq_{\mathrm{fresh}}\Phi'_1 Φ 1 ⊑ fresh Φ 1 ′ , then Φ ⊑ f r e s h Φ 1 ′ ⋈ Φ 2 \Phi\sqsubseteq_{\mathrm{fresh}}\Phi'_1\bowtie\Phi_2 Φ ⊑ fresh Φ 1 ′ ⋈ Φ 2 (and Φ 1 ′ ⋈ Φ 2 \Phi'_1\bowtie\Phi_2 Φ 1 ′ ⋈ Φ 2 is defined).
Proof. We first want to show (c1) that Φ [ p ] ∈ Φ 1 ′ ⋈ Φ 2 \Phi[p]\in\Phi'_1\bowtie\Phi_2 Φ [ p ] ∈ Φ 1 ′ ⋈ Φ 2 for all p ∈ dom ( Φ ) p\in\operatorname{dom}(\Phi) p ∈ dom ( Φ ) . We case-analyze on the origin of p p p via the definition of ⋈ \bowtie ⋈ :
Case p : Init ∈ Φ 1 p:\operatorname{Init}\in\Phi_1 p : Init ∈ Φ 1 : We must also have p ∉ dom ( Φ 2 ) p\notin\operatorname{dom}(\Phi_2) p ∈ / dom ( Φ 2 ) . By the second premise, we have some ϕ ⊒ Init \phi\sqsupseteq\operatorname{Init} ϕ ⊒ Init with p : ϕ ∈ Φ 1 ′ p:\phi\in\Phi'_1 p : ϕ ∈ Φ 1 ′ . Then by definition, p : ϕ ∈ Φ 1 ′ ⋈ Φ 2 p:\phi\in\Phi'_1\bowtie\Phi_2 p : ϕ ∈ Φ 1 ′ ⋈ Φ 2 .
Case p : Succ ∈ Φ 1 p:\operatorname{Succ}\in\Phi_1 p : Succ ∈ Φ 1 : By the second premise, we have p : Succ ∈ Φ 1 ′ p:\operatorname{Succ}\in\Phi'_1 p : Succ ∈ Φ 1 ′ . We also must have either p ∉ dom ( Φ 2 ) p\notin\operatorname{dom}(\Phi_2) p ∈ / dom ( Φ 2 ) or Φ 2 ( p ) = Succ \Phi_2(p)=\operatorname{Succ} Φ 2 ( p ) = Succ . In either case, by definition, p : Succ ∈ Φ 1 ′ ⋈ Φ 2 p:\operatorname{Succ}\in\Phi'_1\bowtie\Phi_2 p : Succ ∈ Φ 1 ′ ⋈ Φ 2 .
Case p ∉ dom ( Φ 1 ) p\notin\operatorname{dom}(\Phi_1) p ∈ / dom ( Φ 1 ) : We must have p : ϕ ∈ Φ 2 p:\phi\in\Phi_2 p : ϕ ∈ Φ 2 . Then by the second premise, since p p p is not fresh, we have p ∉ dom ( Φ ′ ) p\notin\operatorname{dom}(\Phi') p ∈ / dom ( Φ ′ ) . Therefore, for any ϕ \phi ϕ , we get p : ϕ ∈ Φ 1 ′ ⋈ Φ 2 p:\phi\in\Phi'_1\bowtie\Phi_2 p : ϕ ∈ Φ 1 ′ ⋈ Φ 2 .
We have thus shown (c1). It remains to show (c2) that all p p p in dom ( Φ 1 ′ ⋈ Φ 2 ) ∖ dom ( Φ 1 ⋈ Φ 2 ) \operatorname{dom}(\Phi'_1\bowtie\Phi_2)\setminus\operatorname{dom}(\Phi_1\bowtie\Phi_2) dom ( Φ 1 ′ ⋈ Φ 2 ) ∖ dom ( Φ 1 ⋈ Φ 2 ) are fresh: this follows from the second premise, which gives us that all p p p in dom ( Φ ′ ) ∖ dom ( Φ 1 ) \operatorname{dom}(\Phi')\setminus\operatorname{dom}(\Phi_1) dom ( Φ ′ ) ∖ dom ( Φ 1 ) are fresh, alongside the fact that dom ( Φ 1 ′ ⋈ Φ 2 ) = dom ( Φ 1 ) ∪ dom ( Φ 2 ) \operatorname{dom}(\Phi'_1\bowtie\Phi_2)=\operatorname{dom}(\Phi_1)\cup\operatorname{dom}(\Phi_2) dom ( Φ 1 ′ ⋈ Φ 2 ) = dom ( Φ 1 ) ∪ dom ( Φ 2 ) .
The conclusion is thus given by (c1) and (c2), and we are done.
Lemma A.17 (Π-order preservation). If
Π ⊑ Φ 1 Π ′ \Pi\sqsubseteq_{\Phi_1}\Pi' Π ⊑ Φ 1 Π ′ and
Φ = Φ 1 ⋈ Φ 2 \Phi=\Phi_1\bowtie\Phi_2 Φ = Φ 1 ⋈ Φ 2 ,
then Π ⊑ Φ Π ′ \Pi\sqsubseteq_{\Phi}\Pi' Π ⊑ Φ Π ′ .
Proof. By case-analysis on the definition of premise (i). If Π = Π ′ \Pi=\Pi' Π = Π ′ , then the conclusion is trivial. Otherwise, for some number of p p p , we have p : Init ∈ Φ 1 p:\operatorname{Init}\in\Phi_1 p : Init ∈ Φ 1 . Consider an arbitrary such p p p : by premise (i), we have Π [ p ] ⊆ Π ′ [ p ] \Pi[p]\subseteq\Pi'[p] Π [ p ] ⊆ Π ′ [ p ] . By definition of ⋈ \bowtie ⋈ , we must also have p : Init ∈ Φ p:\operatorname{Init}\in\Phi p : Init ∈ Φ . It therefore remains that Π ⊑ Φ Π ′ \Pi\sqsubseteq_{\Phi}\Pi' Π ⊑ Φ Π ′ by definition.
Therefore, in any case, we have Π ⊑ Φ Π ′ \Pi\sqsubseteq_{\Phi}\Pi' Π ⊑ Φ Π ′ .
We prove substitution lemmas as usual, which are fairly standard. For values and computations, we have as additional premises that the context merge on Φ \Phi Φ is well-defined.
Lemma A.18 (Substitution, values). If
Γ ; Π ; Φ 1 ⊢ V : A \Gamma;\Pi;\Phi_1\vdash V:A Γ ; Π ; Φ 1 ⊢ V : A and
Γ , x : A ; Π ; Φ 2 ⊢ W : B \Gamma,x:A;\Pi;\Phi_2\vdash W:B Γ , x : A ; Π ; Φ 2 ⊢ W : B ,
then Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ W [ V / x ] : V \Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash W[V/x]:V Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ W [ V / x ] : V .
Proof. By mutual induction on the typing judgment ( i i ) (ii) ( ii ) alongside Lemmas A.19 and A.20.
Lemma A.19 (Substitution, computations). If
( i ) Γ ; Π ; Φ 1 ⊢ V : A , (i)\ \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash V : A, ( i ) Γ ; Π ; Φ 1 ⊢ V : A ,
( i i ) Γ , x : A ; Π ; Φ 2 ⊢ M : B ! E , (ii)\ \Gamma, x : A \mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash M : B\mathbin{!}E, ( ii ) Γ , x : A ; Π ; Φ 2 ⊢ M : B ! E , and
( i i i ) Φ = Φ 1 ⋈ Φ 2 , (iii)\ \Phi= \Phi_1 \bowtie\Phi_2, ( iii ) Φ = Φ 1 ⋈ Φ 2 ,
then Γ ; Π ; Φ ⊢ M [ V / x ] : B ! E \Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash M[V/x] : B\mathbin{!}E Γ ; Π ; Φ ⊢ M [ V / x ] : B ! E .
Proof. By mutual induction on the typing judgment ( i i ) (ii) ( ii ) alongside Lemmas A.18 and A.20.
Lemma A.20 (Substitution, bodies). If
( i ) Γ ; Π ; Φ 1 ⊢ V : A , (i)\ \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash V : A, ( i ) Γ ; Π ; Φ 1 ⊢ V : A ,
( i i ) Γ , x : A ; Π ; Φ 2 ⊢ D : L , (ii)\ \Gamma, x : A \mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash D : \mathcal{L}, ( ii ) Γ , x : A ; Π ; Φ 2 ⊢ D : L , and
( i i i ) Φ = Φ 1 ⋈ Φ 2 , (iii)\ \Phi= \Phi_1 \bowtie\Phi_2, ( iii ) Φ = Φ 1 ⋈ Φ 2 ,
then Γ ; Π ; Φ ⊢ D [ V / x ] : L \Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash D[V/x] : \mathcal{L} Γ ; Π ; Φ ⊢ D [ V / x ] : L .
Proof. By mutual induction on the typing judgment ( i i ) (ii) ( ii ) alongside Lemmas A.18 and A.19.
We may now proceed to preservation. We first prove a separate theorem for E = P u r e E = \mathrm{Pure} E = Pure , which is then used in the proofs for bodies. Mutual induction between the theorems is therefore unnecessary.
Theorem A.21 (Preservation for ⇝ \rightsquigarrow ⇝ , pure). If
( i ) Γ ; Π ; Φ ⊢ M : A ! P u r e (i)\ \Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash M : A\mathbin{!}\mathrm{Pure} ( i ) Γ ; Π ; Φ ⊢ M : A ! Pure and
( i i ) H ; M ⇝ N ; H ′ (ii)\ \mathcal{H} \mathbin{;} M \rightsquigarrow N \mathbin{;} \mathcal{H}' ( ii ) H ; M ⇝ N ; H ′ (for any H \mathcal{H} H ),
then
( i ) Γ ; Π ; Φ ⊢ N : A ! P u r e (i)\ \Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash N : A\mathbin{!}\mathrm{Pure} ( i ) Γ ; Π ; Φ ⊢ N : A ! Pure and
( i i ) H ′ = H (ii)\ \mathcal{H}' = \mathcal{H} ( ii ) H ′ = H .
Proof. By induction on the derivation of the computation step judgment ( i i ) (ii) ( ii ) .
Case EC-Let: We have
\frac{\mathcal{H} \mathbin{;} M \rightsquigarrow M' \mathbin{;} \mathcal{H}'}{%
\mathcal{H} \mathbin{;} \mathop{\mathrm{let}} x = M \mathbin{\mathrm{in}} N \rightsquigarrow\mathop{\mathrm{let}} x = M' \mathbin{\mathrm{in}} N \mathbin{;} \mathcal{H}'}
\quad\mathrm{EC\mathchar`-Let}
\frac{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash M : A\mathbin{!}\mathrm{Pure}
\qquad
\Gamma, x : A \mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash N : B\mathbin{!}\mathrm{Pure}
}{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \bowtie\Phi_2 \vdash\mathop{\mathrm{let}} x = M \mathbin{\mathrm{in}} N : B\mathbin{!}\mathrm{Pure}
}
\quad\mathrm{TC\mathchar`-Let}
By inductive hypothesis on (1) and (2), we get both that H ′ = H \mathcal{H}' = \mathcal{H} H ′ = H (satisfying conclusion (ii)), and (4) that Γ ; Π ; Φ 1 ⊢ M ′ : A ! P u r e \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash M' : A\mathbin{!}\mathrm{Pure} Γ ; Π ; Φ 1 ⊢ M ′ : A ! Pure .
We derive conclusion (i) as follows:
\frac{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash M' : A\mathbin{!}\mathrm{Pure}
\qquad
\Gamma, x : A \mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash N : B\mathbin{!}\mathrm{Pure}
}{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \bowtie\Phi_2 \vdash\mathop{\mathrm{let}} x = M' \mathbin{\mathrm{in}} N : B\mathbin{!}\mathrm{Pure}
}
\quad\mathrm{TC\mathchar`-Let}
Case EC-Val: We have H \mathcal{H} H ; let x = val V x = \operatorname{val} V x = val V in M ⇝ M [ V / x ] M \leadsto M[V/x] M ⇝ M [ V / x ] ; H \mathcal{H} H (from which conclusion (ii) is immediate) and
Γ ; Π ; Φ 1 ⊢ V : A Γ ; Π ; Φ 1 ⊢ val V : A ! P u r e TV-Val \frac{\Gamma;\Pi;\Phi_1 \vdash V:A}{\Gamma;\Pi;\Phi_1 \vdash\operatorname{val} V:A\mathbin{!}\mathrm{Pure}}\quad\text{TV-Val} Γ ; Π ; Φ 1 ⊢ val V : A ! Pure Γ ; Π ; Φ 1 ⊢ V : A TV-Val
Γ , x : A ; Π ; Φ 2 ⊢ M : B ! P u r e Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = val V in M : B ! P u r e EC-Let \frac{\Gamma,x:A;\Pi;\Phi_2 \vdash M:B\mathbin{!}\mathrm{Pure}}{\Gamma;\Pi;\Phi_1\bowtie\Phi_2 \vdash\operatorname{let} x=\operatorname{val} V\operatorname{\ in\ }M:B\mathbin{!}\mathrm{Pure}}\quad\text{EC-Let} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = val V in M : B ! Pure Γ , x : A ; Π ; Φ 2 ⊢ M : B ! Pure EC-Let
Case EC-App: We have H \mathcal{H} H ; ( λ x . M ) V ⇝ M [ V / x ] (\lambda x.M)\ V \leadsto M[V/x] ( λ x . M ) V ⇝ M [ V / x ] ; H \mathcal{H} H (from which conclusion (ii) is immediate) and
Γ , x : A ; Π ; Φ 1 ⊢ M : B ! P u r e Γ ; Π ; Φ 1 ⊢ λ x . M : A → P u r e B TV-Lam \frac{\Gamma,x:A;\Pi;\Phi_1\vdash M:B\mathbin{!}\mathrm{Pure}}{\Gamma;\Pi;\Phi_1\vdash\lambda x.M:A\mathbin{\xrightarrow{\mathrm{Pure}}}B}\quad\text{TV-Lam} Γ ; Π ; Φ 1 ⊢ λ x . M : A Pure B Γ , x : A ; Π ; Φ 1 ⊢ M : B ! Pure TV-Lam
Γ ; Π ; Φ 2 ⊢ V : A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( λ x . M ) V : B ! P u r e TC-App \frac{\Gamma;\Pi;\Phi_2\vdash V:A}{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash(\lambda x.M)\ V:B\mathbin{!}\mathrm{Pure}}\quad\text{TC-App} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( λ x . M ) V : B ! Pure Γ ; Π ; Φ 2 ⊢ V : A TC-App
Case EC-IfT: We have H \mathcal{H} H ; if true then M M M else N ⇝ M N \leadsto M N ⇝ M ; H \mathcal{H} H (from which conclusion (ii) is immediate) and
Succ ( Φ 1 ) Γ ; Π ; Φ 1 ⊢ t r u e : B o o l TV-True \frac{\operatorname{Succ}(\Phi_1)}{\Gamma;\Pi;\Phi_1\vdash\mathrm{true}:\mathrm{Bool}}\quad\text{TV-True} Γ ; Π ; Φ 1 ⊢ true : Bool Succ ( Φ 1 ) TV-True
Γ ; Π ; Φ 2 ⊢ M : A ! P u r e Γ ; Π ; Φ 2 ⊢ N : A ! P u r e Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ if true then M else N : A ! P u r e TC-If \frac{\Gamma;\Pi;\Phi_2\vdash M:A\mathbin{!}\mathrm{Pure}\qquad\Gamma;\Pi;\Phi_2\vdash N:A\mathbin{!}\mathrm{Pure}}{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash\operatorname{if\ true\ then\ }M\operatorname{\ else\ }N:A\mathbin{!}\mathrm{Pure}}\quad\text{TC-If} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ if true then M else N : A ! Pure Γ ; Π ; Φ 2 ⊢ M : A ! Pure Γ ; Π ; Φ 2 ⊢ N : A ! Pure TC-If
Case EC-IfF: Analogous to the above case.
Case EC-Fst: We have H \mathcal{H} H ; fst ( V , W ) ⇝ val V \operatorname{fst}(V,W)\leadsto\operatorname{val} V fst ( V , W ) ⇝ val V ; H \mathcal{H} H (from which conclusion (ii) is immediate) and
Γ ; Π ; Φ 1 ⊢ V : A Γ ; Π ; Φ 2 ⊢ W : B Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B TV-Pair \frac{\Gamma;\Pi;\Phi_1\vdash V:A\qquad\Gamma;\Pi;\Phi_2\vdash W:B}{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash(V,W):A\times B}\quad\text{TV-Pair} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B Γ ; Π ; Φ 1 ⊢ V : A Γ ; Π ; Φ 2 ⊢ W : B TV-Pair
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ fst ( V , W ) : A ! P u r e TC-Fst \frac{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash(V,W):A\times B}{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash\operatorname{fst}(V,W):A\mathbin{!}\mathrm{Pure}}\quad\text{TC-Fst} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ fst ( V , W ) : A ! Pure Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B TC-Fst
By Lemma A.4 (unrestriction) on (2), we get (3) that Succ ( Φ 2 ) \operatorname{Succ}(\Phi_2) Succ ( Φ 2 ) .
By Lemma A.9 (Φ \Phi Φ -weakening) on (1) and (3), we get (4) that Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : A \Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash V:A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : A .
We derive conclusion (i) as follows:
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ val V : A ! P u r e TC-Val \frac{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash V:A}{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash\operatorname{val} V:A\mathbin{!}\mathrm{Pure}}\quad\text{TC-Val} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ val V : A ! Pure Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : A TC-Val
Case EC-Snd: Analogous to the above case.
Case EC-FdN: We have H \mathcal{H} H ; fold V 1 V_1 V 1 V 2 V_2 V 2 [ ] ⇝ [] \leadsto [ ] ⇝ val V 2 V_2 V 2 ; H \mathcal{H} H (from which conclusion (ii) is immediate) and
Γ ; Π ; Φ 1 ⊢ V 1 : A → P u r e B → P u r e B Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ fold V 1 V 2 [ ] : B ! P u r e Γ ; Π ; Φ 2 ⊢ V 2 : B Γ ; Π ; Φ 3 ⊢ [ ] : List A \begin{aligned}
&\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash V_1 : A \xrightarrow{\mathrm{Pure}} B \xrightarrow{\mathrm{Pure}} B}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \mathbin{\bowtie} \Phi_2 \mathbin{\bowtie} \Phi_3 \vdash\operatorname{fold} V_1\,V_2\,[] : B\mathbin{!}\mathrm{Pure}}
\quad
\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash V_2 : B}{}
\quad
\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_3 \vdash[] : \operatorname{List} A}{}
\end{aligned} Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ fold V 1 V 2 [ ] : B ! Pure Γ ; Π ; Φ 1 ⊢ V 1 : A Pure B Pure B Γ ; Π ; Φ 2 ⊢ V 2 : B Γ ; Π ; Φ 3 ⊢ [ ] : List A
By Lemma A.4 (unrestriction) on (1) and (3), we get (4) that Succ ( Φ 1 ) \operatorname{Succ}(\Phi_1) Succ ( Φ 1 ) and (5) that Succ ( Φ 3 ) \operatorname{Succ}(\Phi_3) Succ ( Φ 3 ) , respectively.
By Lemma A.9 (Φ \Phi Φ -weakening) on (2) using (4) and (5), we get (6) that Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ V 2 : B \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \mathbin{\bowtie} \Phi_2 \mathbin{\bowtie} \Phi_3 \vdash V_2 : B Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ V 2 : B .
We derive conclusion (i) as follows:
Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ V 2 : B Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ val V 2 : B ! P u r e \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \mathbin{\bowtie} \Phi_2 \mathbin{\bowtie} \Phi_3 \vdash V_2 : B}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \mathbin{\bowtie} \Phi_2 \mathbin{\bowtie} \Phi_3 \vdash\operatorname{val} V_2 : B\mathbin{!}\mathrm{Pure}} Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ val V 2 : B ! Pure Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ V 2 : B
Case EC-FdC: We have H \mathcal{H} H ; fold V 1 V_1 V 1 V 2 V_2 V 2 ( V h : : V t ) ⇝ V 1 V h ( fold V 1 V 2 V t ) (V_h :: V_t) \leadsto V_1\,V_h\,(\operatorname{fold} V_1\,V_2\,V_t) ( V h :: V t ) ⇝ V 1 V h ( fold V 1 V 2 V t ) ; H \mathcal{H} H , whose right-hand term desugars to let x = V 1 V h x = V_1\,V_h x = V 1 V h in let y = fold V 1 V 2 V t y = \operatorname{fold} V_1\,V_2\,V_t y = fold V 1 V 2 V t in x y x\,y x y . Conclusion (ii) is immediate, and we also have:
Γ ; Π ; Φ 3 ⊢ V h : A Γ ; Π ; Φ 4 ⊢ V t : List A Γ ; Π ; Φ 3 ⋈ Φ 4 ⊢ V h : : V t : List A Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⋈ Φ 4 ⊢ fold V 1 V 2 ( V h : : V t ) : B ! P u r e Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⋈ Φ 4 ⊢ fold V 1 V 2 ( V h : : V t ) : B ! P u r e \frac{
\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_3 \vdash V_h : A \qquad\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_4 \vdash V_t : \operatorname{List} A}
{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_3 \mathbin{\bowtie} \Phi_4 \vdash V_h :: V_t : \operatorname{List} A}
\qquad
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \mathbin{\bowtie} \Phi_2 \mathbin{\bowtie} \Phi_3 \mathbin{\bowtie} \Phi_4 \vdash\operatorname{fold} V_1\,V_2\,(V_h :: V_t) : B\mathbin{!}\mathrm{Pure}}
{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \mathbin{\bowtie} \Phi_2 \mathbin{\bowtie} \Phi_3 \mathbin{\bowtie} \Phi_4 \vdash\operatorname{fold} V_1\,V_2\,(V_h :: V_t) : B\mathbin{!}\mathrm{Pure}} Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⋈ Φ 4 ⊢ fold V 1 V 2 ( V h :: V t ) : B ! Pure Γ ; Π ; Φ 3 ⋈ Φ 4 ⊢ V h :: V t : List A Γ ; Π ; Φ 3 ⊢ V h : A Γ ; Π ; Φ 4 ⊢ V t : List A Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⋈ Φ 4 ⊢ fold V 1 V 2 ( V h :: V t ) : B ! Pure
where (1) and (2) are identical to the previous case.
By Lemma A.4 (unrestriction) on (1)–(4), we get that Succ ( Φ i ) \operatorname{Succ}(\Phi_i) Succ ( Φ i ) for i ∈ { 1 , 2 , 3 , 4 } i \in\{1,2,3,4\} i ∈ { 1 , 2 , 3 , 4 } . It follows (5) that Succ ( Φ ) \operatorname{Succ}(\Phi) Succ ( Φ ) , where Φ = ⋈ i = 1 4 Φ i \Phi= \mathbin{\bowtie}_{i=1}^{4} \Phi_i Φ = ⋈ i = 1 4 Φ i .
We derive conclusion (i) by way of intermediate derivations (6)–(8) as follows, using Φ \Phi Φ intuitionistically by (5) and weakening (1)–(4) appropriately:
Γ 6 ; Π ; Φ ⊢ x : B → P u r e B Γ 6 ; Π ; Φ ⊢ y : B Γ 6 ; Π ; Φ ⊢ x y : B ! P u r e \frac{\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi\vdash x : B \xrightarrow{\mathrm{Pure}} B
\qquad
\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi\vdash y : B}
{\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi\vdash x\,y : B\mathbin{!}\mathrm{Pure}} Γ 6 ; Π ; Φ ⊢ x y : B ! Pure Γ 6 ; Π ; Φ ⊢ x : B Pure B Γ 6 ; Π ; Φ ⊢ y : B
Γ 7 ; Π ; Φ ⊢ V 1 : A → P u r e B → P u r e B Γ 7 ; Π ; Φ ⊢ V 2 : B Γ 7 ; Π ; Φ ⊢ V t : List A Γ 7 ; Π ; Φ ⊢ fold V 1 V 2 V t : B ! P u r e Γ 6 ; Π ; Φ ⊢ x y : B ! P u r e Γ 8 ; Π ; Φ ⊢ let y = fold V 1 V 2 V t in ⋯ : B ! P u r e \frac{
\frac{\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi\vdash V_1 : A \xrightarrow{\mathrm{Pure}} B \xrightarrow{\mathrm{Pure}} B
\qquad
\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi\vdash V_2 : B
\qquad
\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi\vdash V_t : \operatorname{List} A}
{\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi\vdash\operatorname{fold} V_1\,V_2\,V_t : B\mathbin{!}\mathrm{Pure}}
\qquad
\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi\vdash x\,y : B\mathbin{!}\mathrm{Pure}}
{\Gamma_8 \mathbin{;} \Pi\mathbin{;} \Phi\vdash\operatorname{let} y = \operatorname{fold} V_1\,V_2\,V_t\ \operatorname{in}\ \cdots: B\mathbin{!}\mathrm{Pure}} Γ 8 ; Π ; Φ ⊢ let y = fold V 1 V 2 V t in ⋯ : B ! Pure Γ 7 ; Π ; Φ ⊢ fold V 1 V 2 V t : B ! Pure Γ 7 ; Π ; Φ ⊢ V 1 : A Pure B Pure B Γ 7 ; Π ; Φ ⊢ V 2 : B Γ 7 ; Π ; Φ ⊢ V t : List A Γ 6 ; Π ; Φ ⊢ x y : B ! Pure
[ ( 7 ) , Γ 7 = Γ 8 ] [(7),\ \Gamma_7 = \Gamma_8] [( 7 ) , Γ 7 = Γ 8 ] [ ( 6 ) , Γ 6 = Γ 8 , y : B ] [(6),\ \Gamma_6 = \Gamma_8,\ y : B] [( 6 ) , Γ 6 = Γ 8 , y : B ]
Γ ; Π ; Φ ⊢ V 1 : A → P u r e B → P u r e E Γ ; Π ; Φ ⊢ V h : A Γ ; Π ; Φ ⊢ V 1 V h : B → P u r e B ! P u r e \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash V_1 : A \xrightarrow{\mathrm{Pure}} B \xrightarrow{\mathrm{Pure}} E
\qquad
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash V_h : A}
{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash V_1\,V_h : B \xrightarrow{\mathrm{Pure}} B\mathbin{!}\mathrm{Pure}} Γ ; Π ; Φ ⊢ V 1 V h : B Pure B ! Pure Γ ; Π ; Φ ⊢ V 1 : A Pure B Pure E Γ ; Π ; Φ ⊢ V h : A
Γ ; Π ; Φ ⊢ V 1 V h : B → P u r e B ! P u r e Γ ; Π ; Φ ⊢ let x = V 1 V h in ⋯ : B ! P u r e \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash V_1\,V_h : B \xrightarrow{\mathrm{Pure}} B\mathbin{!}\mathrm{Pure}}
{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash\operatorname{let} x = V_1\,V_h\ \operatorname{in}\ \cdots: B\mathbin{!}\mathrm{Pure}} Γ ; Π ; Φ ⊢ let x = V 1 V h in ⋯ : B ! Pure Γ ; Π ; Φ ⊢ V 1 V h : B Pure B ! Pure
[ ( 8 ) , Γ 8 = Γ , x : B → P u r e B ] [(8),\ \Gamma_8 = \Gamma,\ x : B \xrightarrow{\mathrm{Pure}} B] [( 8 ) , Γ 8 = Γ , x : B Pure B ]
All other cases are untypeable with the Pure effect, and so the theorem holds vacuously. □ \square □
Theorem A.22 (Preservation for ⇝ p I n i t \leadsto^{\mathrm{Init}}_{p} ⇝ p Init ). If
(i) Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L , (ii) L ∩ Π [ p ] = ∅ , (iii) p ∉ dom ( Φ H ⋈ Φ D ) , and (iv) H ; D ⇝ p I n i t D ′ ; H ′ , \begin{aligned}
\text{(i)}\quad&\Gamma; \Pi; \Phi_H ; \Phi_D \vdash\mathcal{H} ; D : \mathcal{L},\\
\text{(ii)}\quad&\mathcal{L} \cap\Pi[p] = \emptyset,\\
\text{(iii)}\quad&p \notin\operatorname{dom}(\Phi_H \bowtie\Phi_D),\text{ and}\\
\text{(iv)}\quad&\mathcal{H} ; D \leadsto^{\mathrm{Init}}_{p} D' ; \mathcal{H}',
\end{aligned} (i) (ii) (iii) (iv) Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L , L ∩ Π [ p ] = ∅ , p ∈ / dom ( Φ H ⋈ Φ D ) , and H ; D ⇝ p Init D ′ ; H ′ , then for some Φ H ′ \Phi'_H Φ H ′ and Π ′ ⊒ p : I n i t Π \Pi' \sqsupseteq_{p:\mathrm{Init}} \Pi Π ′ ⊒ p : Init Π , we have
(i) Γ ; Π ′ ; Φ H ′ ; Φ D ⊢ H ′ ; D ′ : L ′ , (ii) Φ H ′ ⋈ Φ D = Φ H ⋈ Φ D , and (iii) L ′ ⊎ Π ′ [ p ] = L ⊎ Π [ p ] . \begin{aligned}
\text{(i)}\quad&\Gamma; \Pi' ; \Phi'_H ; \Phi_D \vdash\mathcal{H}' ; D' : \mathcal{L}',\\
\text{(ii)}\quad&\Phi'_H \bowtie\Phi_D = \Phi_H \bowtie\Phi_D,\text{ and}\\
\text{(iii)}\quad&\mathcal{L}' \uplus\Pi'[p] = \mathcal{L} \uplus\Pi[p].
\end{aligned} (i) (ii) (iii) Γ ; Π ′ ; Φ H ′ ; Φ D ⊢ H ′ ; D ′ : L ′ , Φ H ′ ⋈ Φ D = Φ H ⋈ Φ D , and L ′ ⊎ Π ′ [ p ] = L ⊎ Π [ p ] .
Proof. By definition of premise (i), we have subpremises
(i-a) Γ ; Π ; Φ D ⊢ D : L \text{(i-a)}\quad\Gamma; \Pi; \Phi_D \vdash D : \mathcal{L} (i-a) Γ ; Π ; Φ D ⊢ D : L
and
(i-b) Γ ; Π ; Φ H ⊨ H . \text{(i-b)}\quad\Gamma; \Pi; \Phi_H \models\mathcal{H}. (i-b) Γ ; Π ; Φ H ⊨ H .
Likewise, to show conclusion (i) it suffices to pick some Π ′ ⊒ p : I n i t Π \Pi' \sqsupseteq_{p:\mathrm{Init}} \Pi Π ′ ⊒ p : Init Π and Φ H ′ \Phi'_H Φ H ′ such that conclusion (ii) holds and:
(i-a) Γ ; Π ′ ; Φ D ⊢ D ′ : L ′ \text{(i-a)}\quad\Gamma; \Pi' ; \Phi_D \vdash D' : \mathcal{L}' (i-a) Γ ; Π ′ ; Φ D ⊢ D ′ : L ′
and
(i-b) Γ ; Π ′ ; Φ H ′ ⊨ H ′ . \text{(i-b)}\quad\Gamma; \Pi' ; \Phi'_H \models\mathcal{H}'. (i-b) Γ ; Π ′ ; Φ H ′ ⊨ H ′ .
Unless otherwise mentioned, we choose Φ H ′ = Φ H \Phi'_H = \Phi_H Φ H ′ = Φ H such that conclusion (ii) is trivial, and we choose Π ′ = Π \Pi' = \Pi Π ′ = Π such that conclusion (iii) is trivial by premise (ii) when L ′ = L \mathcal{L}' = \mathcal{L} L ′ = L . Under both of these choices, to show conclusion (i-b), by premise (i-b) it suffices to show that H ′ = H \mathcal{H}' = \mathcal{H} H ′ = H .
We proceed by induction on the derivation of the body step judgment (iv).
Case EB-Let: We have
H ; M ⇝ N ; H ′ H ; let x = M in D ⇝ p I n i t let x = N in D ; H ′ E B - L e t \frac{\mathcal{H} ; M \leadsto N ; \mathcal{H}'}{\mathcal{H} ; \operatorname{let} x = M\ \operatorname{in}\ D \leadsto^{\mathrm{Init}}_{p} \operatorname{let} x = N\ \operatorname{in}\ D ; \mathcal{H}'}\ \mathrm{EB\text{-}Let} H ; let x = M in D ⇝ p Init let x = N in D ; H ′ H ; M ⇝ N ; H ′ EB - Let
Γ ; Π ; Φ 1 ⊢ M : A ! P u r e Γ , x : A ; Π ; Φ 2 ⊢ D : L Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in D : L T B - L e t \frac{\Gamma; \Pi; \Phi_1 \vdash M : A\ !\ \mathrm{Pure}
\qquad
\Gamma, x : A ; \Pi; \Phi_2 \vdash D : \mathcal{L}}
{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\operatorname{let} x = M\ \operatorname{in}\ D : \mathcal{L}}\ \mathrm{TB\text{-}Let} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in D : L Γ ; Π ; Φ 1 ⊢ M : A ! Pure Γ , x : A ; Π ; Φ 2 ⊢ D : L TB - Let
By Theorem A.21 (pure preservation) on (1) and (2), we get that H ′ = H \mathcal{H}' = \mathcal{H} H ′ = H , satisfying conclusion (i-b), and (4) that Γ ; Π ; Φ 1 ⊢ N : A ! P u r e \Gamma; \Pi; \Phi_1 \vdash N : A\ !\ \mathrm{Pure} Γ ; Π ; Φ 1 ⊢ N : A ! Pure .
We derive conclusion (i-a) as follows:
Γ ; Π ; Φ 1 ⊢ N : A ! P u r e Γ , x : A ; Π ; Φ 2 ⊢ D : L Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = N in D : L T B - L e t \frac{\Gamma; \Pi; \Phi_1 \vdash N : A\ !\ \mathrm{Pure}
\qquad
\Gamma, x : A ; \Pi; \Phi_2 \vdash D : \mathcal{L}}
{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\operatorname{let} x = N\ \operatorname{in}\ D : \mathcal{L}}\ \mathrm{TB\text{-}Let} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = N in D : L Γ ; Π ; Φ 1 ⊢ N : A ! Pure Γ , x : A ; Π ; Φ 2 ⊢ D : L TB - Let
Case EB-Val: We have H ; let x = val V in D ⇝ p I n i t D [ V / x ] ; H \mathcal{H} ; \operatorname{let} x = \operatorname{val} V\ \operatorname{in}\ D \leadsto^{\mathrm{Init}}_{p} D[V/x] ; \mathcal{H} H ; let x = val V in D ⇝ p Init D [ V / x ] ; H (from which conclusion (i-b) is immediate) and
Γ ; Π ; Φ 1 ⊢ V : A Γ ; Π ; Φ 1 ⊢ val V : A ! P u r e T C - V a l \frac{\Gamma; \Pi; \Phi_1 \vdash V : A}
{\Gamma; \Pi; \Phi_1 \vdash\operatorname{val} V : A\ !\ \mathrm{Pure}}\ \mathrm{TC\text{-}Val} Γ ; Π ; Φ 1 ⊢ val V : A ! Pure Γ ; Π ; Φ 1 ⊢ V : A TC - Val
Γ , x : A ; Π ; Φ 2 ⊢ D : L Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = val V in D : L T B - L e t \frac{\Gamma, x : A ; \Pi; \Phi_2 \vdash D : \mathcal{L}}
{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\operatorname{let} x = \operatorname{val} V\ \operatorname{in}\ D : \mathcal{L}}\ \mathrm{TB\text{-}Let} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = val V in D : L Γ , x : A ; Π ; Φ 2 ⊢ D : L TB - Let
Case EB-StateI: We have H \mathcal{H} H ; let x , x s e t = useState ℓ V x, x_{\mathrm{set}} = \operatorname{useState}^{\ell}\ V x , x set = useState ℓ V in D ⇝ p I n i t D [ V / x , x s e t ℓ / x s e t ] D \mathrel{\leadsto_{p}^{\mathrm{Init}}} D[V/x,x_{\mathrm{set}}^{\ell}/x_{\mathrm{set}}] D ⇝ p Init D [ V / x , x set ℓ / x set ] ; H ′ \mathcal{H}' H ′ , where H ′ = H ∣ H [ p ] . st [ ℓ ] ↦ V \mathcal{H}' = \mathcal{H}\mid\mathcal{H}[p].\operatorname{st}[\ell]\mapsto V H ′ = H ∣ H [ p ] . st [ ℓ ] ↦ V , and
Γ ; Π ; Φ 1 ⊢ V : A Γ , x : A , x s e t : A → M u t 1 ; Π ; Φ 2 ⊢ D : L ℓ ∉ dom ( L ) \begin{aligned}
\Gamma;\Pi;\Phi_{1} &\vdash V:A \\
\Gamma,x:A,x_{\mathrm{set}}:A &\xrightarrow{\mathrm{Mut}} 1;\Pi;\Phi_{2}\vdash D:\mathcal{L} \\
\ell&\notin\operatorname{dom}(\mathcal{L})
\end{aligned} Γ ; Π ; Φ 1 Γ , x : A , x set : A ℓ ⊢ V : A Mut 1 ; Π ; Φ 2 ⊢ D : L ∈ / dom ( L )
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x s e t = useState ℓ V in D : L , ℓ : A \Gamma;\Pi;\Phi_{1}\mathbin{\bowtie}\Phi_{2}\vdash\operatorname{let}\ x,x_{\mathrm{set}}=\operatorname{useState}^{\ell}\ V\operatorname{\ in\ }D:\mathcal{L},\ell:A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x set = useState ℓ V in D : L , ℓ : A
Choose Π ′ = Π ∣ Π [ p ] [ ℓ ] = A \Pi'=\Pi\mathbin{\mid}\Pi[p][\ell]=A Π ′ = Π ∣ Π [ p ] [ ℓ ] = A . By definition, (4) Π ⊑ p : I n i t Π ′ \Pi\sqsubseteq_{p:\mathrm{Init}}\Pi' Π ⊑ p : Init Π ′ .
Choose Φ H ′ = Φ H ⋈ Φ 1 \Phi'_{\mathcal{H}}=\Phi_{\mathcal{H}}\mathbin{\bowtie}\Phi_{1} Φ H ′ = Φ H ⋈ Φ 1 .
Since ( Φ 1 ⋈ Φ 2 ) ⋈ Φ H (\Phi_{1}\mathbin{\bowtie}\Phi_{2})\mathbin{\bowtie}\Phi_{\mathcal{H}} ( Φ 1 ⋈ Φ 2 ) ⋈ Φ H is given as defined, we know Φ 1 ⋈ Φ H \Phi_{1}\mathbin{\bowtie}\Phi_{\mathcal{H}} Φ 1 ⋈ Φ H is defined.
To show conclusion ( i i ) (ii) ( ii ) , we want to show ( Φ 1 ⋈ Φ 2 ) ⋈ ( Φ H ⋈ Φ 1 ) = ( Φ 1 ⋈ Φ 2 ) ⋈ Φ H (\Phi_{1}\mathbin{\bowtie}\Phi_{2})\mathbin{\bowtie}(\Phi_{\mathcal{H}}\mathbin{\bowtie}\Phi_{1})=(\Phi_{1}\mathbin{\bowtie}\Phi_{2})\mathbin{\bowtie}\Phi_{\mathcal{H}} ( Φ 1 ⋈ Φ 2 ) ⋈ ( Φ H ⋈ Φ 1 ) = ( Φ 1 ⋈ Φ 2 ) ⋈ Φ H .
These are equal by associativity/commutativity of ⋈ \bowtie ⋈ and by Lemma A.4 (unrestriction) on (1), meaning Φ 1 ⋈ Φ 1 = Φ 1 \Phi_{1}\mathbin{\bowtie}\Phi_{1}=\Phi_{1} Φ 1 ⋈ Φ 1 = Φ 1 .
We show conclusion (i-a) as follows:
By premise ( i i i ) (iii) ( iii ) , we have (5) that p : I n i t ⋈ Φ 1 p:\mathrm{Init}\mathbin{\bowtie}\Phi_{1} p : Init ⋈ Φ 1 is defined and (6) that p : I n i t ⋈ Φ 2 p:\mathrm{Init}\mathbin{\bowtie}\Phi_{2} p : Init ⋈ Φ 2 is defined.
By Lemma A.1 (Π \Pi Π -weakening) on (1), (4), and (5), we get (7) that Γ ; Π ′ ; Φ 1 ⊢ V : A \Gamma;\Pi';\Phi_{1}\vdash V:A Γ ; Π ′ ; Φ 1 ⊢ V : A .
By Lemma A.3 (Π \Pi Π -weakening) on (2), (4), and (6), we get (8) that Γ , x : A , x s e t : A → M u t 1 ; Π ′ ; Φ 2 ⊢ D : L \Gamma,x:A,x_{\mathrm{set}}:A\xrightarrow{\mathrm{Mut}}1;\Pi';\Phi_{2}\vdash D:\mathcal{L} Γ , x : A , x set : A Mut 1 ; Π ′ ; Φ 2 ⊢ D : L .
Since ℓ : A ∈ Π ′ [ p ] \ell:A\in\Pi'[p] ℓ : A ∈ Π ′ [ p ] by definition and Succ ( ∅ ) \operatorname{Succ}(\varnothing) Succ ( ∅ ) trivially, we derive the setter type as follows:
ℓ : A ∈ Π ′ [ p ] Succ ( ∅ ) \ell:A\in\Pi'[p]\qquad\operatorname{Succ}(\varnothing) ℓ : A ∈ Π ′ [ p ] Succ ( ∅ )
Γ ; Π ′ ; ∅ ⊢ set p ℓ : A → M u t 1 \Gamma;\Pi';\varnothing\vdash\operatorname{set}^{\ell}_{p}:A\xrightarrow{\mathrm{Mut}}1 Γ ; Π ′ ; ∅ ⊢ set p ℓ : A Mut 1
We apply Lemma A.20 (substitution) twice to (8), using (7) and (9), to get that Γ ; Π ′ ; Φ 1 ⋈ Φ 2 ⊢ D [ V / x , x s e t ℓ / x s e t ] : L \Gamma;\Pi';\Phi_{1}\mathbin{\bowtie}\Phi_{2}\vdash D[V/x,x_{\mathrm{set}}^{\ell}/x_{\mathrm{set}}]:\mathcal{L} Γ ; Π ′ ; Φ 1 ⋈ Φ 2 ⊢ D [ V / x , x set ℓ / x set ] : L , i.e. conclusion (i-a) holds.
Case EB-StateS: Impossible, since the step rule requires that ϕ = Succ \phi=\operatorname{Succ} ϕ = Succ .
Theorem A.23 (Preservation for ⇝ p S u c c \mathrel{\leadsto_{p}^{\mathrm{Succ}}} ⇝ p Succ ). If
Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L \Gamma;\Pi;\Phi_{\mathcal{H}};\Phi_{D}\vdash\mathcal{H};D:\mathcal{L} Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L ,
L ⊆ Π [ p ] \mathcal{L}\subseteq\Pi[p] L ⊆ Π [ p ] , and
(iii) H ; D ⇝ S u c c p D ′ ; H ′ \mathcal{H};D \mathrel{\overset{\mathrm{Succ}}{\leadsto}_{p}}D';\mathcal{H}' H ; D ⇝ Succ p D ′ ; H ′ , then for some Φ D ′ \Phi_{\mathcal{D}}' Φ D ′ , we have (i) Γ ; Π ; Φ D ′ ⊢ D ′ : L ′ \Gamma;\Pi;\Phi_{\mathcal{D}}'\vdash D':\mathcal{L}' Γ ; Π ; Φ D ′ ⊢ D ′ : L ′ , (ii) Φ H ⋈ Φ D ′ = Φ H ⋈ Φ D \Phi_{\mathcal{H}}\bowtie\Phi_{\mathcal{D}}'=\Phi_{\mathcal{H}}\bowtie\Phi_{\mathcal{D}} Φ H ⋈ Φ D ′ = Φ H ⋈ Φ D , (iii) H ′ = H \mathcal{H}'=\mathcal{H} H ′ = H , and (iv) L ′ ⊆ L \mathcal{L}'\subseteq\mathcal{L} L ′ ⊆ L .
Proof. By induction on the derivation of the body step judgment (iii).
Cases EB-Let, and EB-Val are shown analogously to Theorem A.22 (preservation for ⇝ p I n i t \leadsto^{\mathrm{Init}}_{p} ⇝ p Init ). Choosing Φ D ′ = Φ D \Phi_{\mathcal{D}}'=\Phi_{\mathcal{D}} Φ D ′ = Φ D trivializes conclusion (ii), and we always get L ′ = L \mathcal{L}'=\mathcal{L} L ′ = L to satisfy conclusion (iv).
Case EB-StateI: Impossible, since the step rule requires that ϕ = I n i t \phi=\mathrm{Init} ϕ = Init .
Case EB-StateS: We have H ; l e t x , x s e t = u s e S t a t e ℓ V i n D ⇝ S u c c p D [ W / x , s e t p ℓ / x s e t ] ; H \mathcal{H};\mathop{\mathrm{let}} x,x_{\mathrm{set}}=\mathrm{useState}^{\ell}\ V\mathop{\mathrm{in}}D\mathrel{\overset{\mathrm{Succ}}{\leadsto}_{p}}D[W/x,\mathrm{set}^{\ell}_{p}/x_{\mathrm{set}}];\mathcal{H} H ; let x , x set = useState ℓ V in D ⇝ Succ p D [ W / x , set p ℓ / x set ] ; H (from which conclusion (iii) is immediate), where W = H [ p ] . s t [ ℓ ] W=\mathcal{H}[p].\mathrm{st}[\ell] W = H [ p ] . st [ ℓ ] , and
Γ ; Π ; Φ 1 ⊢ V : A Γ , x : A , x s e t : A ⟶ M u t 1 ; Π ; Φ 2 ⊢ D : L ℓ ∉ dom ( L ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ l e t x , x s e t = u s e S t a t e ℓ V i n D : L , ℓ : A \frac{\Gamma;\Pi;\Phi_{1}\vdash V:A \qquad\Gamma,x:A,x_{\mathrm{set}}:A\mathrel{\overset{\mathrm{Mut}}{\longrightarrow}}1;\Pi;\Phi_{2}\vdash D:\mathcal{L} \qquad\ell\notin\operatorname{dom}(\mathcal{L})}{\Gamma;\Pi;\Phi_{1}\bowtie\Phi_{2}\vdash\mathop{\mathrm{let}}x,x_{\mathrm{set}}=\mathrm{useState}^{\ell}\ V\mathop{\mathrm{in}}D:\mathcal{L},\ell:A} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x set = useState ℓ V in D : L , ℓ : A Γ ; Π ; Φ 1 ⊢ V : A Γ , x : A , x set : A ⟶ Mut 1 ; Π ; Φ 2 ⊢ D : L ℓ ∈ / dom ( L )
• By premise (ii), we know L , ℓ : A ⊆ Π [ p ] \mathcal{L},\ell:A\subseteq\Pi[p] L , ℓ : A ⊆ Π [ p ] , i.e. (3) Π [ p ] [ ℓ ] = A \Pi[p][\ell]=A Π [ p ] [ ℓ ] = A .
• We derive the setter type as follows (noting S u c c ( ∅ ) \mathrm{Succ}(\varnothing) Succ ( ∅ ) holds trivially):
ℓ : A ∈ Π [ p ] Γ ; Π ; ∅ ⊢ s e t p ℓ : A ⟶ M u t 1 \frac{\ell:A\in\Pi[p]}{\Gamma;\Pi;\varnothing\vdash\mathrm{set}^{\ell}_{p}:A\mathrel{\overset{\mathrm{Mut}}{\longrightarrow}}1} Γ ; Π ; ∅ ⊢ set p ℓ : A ⟶ Mut 1 ℓ : A ∈ Π [ p ]
• By premise (i-b), we have that Γ ; Π ; Φ W ⊢ W : Π [ p ] [ ℓ ] \Gamma;\Pi;\Phi_{W}\vdash W:\Pi[p][\ell] Γ ; Π ; Φ W ⊢ W : Π [ p ] [ ℓ ] for some Φ 3 \Phi_{3} Φ 3 with Φ H = Φ W ⋈ Φ H ′ \Phi_{\mathcal{H}}=\Phi_{W}\bowtie\Phi_{\mathcal{H}}' Φ H = Φ W ⋈ Φ H ′ . By (3), this is equivalent to (5) that Γ ; Π ; Φ W ⊢ W : A \Gamma;\Pi;\Phi_{W}\vdash W:A Γ ; Π ; Φ W ⊢ W : A .
• Choose Φ D ′ = Φ D ⋈ Φ W \Phi_{\mathcal{D}}'=\Phi_{\mathcal{D}}\bowtie\Phi_{W} Φ D ′ = Φ D ⋈ Φ W . We are given that Φ D ⋈ ( Φ W ⋈ Φ H ′ ) \Phi_{\mathcal{D}}\bowtie(\Phi_{W}\bowtie\Phi_{\mathcal{H}}') Φ D ⋈ ( Φ W ⋈ Φ H ′ ) is defined, so Φ D ⋈ Φ W \Phi_{\mathcal{D}}\bowtie\Phi_{W} Φ D ⋈ Φ W is also defined.
• By A.4 (unrestriction) on (5), we have S u c c ( Φ W ) \mathrm{Succ}(\Phi_{W}) Succ ( Φ W ) . It follows that ( Φ D ⋈ Φ W ) ⋈ ( Φ W ⋈ Φ H ′ ) = Φ D ⋈ ( Φ W ⋈ Φ H ′ ) (\Phi_{\mathcal{D}}\bowtie\Phi_{W})\bowtie(\Phi_{W}\bowtie\Phi_{\mathcal{H}}')=\Phi_{\mathcal{D}}\bowtie(\Phi_{W}\bowtie\Phi_{\mathcal{H}}') ( Φ D ⋈ Φ W ) ⋈ ( Φ W ⋈ Φ H ′ ) = Φ D ⋈ ( Φ W ⋈ Φ H ′ ) , satisfying conclusion (ii).
• Lemma A.4 (unrestriction) on (1) gives that S u c c ( Φ 1 ) \mathrm{Succ}(\Phi_{1}) Succ ( Φ 1 ) . We then apply Lemma A.11 (Φ \Phi Φ -weakening) to (2), getting (6) Γ , x : A , x s e t : A ⟶ M u t 1 ; Π ; Φ 1 ⋈ Φ 2 ⊢ D [ W / x , s e t p ℓ / x s e t ] : L \Gamma,x:A,x_{\mathrm{set}}:A\mathrel{\overset{\mathrm{Mut}}{\longrightarrow}}1;\Pi;\Phi_{1}\bowtie\Phi_{2}\vdash D[W/x,\mathrm{set}^{\ell}_{p}/x_{\mathrm{set}}]:\mathcal{L} Γ , x : A , x set : A ⟶ Mut 1 ; Π ; Φ 1 ⋈ Φ 2 ⊢ D [ W / x , set p ℓ / x set ] : L .
• We apply Lemma A.20 (substitution) twice to (6), using (4) and (5), to obtain that Γ ; Π ; Φ D ′ ⊢ D [ W / x , s e t p ℓ / x s e t ] : L \Gamma;\Pi;\Phi_{\mathcal{D}}'\vdash D[W/x,\mathrm{set}^{\ell}_{p}/x_{\mathrm{set}}]:\mathcal{L} Γ ; Π ; Φ D ′ ⊢ D [ W / x , set p ℓ / x set ] : L , satisfying conclusion (i).
• Conclusion (iv) is obvious, and we are done.
Theorem A.24 (Preservation for ⇝ \leadsto ⇝ , impure). If
(i) Γ ; Π ; Φ H ; Φ M ⊢ H ; M : A ! M u t \Gamma;\Pi;\Phi_{\mathcal{H}};\Phi_{\mathcal{M}}\vdash\mathcal{H};M:A!\mathrm{Mut} Γ ; Π ; Φ H ; Φ M ⊢ H ; M : A ! Mut and
(ii) H ; M ⇝ N ; H ′ \mathcal{H};M\leadsto N;\mathcal{H}' H ; M ⇝ N ; H ′ ,
then for some Φ N \Phi_{N} Φ N and Φ H ′ \Phi_{\mathcal{H}}' Φ H ′ such that Φ N ⋈ Φ H ′ ⪰ f r e s h Φ M ⋈ Φ H \Phi_{N}\bowtie\Phi_{\mathcal{H}}'\succeq_{\mathrm{fresh}}\Phi_{\mathcal{M}}\bowtie\Phi_{\mathcal{H}} Φ N ⋈ Φ H ′ ⪰ fresh Φ M ⋈ Φ H and Π ′ ⪰ Φ N ⋈ Φ H ′ Π \Pi'\succeq_{\Phi_{N}\bowtie\Phi_{\mathcal{H}}'}\Pi Π ′ ⪰ Φ N ⋈ Φ H ′ Π , we have Γ ; Π ′ ; Φ H ′ ; Φ N ⊢ H ; N : A ! M u t \Gamma;\Pi';\Phi_{\mathcal{H}}';\Phi_{N}\vdash\mathcal{H};N:A!\mathrm{Mut} Γ ; Π ′ ; Φ H ′ ; Φ N ⊢ H ; N : A ! Mut .
Proof. By definition of premise (i), we have subpremises
(i-a) Γ ; Π ; Φ M ⊢ M : A ! M u t \Gamma;\Pi;\Phi_{\mathcal{M}}\vdash M:A!\mathrm{Mut} Γ ; Π ; Φ M ⊢ M : A ! Mut and
(i-b) Γ ; Π ; Φ H ⊢ H \Gamma;\Pi;\Phi_{\mathcal{H}}\vdash\mathcal{H} Γ ; Π ; Φ H ⊢ H .
Likewise, to show the conclusion, it suffices to pick some Φ N \Phi_{N} Φ N , Φ H ′ \Phi_{\mathcal{H}}' Φ H ′ , and Π ′ \Pi' Π ′ such that (i) Γ ; Π ′ ; Φ N ⊢ N : A ! M u t \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_N \vdash N : A \mathbin{!} \mathrm{Mut} Γ ; Π ′ ; Φ N ⊢ N : A ! Mut , (ii) Γ ; Π ′ ; Φ H ′ ⊨ H ′ \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi'_H \models H' Γ ; Π ′ ; Φ H ′ ⊨ H ′ , (iii) Φ M ⋈ Φ H ⊑ f r e s h Φ N ⋈ Φ H ′ \Phi_M \mathbin{\bowtie} \Phi_H \sqsubseteq_{\mathrm{fresh}} \Phi_N \mathbin{\bowtie} \Phi'_H Φ M ⋈ Φ H ⊑ fresh Φ N ⋈ Φ H ′ , and (iv) Π ⊑ Φ N ⋈ Φ H ′ Π ′ \Pi\sqsubseteq_{\Phi_N\bowtie\Phi'_H} \Pi' Π ⊑ Φ N ⋈ Φ H ′ Π ′ .
Unless otherwise mentioned, we choose Φ N = Φ M \Phi_N = \Phi_M Φ N = Φ M , Φ H ′ = Φ H \Phi'_H = \Phi_H Φ H ′ = Φ H , and Π ′ = Π \Pi' = \Pi Π ′ = Π , such that conclusions (iii)-(iv) are trivial and (ii) is trivial by premise (i-b) when H ′ = H H' = H H ′ = H .
We proceed by induction on the derivation of the computation step judgment (ii).
Case EC-Let: We have
H ; M ⇝ M ′ ; H ′ H ; let x = M in N ⇝ let x = M ′ in N ; H ′ \frac{\mathcal{H} \mathbin{;} M \leadsto M' \mathbin{;} \mathcal{H}'}{\mathcal{H} \mathbin{;} \operatorname{let} x = M \operatorname{in} N \leadsto\operatorname{let} x = M' \operatorname{in} N \mathbin{;} \mathcal{H}'} H ; let x = M in N ⇝ let x = M ′ in N ; H ′ H ; M ⇝ M ′ ; H ′
Γ ; Π ; Φ 1 ⊢ M : A ! M u t Γ , x : A ; Π ; Φ 2 ⊢ N : B ! M u t Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in N : B ! M u t \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash M : A \mathbin{!} \mathrm{Mut} \qquad\Gamma,x:A \mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash N : B \mathbin{!} \mathrm{Mut}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \bowtie\Phi_2 \vdash\operatorname{let} x = M \operatorname{in} N : B \mathbin{!} \mathrm{Mut}} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in N : B ! Mut Γ ; Π ; Φ 1 ⊢ M : A ! Mut Γ , x : A ; Π ; Φ 2 ⊢ N : B ! Mut
By inductive hypothesis on (1), (2), and premise (i-b), we get some Φ 1 ′ \Phi'_1 Φ 1 ′ , Φ H ′ \Phi'_H Φ H ′ , and Π ′ \Pi' Π ′ such that: (4) Γ ; Π ′ ; Φ 1 ′ ⊢ M ′ : A ! M u t \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi'_1 \vdash M' : A \mathbin{!} \mathrm{Mut} Γ ; Π ′ ; Φ 1 ′ ⊢ M ′ : A ! Mut , (5) Γ ; Π ′ ; Φ H ′ ⊨ H ′ \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi'_H \models H' Γ ; Π ′ ; Φ H ′ ⊨ H ′ , (6) Φ 1 ⋈ Φ H ⊑ f r e s h Φ 1 ′ ⋈ Φ H ′ \Phi_1 \bowtie\Phi_H \sqsubseteq_{\mathrm{fresh}} \Phi'_1 \bowtie\Phi'_H Φ 1 ⋈ Φ H ⊑ fresh Φ 1 ′ ⋈ Φ H ′ , and (7) Π ⊑ Φ 1 ′ ⋈ Φ H ′ Π ′ \Pi\sqsubseteq_{\Phi'_1\bowtie\Phi'_H} \Pi' Π ⊑ Φ 1 ′ ⋈ Φ H ′ Π ′ .
Choose Φ N = Φ 1 ′ ⋈ Φ 2 \Phi_N = \Phi'_1 \bowtie\Phi_2 Φ N = Φ 1 ′ ⋈ Φ 2 and this Φ H ′ \Phi'_H Φ H ′ as our own.
By Lemma 4.5 (fresh Φ \Phi Φ -extension) using (6) and extending by Φ 2 \Phi_2 Φ 2 , we get that Φ N ⋈ Φ H ′ \Phi_N \bowtie\Phi'_H Φ N ⋈ Φ H ′ is defined and Φ M ⋈ Φ H ⊑ f r e s h Φ N ⋈ Φ H ′ \Phi_M \bowtie\Phi_H \sqsubseteq_{\mathrm{fresh}} \Phi_N \bowtie\Phi'_H Φ M ⋈ Φ H ⊑ fresh Φ N ⋈ Φ H ′ , satisfying conclusion (iii).
Choose this Π ′ \Pi' Π ′ as our own. By Lemma A.17 (Π \Pi Π -order preservation) using (7) and extending by Φ 2 \Phi_2 Φ 2 , we get that Π ⊑ Φ N ⋈ Φ H ′ Π ′ \Pi\sqsubseteq_{\Phi_N\bowtie\Phi'_H} \Pi' Π ⊑ Φ N ⋈ Φ H ′ Π ′ .
(5) gives us conclusion (ii).
By Lemma A.2 (Π \Pi Π -weakening) on (3) using (7) and the fact that Φ N ⋈ Φ H \Phi_N \bowtie\Phi_H Φ N ⋈ Φ H is defined, we get (8) that Γ , x : A ; Π ′ ; Φ 2 ⊢ N : B ! P u r e \Gamma,x:A \mathbin{;} \Pi' \mathbin{;} \Phi_2 \vdash N : B \mathbin{!} \mathrm{Pure} Γ , x : A ; Π ′ ; Φ 2 ⊢ N : B ! Pure .
We derive conclusion (i) as follows:
Γ ; Π ′ ; Φ 1 ′ ⊢ M ′ : A ! P u r e Γ , x : A ; Π ′ ; Φ 2 ⊢ N : B ! P u r e Γ ; Π ′ ; Φ 1 ′ ⋈ Φ 2 ⊢ let x = M ′ in N : B ! P u r e \frac{\Gamma\mathbin{;} \Pi' \mathbin{;} \Phi'_1 \vdash M' : A \mathbin{!} \mathrm{Pure}
\qquad
\Gamma,x:A \mathbin{;} \Pi' \mathbin{;} \Phi_2 \vdash N : B \mathbin{!} \mathrm{Pure}}
{\Gamma\mathbin{;} \Pi' \mathbin{;} \Phi'_1 \bowtie\Phi_2 \vdash\operatorname{let} x = M' \operatorname{in} N : B \mathbin{!} \mathrm{Pure}} Γ ; Π ′ ; Φ 1 ′ ⋈ Φ 2 ⊢ let x = M ′ in N : B ! Pure Γ ; Π ′ ; Φ 1 ′ ⊢ M ′ : A ! Pure Γ , x : A ; Π ′ ; Φ 2 ⊢ N : B ! Pure
Cases EC-Val, EC-App, EC-IfT, EC-IfF, EC-Fst, EC-Snd, EC-FdN, and EC-FdC are all shown analogously to Theorem A.21 (pure preservation). The main difference is that rule TC-Sub now appears in typing derivations, but this ultimately has no effect on what we can derive. (These cases are also spelled out in 6.5)
Case EC-AppSet: We have H ; set p ℓ V ⇝ val ( ) ; H ′ \mathcal{H} \mathbin{;} \operatorname{set}^{\ell}_{p}\ V \leadsto\operatorname{val}() \mathbin{;} \mathcal{H}' H ; set p ℓ V ⇝ val ( ) ; H ′ and
ℓ : A ∈ Π [ p ] Γ ; Π ; Φ 1 ⊢ set p ℓ : A → M u t 1 Succ ( Φ 1 ) Γ ; Π ; Φ 1 ⊢ set p ℓ : A → M u t 1 Γ ; Π ; Φ 2 ⊢ V : A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ set p ℓ V : 1 ! M u t \frac{\ell: A \in\Pi[p]}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash\operatorname{set}^{\ell}_{p} : A \xrightarrow{\mathrm{Mut}} 1}
\qquad
\frac{\operatorname{Succ}(\Phi_1)}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash\operatorname{set}^{\ell}_{p} : A \xrightarrow{\mathrm{Mut}} 1}
\qquad
\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash V : A}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \bowtie\Phi_2 \vdash\operatorname{set}^{\ell}_{p}\ V : 1 \mathbin{!} \mathrm{Mut}} Γ ; Π ; Φ 1 ⊢ set p ℓ : A Mut 1 ℓ : A ∈ Π [ p ] Γ ; Π ; Φ 1 ⊢ set p ℓ : A Mut 1 Succ ( Φ 1 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ set p ℓ V : 1 ! Mut Γ ; Π ; Φ 2 ⊢ V : A
where H ′ = H ∣ H [ p ] . s t [ ℓ ] ↦ V \mathcal{H}' = \mathcal{H} \mid\mathcal{H}[p].\mathrm{st}[\ell] \mapsto V H ′ = H ∣ H [ p ] . st [ ℓ ] ↦ V and H [ p ] . r e r e n d e r ↦ t t \mathcal{H}[p].\mathrm{rerender} \mapsto\mathrm{tt} H [ p ] . rerender ↦ tt .
By Lemma A.4 (unrestriction) on (3), we know (5) that Succ ( Φ 2 ) \operatorname{Succ}(\Phi_2) Succ ( Φ 2 ) .
Choose Φ N = Φ M \Phi_N = \Phi_M Φ N = Φ M , Φ H ′ = Φ H ▹ Φ 2 \Phi'_H = \Phi_H \mathbin{\triangleright} \Phi_2 Φ H ′ = Φ H ▹ Φ 2 , and Π ′ = Π \Pi' = \Pi Π ′ = Π , trivializing conclusion (iv). By (5) and Lemma A.8 (unrestriction) on Φ H \Phi_H Φ H , Φ H ′ \Phi'_H Φ H ′ is defined.
By (5), ( Φ 1 ▹ Φ 2 ) ▹ ( Φ H ▹ Φ 2 ) = ( Φ 1 ▹ Φ 2 ) ▹ Φ H (\Phi_1 \mathbin{\triangleright} \Phi_2) \mathbin{\triangleright} (\Phi_H \mathbin{\triangleright} \Phi_2) = (\Phi_1 \mathbin{\triangleright} \Phi_2) \mathbin{\triangleright} \Phi_H ( Φ 1 ▹ Φ 2 ) ▹ ( Φ H ▹ Φ 2 ) = ( Φ 1 ▹ Φ 2 ) ▹ Φ H , satisfying conclusion (iii).
Clearly Succ ( Φ 3 ) \operatorname{Succ}(\Phi_3) Succ ( Φ 3 ) by Lemma A.8, so we weaken (3) by Φ 3 \Phi_3 Φ 3 (Lemma A.9) to get that Γ ; Π ; Φ 2 ▹ Φ 3 ⊢ V : A \Gamma; \Pi; \Phi_2 \mathbin{\triangleright} \Phi_3 \vdash V : A Γ ; Π ; Φ 2 ▹ Φ 3 ⊢ V : A . It then follows from premise (i-b) that Γ ; Π ; ( Φ 2 ▹ Φ 3 ) ▹ Φ 4 ⊨ H \Gamma; \Pi; (\Phi_2 \mathbin{\triangleright} \Phi_3) \mathbin{\triangleright} \Phi_4 \models\mathcal{H} Γ ; Π ; ( Φ 2 ▹ Φ 3 ) ▹ Φ 4 ⊨ H , i.e. conclusion (ii) holds.
We derive conclusion (i) as follows:
Succ ( Φ 1 ▹ Φ 2 ) ( 2 ) and ( 5 ) \frac{\operatorname{Succ}(\Phi_1 \mathbin{\triangleright} \Phi_2)}{(2)\text{ and }(5)} ( 2 ) and ( 5 ) Succ ( Φ 1 ▹ Φ 2 )
Γ ; Π ; Φ 1 ▹ Φ 2 ⊢ ( ) : 1 Γ ; Π ; Φ 1 ▹ Φ 2 ⊢ val ( ) : 1 ! Pure \frac{\Gamma; \Pi; \Phi_1 \mathbin{\triangleright} \Phi_2 \vdash() : 1}{\Gamma; \Pi; \Phi_1 \mathbin{\triangleright} \Phi_2 \vdash\operatorname{val}() : 1\ !\ \operatorname{Pure}} Γ ; Π ; Φ 1 ▹ Φ 2 ⊢ val ( ) : 1 ! Pure Γ ; Π ; Φ 1 ▹ Φ 2 ⊢ ( ) : 1
Γ ; Π ; Φ 1 ▹ Φ 2 ⊢ val ( ) : 1 ! Pure Γ ; Π ; Φ 1 ▹ Φ 2 ⊢ val ( ) : 1 ! Mut \frac{\Gamma; \Pi; \Phi_1 \mathbin{\triangleright} \Phi_2 \vdash\operatorname{val}() : 1\ !\ \operatorname{Pure}}{\Gamma; \Pi; \Phi_1 \mathbin{\triangleright} \Phi_2 \vdash\operatorname{val}() : 1\ !\ \operatorname{Mut}} Γ ; Π ; Φ 1 ▹ Φ 2 ⊢ val ( ) : 1 ! Mut Γ ; Π ; Φ 1 ▹ Φ 2 ⊢ val ( ) : 1 ! Pure
Case EC-Eval, ϕ = Init \phi= \operatorname{Init} ϕ = Init : We have
H ; D ⇝ p Init D ′ ; H ′ H ; ⌈ D 0 ⌉ ⇓ p Init D ⇝ p Init ⌈ D 0 ⌉ ⇓ p Init D ′ ; H ′ \frac{\mathcal{H} ; D \mathrel{\leadsto^{\operatorname{Init}}_p} D' ; \mathcal{H}'}{\mathcal{H} ; \lceil D_0 \rceil\mathrel{\Downarrow^{\operatorname{Init}}_p} D \mathrel{\leadsto^{\operatorname{Init}}_p} \lceil D_0 \rceil\mathrel{\Downarrow^{\operatorname{Init}}_p} D' ; \mathcal{H}'} H ; ⌈ D 0 ⌉ ⇓ p Init D ⇝ p Init ⌈ D 0 ⌉ ⇓ p Init D ′ ; H ′ H ; D ⇝ p Init D ′ ; H ′
Γ ; Π ; Φ 1 ⊢ D 0 : L ⊎ Π [ p ] Γ ; Π ; Φ 2 ⊢ D : L Γ ; Π ; Φ 1 ▹ Φ 2 , p : Init ⊢ ⌈ D 0 ⌉ ⇓ p Init D : ElemInst ! Mut \frac{\Gamma; \Pi; \Phi_1 \vdash D_0 : \mathcal{L} \uplus\Pi[p] \qquad\Gamma; \Pi; \Phi_2 \vdash D : \mathcal{L}}{\Gamma; \Pi; \Phi_1 \mathbin{\triangleright} \Phi_2, p : \operatorname{Init} \vdash\lceil D_0 \rceil\mathrel{\Downarrow^{\operatorname{Init}}_p} D : \operatorname{ElemInst}\ !\ \operatorname{Mut}} Γ ; Π ; Φ 1 ▹ Φ 2 , p : Init ⊢ ⌈ D 0 ⌉ ⇓ p Init D : ElemInst ! Mut Γ ; Π ; Φ 1 ⊢ D 0 : L ⊎ Π [ p ] Γ ; Π ; Φ 2 ⊢ D : L
(2) implies (4) that L ∩ Π [ p ] = ∅ \mathcal{L} \cap\Pi[p] = \varnothing L ∩ Π [ p ] = ∅ . That Φ 1 ▹ Φ 2 , p : Init \Phi_1 \mathbin{\triangleright} \Phi_2, p : \operatorname{Init} Φ 1 ▹ Φ 2 , p : Init is defined entails (5) p ∉ dom ( Φ 2 ) p \notin\operatorname{dom}(\Phi_2) p ∈ / dom ( Φ 2 ) .
By Theorem A.22 (⇝ p Init \mathrel{\leadsto^{\operatorname{Init}}_p} ⇝ p Init -preservation) on (1), (3), (4), (5), and premise (i-b), we have some Φ H ′ \Phi'_H Φ H ′ and Π ′ \Pi' Π ′ with: (6) Γ ; Π ′ ; Φ 2 ⊢ D ′ : L ′ \Gamma; \Pi' ; \Phi_2 \vdash D' : \mathcal{L}' Γ ; Π ′ ; Φ 2 ⊢ D ′ : L ′ , (7) Γ ; Π ′ ⊨ H ′ \Gamma; \Pi' \models\mathcal{H}' Γ ; Π ′ ⊨ H ′ , (8) Φ 2 ▹ Φ H ′ = Φ 2 ▹ Φ H \Phi_2 \mathbin{\triangleright} \Phi'_H = \Phi_2 \mathbin{\triangleright} \Phi_H Φ 2 ▹ Φ H ′ = Φ 2 ▹ Φ H , (9) Π ⊑ p : Init Π ′ \Pi\sqsubseteq_{p:\operatorname{Init}} \Pi' Π ⊑ p : Init Π ′ , and (10) Π ′ [ p ] ⊎ L ′ = Π [ p ] ⊎ L \Pi'[p] \uplus\mathcal{L}' = \Pi[p] \uplus\mathcal{L} Π ′ [ p ] ⊎ L ′ = Π [ p ] ⊎ L .
We choose this Π ′ \Pi' Π ′ and Φ H ′ \Phi'_H Φ H ′ , and retain Φ N = Φ M = Φ 1 ▹ Φ 2 , p : Init \Phi_N = \Phi_M = \Phi_1 \mathbin{\triangleright} \Phi_2, p : \operatorname{Init} Φ N = Φ M = Φ 1 ▹ Φ 2 , p : Init .
We started with Φ 1 ▹ Φ 2 ▹ Φ H , p : Init \Phi_1 \mathbin{\triangleright} \Phi_2 \mathbin{\triangleright} \Phi_H, p : \operatorname{Init} Φ 1 ▹ Φ 2 ▹ Φ H , p : Init as defined. By (8), we know (11) that Φ 1 ▹ Φ 2 ▹ Φ H ′ , p : Init \Phi_1 \mathbin{\triangleright} \Phi_2 \mathbin{\triangleright} \Phi'_H, p : \operatorname{Init} Φ 1 ▹ Φ 2 ▹ Φ H ′ , p : Init is also defined.
Conclusion (iii) follows from Lemma 4.5 (fresh Φ \Phi Φ -extension) using (8) and extending by Φ 1 , p : Init \Phi_1, p : \operatorname{Init} Φ 1 , p : Init , which is valid by (11).
(11) also lets us apply Lemma A.17 (Π \Pi Π -order preservation) on (8), extending by Φ 1 ▹ Φ 2 ▹ Φ H ′ \Phi_1 \mathbin{\triangleright} \Phi_2 \mathbin{\triangleright} \Phi'_H Φ 1 ▹ Φ 2 ▹ Φ H ′ , to get that Π ⊑ Φ M ▹ Φ H ′ Π ′ \Pi\mathrel{\sqsubseteq_{\Phi_M\mathbin{\triangleright}\Phi'_H}} \Pi' Π ⊑ Φ M ▹ Φ H ′ Π ′ , satisfying conclusion (iv).
By choice of Π \Pi Π and Φ \Phi Φ , (7) gives conclusion (ii).
Lemma A.3 (Π \Pi Π -weakening) on (2) using (9), which is valid by (11), gives us (12) that Γ ; Π ′ ; Φ 1 ⊢ D 0 : L ⊎ Π [ p ] \Gamma; \Pi' ; \Phi_1 \vdash D_0 : \mathcal{L} \uplus\Pi[p] Γ ; Π ′ ; Φ 1 ⊢ D 0 : L ⊎ Π [ p ] .
By (10), (12) is equivalent to (13) that Γ ; Π ′ ; Φ 1 ⊢ D 0 : L ′ ⊎ Π ′ [ p ] \Gamma; \Pi' ; \Phi_1 \vdash D_0 : \mathcal{L}' \uplus\Pi'[p] Γ ; Π ′ ; Φ 1 ⊢ D 0 : L ′ ⊎ Π ′ [ p ] .
We derive conclusion (i) as follows:
Γ ; Π ′ ; Φ 1 ⊢ D 0 : L ′ ⊎ Π ′ [ p ] Γ ; Π ′ ; Φ 2 ⊢ D ′ : L ′ Γ ; Π ′ ; Φ 1 ▹ Φ 2 , p : Init ⊢ ⌈ D 0 ⌉ ⇓ p Init D ′ : ElemInst ! Mut \frac{\Gamma; \Pi' ; \Phi_1 \vdash D_0 : \mathcal{L}' \uplus\Pi'[p] \qquad\Gamma; \Pi' ; \Phi_2 \vdash D' : \mathcal{L}'}{\Gamma; \Pi' ; \Phi_1 \mathbin{\triangleright} \Phi_2, p : \operatorname{Init} \vdash\lceil D_0 \rceil\mathrel{\Downarrow^{\operatorname{Init}}_p} D' : \operatorname{ElemInst}\ !\ \operatorname{Mut}} Γ ; Π ′ ; Φ 1 ▹ Φ 2 , p : Init ⊢ ⌈ D 0 ⌉ ⇓ p Init D ′ : ElemInst ! Mut Γ ; Π ′ ; Φ 1 ⊢ D 0 : L ′ ⊎ Π ′ [ p ] Γ ; Π ′ ; Φ 2 ⊢ D ′ : L ′
Case EC-Eval, ϕ = S u c c \phi= \mathrm{Succ} ϕ = Succ : We have
( 1 ) H ; D ⇝ p S u c c D ′ ; H ′ H ; ⌈ D 0 ⌉ ⇓ p S u c c D ⇝ p S u c c ⌈ D 0 ⌉ ⇓ p S u c c D ′ ; H ′ E C - E v a l \frac{(1)\quad\mathcal{H};D \mathrel{\leadsto^{\mathrm{Succ}}_{p}} D';\mathcal{H}'}{\mathcal{H};\lceil D_{0}\rceil\mathrel{\Downarrow^{\mathrm{Succ}}_{p}} D \mathrel{\leadsto^{\mathrm{Succ}}_{p}} \lceil D_{0}\rceil\mathrel{\Downarrow^{\mathrm{Succ}}_{p}} D';\mathcal{H}'}\ \mathrm{EC\text{-}Eval} H ; ⌈ D 0 ⌉ ⇓ p Succ D ⇝ p Succ ⌈ D 0 ⌉ ⇓ p Succ D ′ ; H ′ ( 1 ) H ; D ⇝ p Succ D ′ ; H ′ EC - Eval
( 2 ) Γ ; Π ; Φ 1 ⊢ D 0 : Π [ p ] ( 3 ) Γ ; Π ; Φ 2 ⊢ D : L ( 4 ) L ⊆ Π [ p ] ( 5 ) ( Φ 1 ⋈ Φ 2 ) [ p ] = S u c c Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ⌈ D 0 ⌉ ⇓ p S u c c D : E l e m I n s t ! M u t T C - E v a l S \frac{(2)\quad\Gamma;\Pi;\Phi_{1}\vdash D_{0}:\Pi[p]\qquad(3)\quad\Gamma;\Pi;\Phi_{2}\vdash D:L\qquad(4)\quad L\subseteq\Pi[p]\qquad(5)\quad(\Phi_{1}\bowtie\Phi_{2})[p]=\mathrm{Succ}}{\Gamma;\Pi;\Phi_{1}\bowtie\Phi_{2}\vdash\lceil D_{0}\rceil\Downarrow^{\mathrm{Succ}}_{p}D:\mathrm{ElemInst}\mathbin{!}\mathrm{Mut}}\ \mathrm{TC\text{-}EvalS} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ⌈ D 0 ⌉ ⇓ p Succ D : ElemInst ! Mut ( 2 ) Γ ; Π ; Φ 1 ⊢ D 0 : Π [ p ] ( 3 ) Γ ; Π ; Φ 2 ⊢ D : L ( 4 ) L ⊆ Π [ p ] ( 5 ) ( Φ 1 ⋈ Φ 2 ) [ p ] = Succ TC - EvalS
By Theorem A.23 (⇝^{\mathrm{Succ}}_{p}\text{-preservation}) on (1), (3), (4), and premise (i-b), we have some Φ 2 ′ \Phi'_{2} Φ 2 ′ such that (6) Γ ; Π ; Φ 2 ′ ⊢ D ′ : L ′ \Gamma;\Pi;\Phi'_{2}\vdash D':L' Γ ; Π ; Φ 2 ′ ⊢ D ′ : L ′ , (7) Φ 2 ′ ⋈ Φ H = Φ 2 ⋈ Φ H \Phi'_{2}\bowtie\Phi_{\mathcal{H}}=\Phi_{2}\bowtie\Phi_{\mathcal{H}} Φ 2 ′ ⋈ Φ H = Φ 2 ⋈ Φ H , (8) H ′ = H \mathcal{H}'=\mathcal{H} H ′ = H , and (9) L ′ ⊆ L L'\subseteq L L ′ ⊆ L .
Choose Φ N = Φ 1 ⋈ Φ 2 ′ \Phi_{N}=\Phi_{1}\bowtie\Phi'_{2} Φ N = Φ 1 ⋈ Φ 2 ′ and Φ H ′ = Φ H \Phi'_{\mathcal{H}}=\Phi_{\mathcal{H}} Φ H ′ = Φ H . By Lemma A.6 (unrestriction) on (2) and (6), both S u c c ( Φ 1 ) \mathrm{Succ}(\Phi_{1}) Succ ( Φ 1 ) and S u c c ( Φ 2 ′ ) \mathrm{Succ}(\Phi'_{2}) Succ ( Φ 2 ′ ) , so Φ N \Phi_{N} Φ N is defined. Lemma 4.5 (fresh $\Phi$-extension) on (7) then gives us conclusion (iii).
( 2 ) Γ ; Π ; Φ 1 ⊢ D 0 : Π [ p ] ( 7 ) Γ ; Π ; Φ 2 ′ ⊢ D ′ : L ′ ( 10 ) L ′ ⊆ Π [ p ] ( 11 ) ( Φ 1 ⋈ Φ 2 ′ ) [ p ] = S u c c Γ ; Π ; Φ 1 ⋈ Φ 2 ′ ⊢ ⌈ D 0 ⌉ ⇓ p S u c c D ′ : E l e m I n s t ! M u t \frac{(2)\quad\Gamma;\Pi;\Phi_{1}\vdash D_{0}:\Pi[p]\qquad(7)\quad\Gamma;\Pi;\Phi'_{2}\vdash D':L'\qquad(10)\quad L'\subseteq\Pi[p]\qquad(11)\quad(\Phi_{1}\bowtie\Phi'_{2})[p]=\mathrm{Succ}}{\Gamma;\Pi;\Phi_{1}\bowtie\Phi'_{2}\vdash\lceil D_{0}\rceil\Downarrow^{\mathrm{Succ}}_{p}D':\mathrm{ElemInst}\mathbin{!}\mathrm{Mut}} Γ ; Π ; Φ 1 ⋈ Φ 2 ′ ⊢ ⌈ D 0 ⌉ ⇓ p Succ D ′ : ElemInst ! Mut ( 2 ) Γ ; Π ; Φ 1 ⊢ D 0 : Π [ p ] ( 7 ) Γ ; Π ; Φ 2 ′ ⊢ D ′ : L ′ ( 10 ) L ′ ⊆ Π [ p ] ( 11 ) ( Φ 1 ⋈ Φ 2 ′ ) [ p ] = Succ
Case EC-EvalDone, ϕ = I n i t \phi= \mathrm{Init} ϕ = Init : We have
H ; ⌈ D ⌉ ⇓ p I n i t v a l V ⇝ l e t x = i n i t V i n v a l c o m p I n s t p ( ⌈ D ⌉ , x ) ; H \mathcal{H};\lceil D\rceil\Downarrow^{\mathrm{Init}}_{p}\ \mathrm{val}\ V\mathrel{\leadsto}\mathrm{let}\ x=\mathrm{init}\ V\ \mathrm{in}\ \mathrm{val}\ \mathrm{compInst}_{p}(\lceil D\rceil,x);\mathcal{H} H ; ⌈ D ⌉ ⇓ p Init val V ⇝ let x = init V in val compInst p (⌈ D ⌉ , x ) ; H
( 1 ) Γ ; Π ; Φ 1 ⊢ D 0 : ∅ ⊎ Π [ p ] ( 2 ) Γ ; Π ; Φ 2 ⊢ V : E l e m e n t Γ ; Π ; Φ 2 ⊢ v a l V : ∅ Γ ; Π ; Φ 1 ⋈ Φ 2 , p : I n i t ⊢ ⌈ D 0 ⌉ ⇓ p I n i t v a l V : E l e m I n s t ! M u t T C - E v a l I \frac{(1)\quad\Gamma;\Pi;\Phi_{1}\vdash D_{0}:\varnothing\uplus\Pi[p]\qquad(2)\quad\Gamma;\Pi;\Phi_{2}\vdash V:\mathrm{Element}\qquad\Gamma;\Pi;\Phi_{2}\vdash\mathrm{val}\ V:\varnothing}{\Gamma;\Pi;\Phi_{1}\bowtie\Phi_{2},p:\mathrm{Init}\vdash\lceil D_{0}\rceil\Downarrow^{\mathrm{Init}}_{p}\mathrm{val}\ V:\mathrm{ElemInst}\mathbin{!}\mathrm{Mut}}\ \mathrm{TC\text{-}EvalI} Γ ; Π ; Φ 1 ⋈ Φ 2 , p : Init ⊢ ⌈ D 0 ⌉ ⇓ p Init val V : ElemInst ! Mut ( 1 ) Γ ; Π ; Φ 1 ⊢ D 0 : ∅ ⊎ Π [ p ] ( 2 ) Γ ; Π ; Φ 2 ⊢ V : Element Γ ; Π ; Φ 2 ⊢ val V : ∅ TC - EvalI
We choose Φ H ′ = Φ H \Phi'_{\mathcal{H}}=\Phi_{\mathcal{H}} Φ H ′ = Φ H and Φ N = Φ 1 ⋈ Φ 2 , p : S u c c \Phi_{N}=\Phi_{1}\bowtie\Phi_{2},p:\mathrm{Succ} Φ N = Φ 1 ⋈ Φ 2 , p : Succ . Clearly Φ M ⋈ Φ H ⊑ f r e s h Φ N ⋈ Φ H ′ \Phi_{M}\bowtie\Phi_{\mathcal{H}}\sqsubseteq_{\mathrm{fresh}}\Phi_{N}\bowtie\Phi'_{\mathcal{H}} Φ M ⋈ Φ H ⊑ fresh Φ N ⋈ Φ H ′ , satisfying conclusion (iii).
By Lemmas A.6 and A.4 on (1) and (2), we get S u c c ( Φ 1 ) \mathrm{Succ}(\Phi_{1}) Succ ( Φ 1 ) and S u c c ( Φ 2 ) \mathrm{Succ}(\Phi_{2}) Succ ( Φ 2 ) , respectively. Clearly then (3) S u c c ( Φ N ) \mathrm{Succ}(\Phi_{N}) Succ ( Φ N ) .
Γ 6 ; Π ; Φ N ⊢ D : Π [ p ] Φ N [ p ] = S u c c ( 4 ) S u c c ( Φ N ) Γ 6 ; Π ; Φ N ⊢ x : E l e m I n s t T V - V a r Γ 6 ; Π ; Φ N ⊢ D : Π [ p ] Γ 6 ; Π ; Φ N ⊢ x : E l e m I n s t Γ 6 ; Π ; Φ N ⊢ compInst p ( ⌈ D ⌉ , x ) : E l e m I n s t T V - C o m p I Γ 6 ; Π ; Φ N ⊢ compInst p ( ⌈ D ⌉ , x ) : E l e m I n s t Γ 6 ; Π ; Φ N ⊢ val compInst p ( ⌈ D ⌉ , x ) : E l e m I n s t ! P u r e T C - V a l Γ 6 ; Π ; Φ N ⊢ val compInst p ( ⌈ D ⌉ , x ) : E l e m I n s t ! P u r e Γ 6 ; Π ; Φ N ⊢ val compInst p ( ⌈ D ⌉ , x ) : E l e m I n s t ! M u t T C - S u b ( 6 ) Γ 6 ; Π ; Φ N ⊢ val compInst p ( ⌈ D ⌉ , x ) : E l e m I n s t ! M u t Γ ; Π ; Φ N ⊢ V : E l e m e n t Γ ; Π ; Φ N ⊢ init V : E l e m I n s t ! M u t T C - I n i t ( 5 ) Γ ; Π ; Φ N ⊢ init V : E l e m I n s t ! M u t [ ( 6 ) , Γ 6 = Γ , x : E l e m I n s t ] Γ ; Π ; Φ N ⊢ let x = init V in val compInst p ( ⌈ D ⌉ , x ) : E l e m I n s t ! M u t T C - L e t \begin{aligned}
&\frac{\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash D : \Pi[p]}{\Phi_N[p] = \mathrm{Succ}}\ (4)
\qquad
\frac{\mathrm{Succ}(\Phi_N)}{\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash x : \mathrm{ElemInst}}\ \mathrm{TV\text{-}Var}\\
&\frac{\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash D : \Pi[p]\qquad\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash x : \mathrm{ElemInst}}{\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{compInst}_{p}(\lceil D\rceil,x) : \mathrm{ElemInst}}\ \mathrm{TV\text{-}CompI}\\
&\frac{\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{compInst}_{p}(\lceil D\rceil,x) : \mathrm{ElemInst}}{\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{val}\operatorname{compInst}_{p}(\lceil D\rceil,x) : \mathrm{ElemInst}\mathbin{!}\mathrm{Pure}}\ \mathrm{TC\text{-}Val}\\
&\frac{\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{val}\operatorname{compInst}_{p}(\lceil D\rceil,x) : \mathrm{ElemInst}\mathbin{!}\mathrm{Pure}}{\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{val}\operatorname{compInst}_{p}(\lceil D\rceil,x) : \mathrm{ElemInst}\mathbin{!}\mathrm{Mut}}\ \mathrm{TC\text{-}Sub}\\
&(6)\quad\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{val}\operatorname{compInst}_{p}(\lceil D\rceil,x) : \mathrm{ElemInst}\mathbin{!}\mathrm{Mut}\\
&\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_N \vdash V : \mathrm{Element}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{init} V : \mathrm{ElemInst}\mathbin{!}\mathrm{Mut}}\ \mathrm{TC\text{-}Init}\quad(5)\\
&\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{init} V : \mathrm{ElemInst}\mathbin{!}\mathrm{Mut}\qquad[(6),\ \Gamma_6=\Gamma,\ x:\mathrm{ElemInst}]}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{let}\ x=\operatorname{init} V\ \operatorname{in}\ \operatorname{val}\operatorname{compInst}_{p}(\lceil D\rceil,x) : \mathrm{ElemInst}\mathbin{!}\mathrm{Mut}}\ \mathrm{TC\text{-}Let}
\end{aligned} Φ N [ p ] = Succ Γ 6 ; Π ; Φ N ⊢ D : Π [ p ] ( 4 ) Γ 6 ; Π ; Φ N ⊢ x : ElemInst Succ ( Φ N ) TV - Var Γ 6 ; Π ; Φ N ⊢ compInst p (⌈ D ⌉ , x ) : ElemInst Γ 6 ; Π ; Φ N ⊢ D : Π [ p ] Γ 6 ; Π ; Φ N ⊢ x : ElemInst TV - CompI Γ 6 ; Π ; Φ N ⊢ val compInst p (⌈ D ⌉ , x ) : ElemInst ! Pure Γ 6 ; Π ; Φ N ⊢ compInst p (⌈ D ⌉ , x ) : ElemInst TC - Val Γ 6 ; Π ; Φ N ⊢ val compInst p (⌈ D ⌉ , x ) : ElemInst ! Mut Γ 6 ; Π ; Φ N ⊢ val compInst p (⌈ D ⌉ , x ) : ElemInst ! Pure TC - Sub ( 6 ) Γ 6 ; Π ; Φ N ⊢ val compInst p (⌈ D ⌉ , x ) : ElemInst ! Mut Γ ; Π ; Φ N ⊢ init V : ElemInst ! Mut Γ ; Π ; Φ N ⊢ V : Element TC - Init ( 5 ) Γ ; Π ; Φ N ⊢ let x = init V in val compInst p (⌈ D ⌉ , x ) : ElemInst ! Mut Γ ; Π ; Φ N ⊢ init V : ElemInst ! Mut [( 6 ) , Γ 6 = Γ , x : ElemInst ] TC - Let
Case EC-EvalDone, ϕ = S u c c \phi= \mathrm{Succ} ϕ = Succ :
H ; ⌈ D ⌉ ⇓ p S u c c val V ⇝ let x = init V in val compInst p ( ⌈ D ⌉ , x ) ; H \mathcal{H}\mathbin{;} \lceil D\rceil\mathrel{\Downarrow^{\mathrm{Succ}}_{p}} \operatorname{val} V \mathrel{\rightsquigarrow} \operatorname{let}\ x=\operatorname{init} V\ \operatorname{in}\ \operatorname{val}\operatorname{compInst}_{p}(\lceil D\rceil,x)\mathbin{;} \mathcal{H} H ; ⌈ D ⌉ ⇓ p Succ val V ⇝ let x = init V in val compInst p (⌈ D ⌉ , x ) ; H
Γ ; Π ; Φ 1 ⊢ D : Π [ p ] Γ ; Π ; Φ 2 ⊢ val V : ∅ Γ ; Π ; Φ 2 ⊢ V : E l e m e n t ( 2 ) T B - V a l Γ ; Π ; Φ 1 ⊢ D : Π [ p ] ( Φ 1 ⋏ Φ 2 ) [ p ] = S u c c ⋯ Γ ; Π ; Φ 1 ⋏ Φ 2 ⊢ ⌈ D 0 ⌉ ⇓ p S u c c D : E l e m I n s t ! M u t ( 1 ) ( 3 ) T C - E v a l S \begin{aligned}
&\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash D : \Pi[p]\qquad\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash\operatorname{val} V : \varnothing}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash V : \mathrm{Element}}\ (2)\ \mathrm{TB\text{-}Val}\\
&\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash D : \Pi[p]\qquad(\Phi_1 \mathbin{\curlywedge} \Phi_2)[p] = \mathrm{Succ}\ \cdots}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \mathbin{\curlywedge} \Phi_2 \vdash\lceil D_0\rceil\mathrel{\Downarrow^{\mathrm{Succ}}_{p}} D : \mathrm{ElemInst}\mathbin{!}\mathrm{Mut}}\ (1)\ (3)\ \mathrm{TC\text{-}EvalS}
\end{aligned} Γ ; Π ; Φ 2 ⊢ V : Element Γ ; Π ; Φ 1 ⊢ D : Π [ p ] Γ ; Π ; Φ 2 ⊢ val V : ∅ ( 2 ) TB - Val Γ ; Π ; Φ 1 ⋏ Φ 2 ⊢ ⌈ D 0 ⌉ ⇓ p Succ D : ElemInst ! Mut Γ ; Π ; Φ 1 ⊢ D : Π [ p ] ( Φ 1 ⋏ Φ 2 ) [ p ] = Succ ⋯ ( 1 ) ( 3 ) TC - EvalS
We retain Φ N = Φ 1 ⋏ Φ 2 \Phi_N = \Phi_1 \mathbin{\curlywedge} \Phi_2 Φ N = Φ 1 ⋏ Φ 2 . By Lemmas A.6 and A.4 on (1) and (2), we get S u c c ( Φ 1 ) \mathrm{Succ}(\Phi_1) Succ ( Φ 1 ) and S u c c ( Φ 2 ) \mathrm{Succ}(\Phi_2) Succ ( Φ 2 ) , respectively. Clearly then (4) S u c c ( Φ N ) \mathrm{Succ}(\Phi_N) Succ ( Φ N ) .
By Lemma A.11 (Φ \Phi Φ -weakening) on (1) using (4), we get (5) that Γ ; Π ; Φ N ⊢ D : Π [ p ] \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_N \vdash D : \Pi[p] Γ ; Π ; Φ N ⊢ D : Π [ p ] .
By Lemma A.9 (Φ \Phi Φ -weakening) on (2), we get (6) Γ ; Π ; Φ N ⊢ V : E l e m e n t \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_N \vdash V : \mathrm{Element} Γ ; Π ; Φ N ⊢ V : Element .
We derive conclusion (i) as follows by way of subderivation (7), using Φ N \Phi_N Φ N intuitionistically by (4):
Γ 7 ; Π ; Φ N ⊢ D : Π [ p ] Φ N [ p ] = S u c c ( 5 ) S u c c ( Φ D ′ ) Γ 7 ; Π ; Φ N ⊢ x : E l e m I n s t ( 4 ) T V - V a r Γ 7 ; Π ; Φ N ⊢ D : Π [ p ] Γ 7 ; Π ; Φ N ⊢ x : E l e m I n s t Γ 7 ; Π ; Φ N ⊢ compInst p ( ⌈ D ⌉ , x ) : E l e m I n s t T V - C o m p I Γ 7 ; Π ; Φ N ⊢ compInst p ( ⌈ D ⌉ , x ) : E l e m I n s t Γ 7 ; Π ; Φ N ⊢ val compInst p ( ⌈ D ⌉ , x ) : E l e m I n s t ! P u r e T C - V a l Γ 7 ; Π ; Φ N ⊢ val compInst p ( ⌈ D ⌉ , x ) : E l e m I n s t ! P u r e Γ 7 ; Π ; Φ N ⊢ val compInst p ( ⌈ D ⌉ , x ) : E l e m I n s t ! M u t T C - S u b ( 7 ) Γ 7 ; Π ; Φ N ⊢ val compInst p ( ⌈ D ⌉ , x ) : E l e m I n s t ! M u t Γ ; Π ; Φ N ⊢ V : E l e m e n t Γ ; Π ; Φ N ⊢ init V : E l e m I n s t ! M u t ( 5 ) T C - I n i t Γ ; Π ; Φ N ⊢ init V : E l e m I n s t ! M u t [ ( 7 ) , Γ 7 = Γ , x : E l e m I n s t ] Γ ; Π ; Φ N ⊢ let x = init V in val compInst p ( ⌈ D ⌉ , x ) : E l e m I n s t ! M u t T C - L e t \begin{aligned}
&\frac{\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash D : \Pi[p]}{\Phi_N[p] = \mathrm{Succ}}\ (5)
\qquad
\frac{\mathrm{Succ}(\Phi'_D)}{\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash x : \mathrm{ElemInst}}\ (4)\ \mathrm{TV\text{-}Var}\\
&\frac{\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash D : \Pi[p]\qquad\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash x : \mathrm{ElemInst}}{\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{compInst}_{p}(\lceil D\rceil,x) : \mathrm{ElemInst}}\ \mathrm{TV\text{-}CompI}\\
&\frac{\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{compInst}_{p}(\lceil D\rceil,x) : \mathrm{ElemInst}}{\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{val}\operatorname{compInst}_{p}(\lceil D\rceil,x) : \mathrm{ElemInst}\mathbin{!}\mathrm{Pure}}\ \mathrm{TC\text{-}Val}\\
&\frac{\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{val}\operatorname{compInst}_{p}(\lceil D\rceil,x) : \mathrm{ElemInst}\mathbin{!}\mathrm{Pure}}{\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{val}\operatorname{compInst}_{p}(\lceil D\rceil,x) : \mathrm{ElemInst}\mathbin{!}\mathrm{Mut}}\ \mathrm{TC\text{-}Sub}\\
&(7)\quad\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{val}\operatorname{compInst}_{p}(\lceil D\rceil,x) : \mathrm{ElemInst}\mathbin{!}\mathrm{Mut}\\
&\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_N \vdash V : \mathrm{Element}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{init} V : \mathrm{ElemInst}\mathbin{!}\mathrm{Mut}}\ (5)\ \mathrm{TC\text{-}Init}\\
&\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{init} V : \mathrm{ElemInst}\mathbin{!}\mathrm{Mut}\qquad[(7),\ \Gamma_7=\Gamma,\ x:\mathrm{ElemInst}]}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_N \vdash\operatorname{let}\ x=\operatorname{init} V\ \operatorname{in}\ \operatorname{val}\operatorname{compInst}_{p}(\lceil D\rceil,x) : \mathrm{ElemInst}\mathbin{!}\mathrm{Mut}}\ \mathrm{TC\text{-}Let}
\end{aligned} Φ N [ p ] = Succ Γ 7 ; Π ; Φ N ⊢ D : Π [ p ] ( 5 ) Γ 7 ; Π ; Φ N ⊢ x : ElemInst Succ ( Φ D ′ ) ( 4 ) TV - Var Γ 7 ; Π ; Φ N ⊢ compInst p (⌈ D ⌉ , x ) : ElemInst Γ 7 ; Π ; Φ N ⊢ D : Π [ p ] Γ 7 ; Π ; Φ N ⊢ x : ElemInst TV - CompI Γ 7 ; Π ; Φ N ⊢ val compInst p (⌈ D ⌉ , x ) : ElemInst ! Pure Γ 7 ; Π ; Φ N ⊢ compInst p (⌈ D ⌉ , x ) : ElemInst TC - Val Γ 7 ; Π ; Φ N ⊢ val compInst p (⌈ D ⌉ , x ) : ElemInst ! Mut Γ 7 ; Π ; Φ N ⊢ val compInst p (⌈ D ⌉ , x ) : ElemInst ! Pure TC - Sub ( 7 ) Γ 7 ; Π ; Φ N ⊢ val compInst p (⌈ D ⌉ , x ) : ElemInst ! Mut Γ ; Π ; Φ N ⊢ init V : ElemInst ! Mut Γ ; Π ; Φ N ⊢ V : Element ( 5 ) TC - Init Γ ; Π ; Φ N ⊢ let x = init V in val compInst p (⌈ D ⌉ , x ) : ElemInst ! Mut Γ ; Π ; Φ N ⊢ init V : ElemInst ! Mut [( 7 ) , Γ 7 = Γ , x : ElemInst ] TC - Let
Case EC-InitText: We have H \mathcal{H} H ; init text V ⇝ val textInst V V \rightsquigarrow\operatorname{val}\ \operatorname{textInst}\ V V ⇝ val textInst V ; H \mathcal{H} H and
(1) Γ ; Π ; Φ M ⊢ V : S t r Γ ; Π ; Φ M ⊢ text V : E l e m e n t T V - T e x t \frac{\text{(1)} \qquad\Gamma; \Pi; \Phi_{M} \vdash V : \mathrm{Str}}{\Gamma; \Pi; \Phi_{M} \vdash\operatorname{text}\ V : \mathrm{Element}}\ \mathrm{TV\text{-}Text} Γ ; Π ; Φ M ⊢ text V : Element (1) Γ ; Π ; Φ M ⊢ V : Str TV - Text
Γ ; Π ; Φ M ⊢ text V : E l e m e n t Γ ; Π ; Φ M ⊢ init text V : E l e m I n s t ! M u t T C - I n i t \frac{\Gamma; \Pi; \Phi_{M} \vdash\operatorname{text}\ V : \mathrm{Element}}{\Gamma; \Pi; \Phi_{M} \vdash\operatorname{init\ text}\ V : \mathrm{ElemInst}\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Init} Γ ; Π ; Φ M ⊢ init text V : ElemInst ! Mut Γ ; Π ; Φ M ⊢ text V : Element TC - Init
(1) Γ ; Π ; Φ M ⊢ V : S t r Γ ; Π ; Φ M ⊢ textInst V : E l e m I n s t T V - T e x t I \frac{\text{(1)} \qquad\Gamma; \Pi; \Phi_{M} \vdash V : \mathrm{Str}}{\Gamma; \Pi; \Phi_{M} \vdash\operatorname{textInst}\ V : \mathrm{ElemInst}}\ \mathrm{TV\text{-}TextI} Γ ; Π ; Φ M ⊢ textInst V : ElemInst (1) Γ ; Π ; Φ M ⊢ V : Str TV - TextI
Γ ; Π ; Φ M ⊢ textInst V : E l e m I n s t Γ ; Π ; Φ M ⊢ val textInst V : E l e m I n s t ! P u r e T C - V a l \frac{\Gamma; \Pi; \Phi_{M} \vdash\operatorname{textInst}\ V : \mathrm{ElemInst}}{\Gamma; \Pi; \Phi_{M} \vdash\operatorname{val}\ \operatorname{textInst}\ V : \mathrm{ElemInst}\ !\ \mathrm{Pure}}\ \mathrm{TC\text{-}Val} Γ ; Π ; Φ M ⊢ val textInst V : ElemInst ! Pure Γ ; Π ; Φ M ⊢ textInst V : ElemInst TC - Val
Γ ; Π ; Φ M ⊢ val textInst V : E l e m I n s t ! P u r e Γ ; Π ; Φ M ⊢ val textInst V : E l e m I n s t ! M u t T C - S u b \frac{\Gamma; \Pi; \Phi_{M} \vdash\operatorname{val}\ \operatorname{textInst}\ V : \mathrm{ElemInst}\ !\ \mathrm{Pure}}{\Gamma; \Pi; \Phi_{M} \vdash\operatorname{val}\ \operatorname{textInst}\ V : \mathrm{ElemInst}\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Sub} Γ ; Π ; Φ M ⊢ val textInst V : ElemInst ! Mut Γ ; Π ; Φ M ⊢ val textInst V : ElemInst ! Pure TC - Sub
Case EC-InitTag: We have H \mathcal{H} H ; init tag( V , W ) ⇝ let x = inits W in val tagInst i d ( V , x ) (V,W) \rightsquigarrow\operatorname{let}\ x = \operatorname{inits}\ W\ \operatorname{in}\ \operatorname{val}\ \operatorname{tagInst}_{id}(V,x) ( V , W ) ⇝ let x = inits W in val tagInst i d ( V , x ) ; H \mathcal{H} H and
(1) Γ ; Π ; Φ 1 ⊢ V : L i s t A t t r (2) Γ ; Π ; Φ 2 ⊢ W : L i s t E l e m e n t Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tag ( V , W ) : E l e m e n t T V - T a g \frac{\text{(1)} \qquad\Gamma; \Pi; \Phi_{1} \vdash V : \mathrm{List}\ \mathrm{Attr}
\qquad
\text{(2)} \qquad\Gamma; \Pi; \Phi_{2} \vdash W : \mathrm{List}\ \mathrm{Element}}
{\Gamma; \Pi; \Phi_{1} \mathbin{\bowtie} \Phi_{2} \vdash\operatorname{tag}(V,W) : \mathrm{Element}}\ \mathrm{TV\text{-}Tag} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tag ( V , W ) : Element (1) Γ ; Π ; Φ 1 ⊢ V : List Attr (2) Γ ; Π ; Φ 2 ⊢ W : List Element TV - Tag
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tag ( V , W ) : E l e m e n t Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ init tag ( V , W ) : E l e m I n s t ! M u t T C - I n i t \frac{\Gamma; \Pi; \Phi_{1} \mathbin{\bowtie} \Phi_{2} \vdash\operatorname{tag}(V,W) : \mathrm{Element}}
{\Gamma; \Pi; \Phi_{1} \mathbin{\bowtie} \Phi_{2} \vdash\operatorname{init\ tag}(V,W) : \mathrm{ElemInst}\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Init} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ init tag ( V , W ) : ElemInst ! Mut Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tag ( V , W ) : Element TC - Init
(1) Γ 3 ; Π ; Φ 1 ⊢ V : L i s t A t t r Γ 3 ; Π ; ∅ ⊢ x : L i s t E l e m I n s t Γ 3 ; Π ; Φ 1 ⊢ tagInst i d ( V , x ) : E l e m I n s t T V - T a g I \frac{\text{(1)} \qquad\Gamma_{3} ; \Pi; \Phi_{1} \vdash V : \mathrm{List}\ \mathrm{Attr}
\qquad
\Gamma_{3} ; \Pi; \varnothing\vdash x : \mathrm{List}\ \mathrm{ElemInst}}
{\Gamma_{3} ; \Pi; \Phi_{1} \vdash\operatorname{tagInst}_{id}(V,x) : \mathrm{ElemInst}}\ \mathrm{TV\text{-}TagI} Γ 3 ; Π ; Φ 1 ⊢ tagInst i d ( V , x ) : ElemInst (1) Γ 3 ; Π ; Φ 1 ⊢ V : List Attr Γ 3 ; Π ; ∅ ⊢ x : List ElemInst TV - TagI
Γ 3 ; Π ; Φ 1 ⊢ tagInst i d ( V , x ) : E l e m I n s t Γ 3 ; Π ; Φ 1 ⊢ val tagInst i d ( V , x ) : E l e m I n s t ! P u r e T C - V a l \frac{\Gamma_{3} ; \Pi; \Phi_{1} \vdash\operatorname{tagInst}_{id}(V,x) : \mathrm{ElemInst}}
{\Gamma_{3} ; \Pi; \Phi_{1} \vdash\operatorname{val}\ \operatorname{tagInst}_{id}(V,x) : \mathrm{ElemInst}\ !\ \mathrm{Pure}}\ \mathrm{TC\text{-}Val} Γ 3 ; Π ; Φ 1 ⊢ val tagInst i d ( V , x ) : ElemInst ! Pure Γ 3 ; Π ; Φ 1 ⊢ tagInst i d ( V , x ) : ElemInst TC - Val
Γ 3 ; Π ; Φ 1 ⊢ val tagInst i d ( V , x ) : E l e m I n s t ! P u r e (3) Γ 3 ; Π ; Φ 1 ⊢ val tagInst i d ( V , x ) : E l e m I n s t ! M u t T C - S u b \frac{\Gamma_{3} ; \Pi; \Phi_{1} \vdash\operatorname{val}\ \operatorname{tagInst}_{id}(V,x) : \mathrm{ElemInst}\ !\ \mathrm{Pure}}
{\text{(3)}\qquad\Gamma_{3} ; \Pi; \Phi_{1} \vdash\operatorname{val}\ \operatorname{tagInst}_{id}(V,x) : \mathrm{ElemInst}\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Sub} (3) Γ 3 ; Π ; Φ 1 ⊢ val tagInst i d ( V , x ) : ElemInst ! Mut Γ 3 ; Π ; Φ 1 ⊢ val tagInst i d ( V , x ) : ElemInst ! Pure TC - Sub
(2) Γ ; Π ; Φ 2 ⊢ W : L i s t E l e m e n t Γ ; Π ; Φ 2 ⊢ inits W : L i s t E l e m I n s t ! M u t T C - I n i t s \frac{\text{(2)} \qquad\Gamma; \Pi; \Phi_{2} \vdash W : \mathrm{List}\ \mathrm{Element}}
{\Gamma; \Pi; \Phi_{2} \vdash\operatorname{inits}\ W : \mathrm{List}\ \mathrm{ElemInst}\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Inits} Γ ; Π ; Φ 2 ⊢ inits W : List ElemInst ! Mut (2) Γ ; Π ; Φ 2 ⊢ W : List Element TC - Inits
Γ ; Π ; Φ 2 ⊢ inits W : L i s t E l e m I n s t ! M u t Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = inits W in val tagInst i d ( V , x ) : E l e m e n t ! M u t T C - L e t \frac{\Gamma; \Pi; \Phi_{2} \vdash\operatorname{inits}\ W : \mathrm{List}\ \mathrm{ElemInst}\ !\ \mathrm{Mut}}
{\Gamma; \Pi; \Phi_{1} \mathbin{\bowtie} \Phi_{2} \vdash\operatorname{let}\ x = \operatorname{inits}\ W\ \operatorname{in}\ \operatorname{val}\ \operatorname{tagInst}_{id}(V,x) : \mathrm{Element}\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Let} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = inits W in val tagInst i d ( V , x ) : Element ! Mut Γ ; Π ; Φ 2 ⊢ inits W : List ElemInst ! Mut TC - Let
[ ( 3 ) , Γ 3 = Γ , x : L i s t E l e m I n s t ] [(3),\ \Gamma_{3} = \Gamma,\ x : \mathrm{List}\ \mathrm{ElemInst}] [( 3 ) , Γ 3 = Γ , x : List ElemInst ]
Case EC-InitComp: We have H \mathcal{H} H ; init component { D } ⇝ ⌈ D ⌉ ↓ p I n i t D \{D\} \rightsquigarrow\lceil D\rceil\mathop{\downarrow}\limits_{p}^{\mathrm{Init}} D { D } ⇝ ⌈ D ⌉ p ↓ Init D ; H ′ \mathcal{H}' H ′ , where p p p is fresh, H ′ = H , p ↦ { s t : ∅ , r e r e n d e r : f f } \mathcal{H}' = \mathcal{H},\ p \mapsto\{\mathrm{st} : \varnothing,\ \mathrm{rerender} : \mathrm{ff}\} H ′ = H , p ↦ { st : ∅ , rerender : ff } , and
(1) Γ ; Π ; Φ M ⊢ D : L Γ ; Π ; Φ M ⊢ component { D } : E l e m e n t T V - C o m p \frac{\text{(1)} \qquad\Gamma; \Pi; \Phi_{M} \vdash D : \mathcal{L}}
{\Gamma; \Pi; \Phi_{M} \vdash\operatorname{component}\ \{D\} : \mathrm{Element}}\ \mathrm{TV\text{-}Comp} Γ ; Π ; Φ M ⊢ component { D } : Element (1) Γ ; Π ; Φ M ⊢ D : L TV - Comp
Γ ; Π ; Φ M ⊢ component { D } : E l e m e n t Γ ; Π ; Φ M ⊢ init component { D } : E l e m I n s t ! M u t T C - I n i t \frac{\Gamma; \Pi; \Phi_{M} \vdash\operatorname{component}\ \{D\} : \mathrm{Element}}
{\Gamma; \Pi; \Phi_{M} \vdash\operatorname{init\ component}\ \{D\} : \mathrm{ElemInst}\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Init} Γ ; Π ; Φ M ⊢ init component { D } : ElemInst ! Mut Γ ; Π ; Φ M ⊢ component { D } : Element TC - Init
Choose Φ N = Φ M , p : I n i t \Phi_{N} = \Phi_{M},\ p : \mathrm{Init} Φ N = Φ M , p : Init and Φ H ′ = Φ H \Phi_{H}' = \Phi_{H} Φ H ′ = Φ H . Since p p p is fresh, Φ N ⋈ Φ H \Phi_{N} \bowtie\Phi_{H} Φ N ⋈ Φ H is defined and we have Φ M ⋈ Φ H ⊑ f r e s h Φ N ⋈ Φ H \Phi_{M} \bowtie\Phi_{H} \sqsubseteq_{\mathrm{fresh}} \Phi_{N} \bowtie\Phi_{H} Φ M ⋈ Φ H ⊑ fresh Φ N ⋈ Φ H , satisfying conclusion (iii).
Choose Π ′ = Π , p ↦ ∅ \Pi' = \Pi,\ p \mapsto\varnothing Π ′ = Π , p ↦ ∅ . By definition, we have Π ⊑ Φ N ⋈ Φ H Π ′ \Pi\sqsubseteq_{\Phi_{N}\bowtie\Phi_{H}} \Pi' Π ⊑ Φ N ⋈ Φ H Π ′ , satisfying conclusion (iv).
By premise (i-b) and definition of each of Π ′ \Pi' Π ′ and H ′ \mathcal{H}' H ′ , we have that Γ ; Π ′ ; Φ H ⊨ H ′ \Gamma; \Pi' ; \Phi_{H} \models\mathcal{H}' Γ ; Π ′ ; Φ H ⊨ H ′ , satisfying conclusion (ii).
By Lemma A.3 (Π-weakening) on (1), using the fact that p p p is fresh and so p ∉ dom ( Φ M ) p \notin\operatorname{dom}(\Phi_{M}) p ∈ / dom ( Φ M ) , we get (3) that Γ ; Π ′ ; Φ M ⊢ D : L \Gamma; \Pi' ; \Phi_{M} \vdash D : \mathcal{L} Γ ; Π ′ ; Φ M ⊢ D : L .
Since Π ′ [ p ] = ∅ \Pi' [p] = \emptyset Π ′ [ p ] = ∅ , (3) is equivalent to (4) that Γ ; Π ′ ; Φ M ⊢ D : L ⊎ Π ′ [ p ] \Gamma; \Pi' ; \Phi_M \vdash D : L \uplus\Pi' [p] Γ ; Π ′ ; Φ M ⊢ D : L ⊎ Π ′ [ p ] .
By Lemma A.6 on (1), we know Succ ( Φ M ) \operatorname{Succ}(\Phi_M) Succ ( Φ M ) . It follows that (5) Φ M ⋈ Φ M = Φ M \Phi_M \bowtie\Phi_M = \Phi_M Φ M ⋈ Φ M = Φ M .
We derive conclusion (i) as follows, implicitly using (5):
Γ ; Π ′ ; Φ M ⊢ D : L ⊎ Π ′ [ p ] ‾ ( 4 ) Γ ; Π ′ ; Φ M ⊢ D : L ‾ ( 3 ) Γ ; Π ′ ; Φ M , p : Init ⊢ ⌈ D ⌉ ↓ p Init D : ElemInst ! Mut TC-EvalI \frac{\overline{\Gamma; \Pi' ; \Phi_M \vdash D : L \uplus\Pi' [p]}^{(4)}
\qquad
\overline{\Gamma; \Pi' ; \Phi_M \vdash D : L}^{(3)}
}{
\Gamma; \Pi' ; \Phi_{M,p} : \operatorname{Init} \vdash\lceil D\rceil\mathord{\downarrow}^{\operatorname{Init}}_{p} D : \operatorname{ElemInst}\ !\ \operatorname{Mut}
}
\quad\text{TC-EvalI} Γ ; Π ′ ; Φ M , p : Init ⊢ ⌈ D ⌉ ↓ p Init D : ElemInst ! Mut Γ ; Π ′ ; Φ M ⊢ D : L ⊎ Π ′ [ p ] ( 4 ) Γ ; Π ′ ; Φ M ⊢ D : L ( 3 ) TC-EvalI
Case EC-ClickText: We have H ; click i d textInst V ⇝ val ( ) ; H \mathcal{H} ; \operatorname{click}_{id}\ \operatorname{textInst}\ V \leadsto\operatorname{val}\ () ; \mathcal{H} H ; click i d textInst V ⇝ val ( ) ; H and
Γ ; Π ; Φ M ⊢ textInst V : ElemInst ‾ ( 1 ) Γ ; Π ; Φ M ⊢ click i d textInst V : 1 ! Mut TC-Click \frac{\overline{\Gamma; \Pi; \Phi_M \vdash\operatorname{textInst}\ V : \operatorname{ElemInst}}^{(1)}}{
\Gamma; \Pi; \Phi_M \vdash\operatorname{click}_{id}\ \operatorname{textInst}\ V : 1\ !\ \operatorname{Mut}
}
\quad\text{TC-Click} Γ ; Π ; Φ M ⊢ click i d textInst V : 1 ! Mut Γ ; Π ; Φ M ⊢ textInst V : ElemInst ( 1 ) TC-Click
By Lemma A.4 (unrestriction) on (1), we get (2) that Succ ( Φ M ) \operatorname{Succ}(\Phi_M) Succ ( Φ M ) .
We derive conclusion (i) as follows:
Succ ( Φ M ) ‾ ( 2 ) Γ ; Π ; Φ M ⊢ ( ) : 1 TV-Unit \frac{\overline{\operatorname{Succ}(\Phi_M)}^{(2)}}{
\Gamma; \Pi; \Phi_M \vdash() : 1
}
\quad\text{TV-Unit} Γ ; Π ; Φ M ⊢ ( ) : 1 Succ ( Φ M ) ( 2 ) TV-Unit
Γ ; Π ; Φ M ⊢ ( ) : 1 Γ ; Π ; Φ M ⊢ val ( ) : 1 ! Pure TC-Val \frac{\Gamma; \Pi; \Phi_M \vdash() : 1}{
\Gamma; \Pi; \Phi_M \vdash\operatorname{val}\ () : 1\ !\ \operatorname{Pure}
}
\quad\text{TC-Val} Γ ; Π ; Φ M ⊢ val ( ) : 1 ! Pure Γ ; Π ; Φ M ⊢ ( ) : 1 TC-Val
Γ ; Π ; Φ M ⊢ val ( ) : 1 ! Pure Γ ; Π ; Φ M ⊢ val ( ) : 1 ! Mut TC-Sub \frac{\Gamma; \Pi; \Phi_M \vdash\operatorname{val}\ () : 1\ !\ \operatorname{Pure}}{
\Gamma; \Pi; \Phi_M \vdash\operatorname{val}\ () : 1\ !\ \operatorname{Mut}
}
\quad\text{TC-Sub} Γ ; Π ; Φ M ⊢ val ( ) : 1 ! Mut Γ ; Π ; Φ M ⊢ val ( ) : 1 ! Pure TC-Sub
Case EC-ClickTagT: We have H ; click i d tagInst i d ( V , W ) ⇝ runClicks V ; clicks i d W ; H \mathcal{H} ; \operatorname{click}_{id}\ \operatorname{tagInst}_{id}(V,W) \leadsto\operatorname{runClicks}\ V ; \operatorname{clicks}_{id}\ W ; \mathcal{H} H ; click i d tagInst i d ( V , W ) ⇝ runClicks V ; clicks i d W ; H and
Γ ; Π ; Φ 1 ⊢ V : List Attr ‾ ( 1 ) Γ ; Π ; Φ 2 ⊢ W : List ElemInst ‾ ( 2 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tagInst i d ( V , W ) : ElemInst TV-TagI \frac{
\overline{\Gamma; \Pi; \Phi_1 \vdash V : \operatorname{List}\ \operatorname{Attr}}^{(1)}
\qquad
\overline{\Gamma; \Pi; \Phi_2 \vdash W : \operatorname{List}\ \operatorname{ElemInst}}^{(2)}
}{
\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\operatorname{tagInst}_{id}(V,W) : \operatorname{ElemInst}
}
\quad\text{TV-TagI} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tagInst i d ( V , W ) : ElemInst Γ ; Π ; Φ 1 ⊢ V : List Attr ( 1 ) Γ ; Π ; Φ 2 ⊢ W : List ElemInst ( 2 ) TV-TagI
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tagInst i d ( V , W ) : ElemInst Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ click i d tagInst i d ( V , W ) : 1 ! Mut TC-Click \frac{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\operatorname{tagInst}_{id}(V,W) : \operatorname{ElemInst}}{
\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\operatorname{click}_{id}\ \operatorname{tagInst}_{id}(V,W) : 1\ !\ \operatorname{Mut}
}
\quad\text{TC-Click} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ click i d tagInst i d ( V , W ) : 1 ! Mut Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tagInst i d ( V , W ) : ElemInst TC-Click
Γ ; Π ; Φ 1 ⊢ V : List Attr ‾ ( 1 ) Γ ; Π ; Φ 1 ⊢ runClicks V : 1 ! Mut TC-RunClicks \frac{\overline{\Gamma; \Pi; \Phi_1 \vdash V : \operatorname{List}\ \operatorname{Attr}}^{(1)}}{
\Gamma; \Pi; \Phi_1 \vdash\operatorname{runClicks}\ V : 1\ !\ \operatorname{Mut}
}
\quad\text{TC-RunClicks} Γ ; Π ; Φ 1 ⊢ runClicks V : 1 ! Mut Γ ; Π ; Φ 1 ⊢ V : List Attr ( 1 ) TC-RunClicks
Γ ; Π ; Φ 2 ⊢ W : List ElemInst ‾ ( 2 ) Γ ; Π ; Φ 2 ⊢ clicks i d W : 1 ! Mut TC-Clicks \frac{\overline{\Gamma; \Pi; \Phi_2 \vdash W : \operatorname{List}\ \operatorname{ElemInst}}^{(2)}}{
\Gamma; \Pi; \Phi_2 \vdash\operatorname{clicks}_{id}\ W : 1\ !\ \operatorname{Mut}
}
\quad\text{TC-Clicks} Γ ; Π ; Φ 2 ⊢ clicks i d W : 1 ! Mut Γ ; Π ; Φ 2 ⊢ W : List ElemInst ( 2 ) TC-Clicks
Γ ; Π ; Φ 1 ⊢ runClicks V : 1 ! Mut Γ ; Π ; Φ 2 ⊢ clicks i d W : 1 ! Mut Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ runClicks V ; clicks i d W : 1 ! Mut TC-Let \frac{
\Gamma; \Pi; \Phi_1 \vdash\operatorname{runClicks}\ V : 1\ !\ \operatorname{Mut}
\qquad
\Gamma; \Pi; \Phi_2 \vdash\operatorname{clicks}_{id}\ W : 1\ !\ \operatorname{Mut}
}{
\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\operatorname{runClicks}\ V ; \operatorname{clicks}_{id}\ W : 1\ !\ \operatorname{Mut}
}
\quad\text{TC-Let} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ runClicks V ; clicks i d W : 1 ! Mut Γ ; Π ; Φ 1 ⊢ runClicks V : 1 ! Mut Γ ; Π ; Φ 2 ⊢ clicks i d W : 1 ! Mut TC-Let
Case EC-ClickTagF: We have H ; click i d tagInst i d ′ ( V , W ) ⇝ clicks i d W ; H \mathcal{H} ; \operatorname{click}_{id}\ \operatorname{tagInst}_{id'}(V,W) \leadsto\operatorname{clicks}_{id}\ W ; \mathcal{H} H ; click i d tagInst i d ′ ( V , W ) ⇝ clicks i d W ; H and
Γ ; Π ; Φ 1 ⊢ V : List Attr ‾ ( 1 ) Γ ; Π ; Φ 2 ⊢ W : List ElemInst ‾ ( 2 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tagInst i d ( V , W ) : ElemInst TV-TagI \frac{
\overline{\Gamma; \Pi; \Phi_1 \vdash V : \operatorname{List}\ \operatorname{Attr}}^{(1)}
\qquad
\overline{\Gamma; \Pi; \Phi_2 \vdash W : \operatorname{List}\ \operatorname{ElemInst}}^{(2)}
}{
\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\operatorname{tagInst}_{id}(V,W) : \operatorname{ElemInst}
}
\quad\text{TV-TagI} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tagInst i d ( V , W ) : ElemInst Γ ; Π ; Φ 1 ⊢ V : List Attr ( 1 ) Γ ; Π ; Φ 2 ⊢ W : List ElemInst ( 2 ) TV-TagI
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tagInst i d ( V , W ) : ElemInst Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ click i d tagInst i d ( V , W ) : 1 ! Mut TC-Click \frac{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\operatorname{tagInst}_{id}(V,W) : \operatorname{ElemInst}}{
\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\operatorname{click}_{id}\ \operatorname{tagInst}_{id}(V,W) : 1\ !\ \operatorname{Mut}
}
\quad\text{TC-Click} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ click i d tagInst i d ( V , W ) : 1 ! Mut Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tagInst i d ( V , W ) : ElemInst TC-Click
By Lemma A.4 (unrestriction) on (1), we get (3) that Succ ( Φ 1 ) \operatorname{Succ}(\Phi_1) Succ ( Φ 1 ) .
By Lemma A.9 (Φ \Phi Φ -weakening) on (2) using (3), we get (4) that Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ W : List ElemInst \Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash W : \operatorname{List}\ \operatorname{ElemInst} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ W : List ElemInst .
We derive conclusion (i) as follows:
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ W : List ElemInst ‾ ( 1 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ clicks i d W : 1 ! Mut TC-Clicks \frac{\overline{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash W : \operatorname{List}\ \operatorname{ElemInst}}^{(1)}}{
\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\operatorname{clicks}_{id}\ W : 1\ !\ \operatorname{Mut}
}
\quad\text{TC-Clicks} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ clicks i d W : 1 ! Mut Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ W : List ElemInst ( 1 ) TC-Clicks
Case EC-ClickComp: We have H \mathcal{H} H ; c l i c k i d c o m p I n s t p ( ⌈ D ⌉ , V ) ⇝ c l i c k i d V \mathrm{click}_{id}\ \mathrm{compInst}_{p}(\lceil D\rceil,V) \rightsquigarrow\mathrm{click}_{id}\ V click i d compInst p (⌈ D ⌉ , V ) ⇝ click i d V ; H \mathcal{H} H and
Γ ; Π ; Φ 1 ⊢ D : Π [ p ] ( Φ 1 ⋈ Φ 2 ) [ p ] = S u c c Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ c o m p I n s t p ( ⌈ D ⌉ , V ) : E l e m I n s t T V - C o m p I \frac{\Gamma;\Pi;\Phi_{1}\vdash D:\Pi[p]\qquad(\Phi_{1}\bowtie\Phi_{2})[p]=\mathrm{Succ}}{\Gamma;\Pi;\Phi_{1}\bowtie\Phi_{2}\vdash\mathrm{compInst}_{p}(\lceil D\rceil,V):\mathrm{ElemInst}}\ \mathrm{TV\text{-}CompI} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ compInst p (⌈ D ⌉ , V ) : ElemInst Γ ; Π ; Φ 1 ⊢ D : Π [ p ] ( Φ 1 ⋈ Φ 2 ) [ p ] = Succ TV - CompI
Γ ; Π ; Φ 2 ⊢ V : E l e m I n s t \frac{\Gamma;\Pi;\Phi_{2}\vdash V:\mathrm{ElemInst}}{} Γ ; Π ; Φ 2 ⊢ V : ElemInst
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ c o m p I n s t p ( ⌈ D ⌉ , V ) : E l e m I n s t Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ c l i c k i d c o m p I n s t p ( ⌈ D ⌉ , V ) : 1 ! M u t T C - C l i c k \frac{\Gamma;\Pi;\Phi_{1}\bowtie\Phi_{2}\vdash\mathrm{compInst}_{p}(\lceil D\rceil,V):\mathrm{ElemInst}}{\Gamma;\Pi;\Phi_{1}\bowtie\Phi_{2}\vdash\mathrm{click}_{id}\ \mathrm{compInst}_{p}(\lceil D\rceil,V):1\mathbin{!}\mathrm{Mut}}\ \mathrm{TC\text{-}Click} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ click i d compInst p (⌈ D ⌉ , V ) : 1 ! Mut Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ compInst p (⌈ D ⌉ , V ) : ElemInst TC - Click
By Lemma A.6 (unrestriction) on (1), we get (3) that S u c c ( Φ 1 ) \mathrm{Succ}(\Phi_{1}) Succ ( Φ 1 ) .
By Lemma A.9 (Φ \Phi Φ -weakening) on (2) using (3), we get (4) that Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : E l e m I n s t \Gamma;\Pi;\Phi_{1}\bowtie\Phi_{2}\vdash V:\mathrm{ElemInst} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : ElemInst .
We derive conclusion (i) as follows:
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : E l e m I n s t Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ c l i c k i d V : 1 ! M u t T C - C l i c k \frac{\Gamma;\Pi;\Phi_{1}\bowtie\Phi_{2}\vdash V:\mathrm{ElemInst}}{\Gamma;\Pi;\Phi_{1}\bowtie\Phi_{2}\vdash\mathrm{click}_{id}\ V:1\mathbin{!}\mathrm{Mut}}\ \mathrm{TC\text{-}Click} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ click i d V : 1 ! Mut Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : ElemInst TC - Click
Case EC-RunAttr: Analogous to EC-ClickText.
Case EC-RunClick: We have H \mathcal{H} H ; r u n C l i c k o n C l i c k V ⇝ V ( ) \mathrm{runClick}\ \mathrm{onClick}\ V\rightsquigarrow V\ () runClick onClick V ⇝ V ( ) ; H \mathcal{H} H and
Γ ; Π ; Φ M ⊢ V : 1 → M u t 1 Γ ; Π ; Φ M ⊢ o n C l i c k V : A t t r T V - O n C l i c k \frac{\Gamma;\Pi;\Phi_{M}\vdash V:1\xrightarrow{\mathrm{Mut}}1}{\Gamma;\Pi;\Phi_{M}\vdash\mathrm{onClick}\ V:\mathrm{Attr}}\ \mathrm{TV\text{-}OnClick} Γ ; Π ; Φ M ⊢ onClick V : Attr Γ ; Π ; Φ M ⊢ V : 1 Mut 1 TV - OnClick
Γ ; Π ; Φ M ⊢ o n C l i c k V : A t t r Γ ; Π ; Φ M ⊢ r u n C l i c k o n C l i c k V : 1 ! M u t T C - R u n C l i c k \frac{\Gamma;\Pi;\Phi_{M}\vdash\mathrm{onClick}\ V:\mathrm{Attr}}{\Gamma;\Pi;\Phi_{M}\vdash\mathrm{runClick}\ \mathrm{onClick}\ V:1\mathbin{!}\mathrm{Mut}}\ \mathrm{TC\text{-}RunClick} Γ ; Π ; Φ M ⊢ runClick onClick V : 1 ! Mut Γ ; Π ; Φ M ⊢ onClick V : Attr TC - RunClick
Γ ; Π ; Φ M ⊢ V : 1 → M u t 1 Γ ; Π ; ∅ ⊢ ( ) : 1 Γ ; Π ; Φ M ⊢ V ( ) : 1 ! M u t T C - A p p \frac{\Gamma;\Pi;\Phi_{M}\vdash V:1\xrightarrow{\mathrm{Mut}}1\qquad\Gamma;\Pi;\varnothing\vdash():1}{\Gamma;\Pi;\Phi_{M}\vdash V\ ():1\mathbin{!}\mathrm{Mut}}\ \mathrm{TC\text{-}App} Γ ; Π ; Φ M ⊢ V ( ) : 1 ! Mut Γ ; Π ; Φ M ⊢ V : 1 Mut 1 Γ ; Π ; ∅ ⊢ ( ) : 1 TC - App
Case EC-UpdateText and Case EC-UpdateTag are analogous to EC-InitText and EC-InitTag respectively.
Case EC-UpdateCompT: We have
H ; u p d a t e c o m p I n s t p ( ⌈ D ⌉ , v ) ⇝ ⌈ D ⌉ ↓ p S u c c D ; H ∣ H [ p ] . r e r e n d e r ↦ f f \mathcal{H};\ \mathrm{update}\ \mathrm{compInst}_{p}(\lceil D\rceil,v)\rightsquigarrow\lceil D\rceil\downarrow^{\mathrm{Succ}}_{p}D;\ \mathcal{H}\mid\mathcal{H}[p].\mathrm{rerender}\mapsto\mathrm{ff} H ; update compInst p (⌈ D ⌉ , v ) ⇝ ⌈ D ⌉ ↓ p Succ D ; H ∣ H [ p ] . rerender ↦ ff
Γ ; Π ; Φ 1 ⊢ D : Π [ p ] ( Φ 1 ⋈ Φ 2 ) [ p ] = S u c c Γ ; Π ; Φ 2 ⊢ V : E l e m I n s t Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ c o m p I n s t p ( ⌈ D ⌉ , V ) : E l e m I n s t T V - C o m p I \frac{\Gamma;\Pi;\Phi_{1}\vdash D:\Pi[p]\qquad(\Phi_{1}\bowtie\Phi_{2})[p]=\mathrm{Succ}\qquad\Gamma;\Pi;\Phi_{2}\vdash V:\mathrm{ElemInst}}{\Gamma;\Pi;\Phi_{1}\bowtie\Phi_{2}\vdash\mathrm{compInst}_{p}(\lceil D\rceil,V):\mathrm{ElemInst}}\ \mathrm{TV\text{-}CompI} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ compInst p (⌈ D ⌉ , V ) : ElemInst Γ ; Π ; Φ 1 ⊢ D : Π [ p ] ( Φ 1 ⋈ Φ 2 ) [ p ] = Succ Γ ; Π ; Φ 2 ⊢ V : ElemInst TV - CompI
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ c o m p I n s t p ( ⌈ D ⌉ , V ) : E l e m I n s t Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ u p d a t e c o m p I n s t p ( ⌈ D ⌉ , V ) : E l e m I n s t ! M u t T C - U p d a t e \frac{\Gamma;\Pi;\Phi_{1}\bowtie\Phi_{2}\vdash\mathrm{compInst}_{p}(\lceil D\rceil,V):\mathrm{ElemInst}}{\Gamma;\Pi;\Phi_{1}\bowtie\Phi_{2}\vdash\mathrm{update}\ \mathrm{compInst}_{p}(\lceil D\rceil,V):\mathrm{ElemInst}\mathbin{!}\mathrm{Mut}}\ \mathrm{TC\text{-}Update} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ update compInst p (⌈ D ⌉ , V ) : ElemInst ! Mut Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ compInst p (⌈ D ⌉ , V ) : ElemInst TC - Update
We retain Φ N = Φ M \Phi_{N}=\Phi_{M} Φ N = Φ M , Φ H ′ = Φ H \Phi'_{H}=\Phi_{H} Φ H ′ = Φ H , and Π ′ = Π \Pi'=\Pi Π ′ = Π . Conclusions (iii) and (iv) are trivial. By premise (i-b), we have Γ ; Π ; Φ H ⊨ H ∣ H [ p ] . r e r e n d e r ↦ f f \Gamma;\Pi;\Phi_{H}\models\mathcal{H}\mid\mathcal{H}[p].\mathrm{rerender}\mapsto\mathrm{ff} Γ ; Π ; Φ H ⊨ H ∣ H [ p ] . rerender ↦ ff , satisfying conclusion (ii).
By Lemma A.4 (unrestriction) on (3), we must have (4) S u c c ( Φ 2 ) \mathrm{Succ}(\Phi_{2}) Succ ( Φ 2 ) .
By Lemma A.11 (Φ \Phi Φ -weakening) on (1) using (4), we get (5) that Γ ; Π ; Φ M ⊢ D : Π [ p ] \Gamma;\Pi;\Phi_{M}\vdash D:\Pi[p] Γ ; Π ; Φ M ⊢ D : Π [ p ] .
We derive conclusion (i) as follows, noting that Φ M ⋈ Φ M = Φ M \Phi_{M}\bowtie\Phi_{M}=\Phi_{M} Φ M ⋈ Φ M = Φ M by (4):
Γ ; Π ; Φ M ⊢ D : Π [ p ] Π [ p ] ⊆ Π [ p ] Φ M [ p ] = S u c c Γ ; Π ; Φ M ⊢ ⌈ D ⌉ ↓ p S u c c D : E l e m e n t ! M u t T C - E v a l S \frac{\Gamma;\Pi;\Phi_{M}\vdash D:\Pi[p]\qquad\Pi[p]\subseteq\Pi[p]\qquad\Phi_{M}[p]=\mathrm{Succ}}{\Gamma;\Pi;\Phi_{M}\vdash\lceil D\rceil\downarrow^{\mathrm{Succ}}_{p}D:\mathrm{Element}\mathbin{!}\mathrm{Mut}}\ \mathrm{TC\text{-}EvalS} Γ ; Π ; Φ M ⊢ ⌈ D ⌉ ↓ p Succ D : Element ! Mut Γ ; Π ; Φ M ⊢ D : Π [ p ] Π [ p ] ⊆ Π [ p ] Φ M [ p ] = Succ TC - EvalS
Case EC-UpdateCompF: Analogous to EC-ClickTagF. □ \square □
Theorem 4.7 (Preservation for ⇝ T \leadsto_{\mathsf{T}} ⇝ T ). If Γ ; Π ; Φ H ; Φ M ⊢ H ; M : E l e m I n s t ! M u t \Gamma; \Pi; \Phi_{\mathcal{H}} ; \Phi_{\mathcal{M}} \vdash\mathcal{H} ; M : \mathrm{ElemInst}\ !\ \mathrm{Mut} Γ ; Π ; Φ H ; Φ M ⊢ H ; M : ElemInst ! Mut and H ; M ⇝ T N ; H ′ \mathcal{H} ; M \leadsto_{\mathsf{T}} N ; \mathcal{H}' H ; M ⇝ T N ; H ′ , then for some Φ N \Phi_{\mathcal{N}} Φ N , Φ H ′ \Phi'_{\mathcal{H}} Φ H ′ , and Π ′ \Pi' Π ′ such that Φ M ⋈ Φ H ⊑ f r e s h Φ N ⋈ Φ H ′ \Phi_{\mathcal{M}} \bowtie\Phi_{\mathcal{H}} \sqsubseteq_{\mathrm{fresh}} \Phi_{\mathcal{N}} \bowtie\Phi'_{\mathcal{H}} Φ M ⋈ Φ H ⊑ fresh Φ N ⋈ Φ H ′ and Π ⊑ Φ N ⋈ Φ H ′ Π ′ \Pi\sqsubseteq_{\Phi_{\mathcal{N}}\bowtie\Phi'_{\mathcal{H}}} \Pi' Π ⊑ Φ N ⋈ Φ H ′ Π ′ , we have Γ ; Π ′ ; Φ H ′ ; Φ N ⊢ H ′ ; N : E l e m I n s t ! M u t \Gamma; \Pi' ; \Phi'_{\mathcal{H}} ; \Phi_{\mathcal{N}} \vdash\mathcal{H}' ; N : \mathrm{ElemInst}\ !\ \mathrm{Mut} Γ ; Π ′ ; Φ H ′ ; Φ N ⊢ H ′ ; N : ElemInst ! Mut .
Proof. By case-analysis on the derivation of the small-step judgment. (We label our premises and conclusions as in the previous proof.)
Case ET-Lift: We have
( 1 ) H ; M ⇝ N ; H ′ H ; M ⇝ T N ; H ′ E T - L i f t \frac{(1)\quad\mathcal{H} ; M \leadsto N ; \mathcal{H}'}{\mathcal{H} ; M \leadsto_{\mathsf{T}} N ; \mathcal{H}'}\ \mathrm{ET\text{-}Lift} H ; M ⇝ T N ; H ′ ( 1 ) H ; M ⇝ N ; H ′ ET - Lift
Case ET-Event: We have H ; val V ⇝ T click i d V ; update V ; H \mathcal{H} ; \operatorname{val} V \leadsto_{\mathsf{T}} \operatorname{click}_{id}\ V ; \operatorname{update}\ V ; \mathcal{H} H ; val V ⇝ T click i d V ; update V ; H and
( 1 ) Γ ; Π ; Φ M ⊢ V : E l e m I n s t Γ ; Π ; Φ M ⊢ val V : E l e m I n s t ! P u r e T C - V a l \frac{(1)\quad\Gamma; \Pi; \Phi_{\mathcal{M}} \vdash V : \mathrm{ElemInst}}{\Gamma; \Pi; \Phi_{\mathcal{M}} \vdash\operatorname{val}\ V : \mathrm{ElemInst}\ !\ \mathrm{Pure}}\ \mathrm{TC\text{-}Val} Γ ; Π ; Φ M ⊢ val V : ElemInst ! Pure ( 1 ) Γ ; Π ; Φ M ⊢ V : ElemInst TC - Val
Γ ; Π ; Φ M ⊢ val V : E l e m I n s t ! P u r e Γ ; Π ; Φ M ⊢ val V : E l e m I n s t ! M u t T C - S u b \frac{\Gamma; \Pi; \Phi_{\mathcal{M}} \vdash\operatorname{val}\ V : \mathrm{ElemInst}\ !\ \mathrm{Pure}}{\Gamma; \Pi; \Phi_{\mathcal{M}} \vdash\operatorname{val}\ V : \mathrm{ElemInst}\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Sub} Γ ; Π ; Φ M ⊢ val V : ElemInst ! Mut Γ ; Π ; Φ M ⊢ val V : ElemInst ! Pure TC - Sub
Choose Φ N = Φ M \Phi_{\mathcal{N}} = \Phi_{\mathcal{M}} Φ N = Φ M , Φ H ′ = Φ H \Phi'_{\mathcal{H}} = \Phi_{\mathcal{H}} Φ H ′ = Φ H , and Π ′ = Π \Pi' = \Pi Π ′ = Π , such that conclusions (iii) and (iv) are trivial, and conclusion (ii) is given by premise (i-a).
By Lemma A.4 (unrestriction) on (1), we get Succ ( Φ M ) \operatorname{Succ}(\Phi_{\mathcal{M}}) Succ ( Φ M ) . Then by definition, Φ M = Φ M ⋈ Φ M \Phi_{\mathcal{M}} = \Phi_{\mathcal{M}} \bowtie\Phi_{\mathcal{M}} Φ M = Φ M ⋈ Φ M .
We derive conclusion (i) as follows:
Γ ; Π ; Φ M ⊢ V : E l e m I n s t Γ ; Π ; Φ M ⊢ click i d V : 1 ! M u t T C - C l i c k Γ ; Π ; Φ M ⊢ V : E l e m I n s t Γ ; Π ; Φ M ⊢ update V : E l e m I n s t ! M u t T C - U p d a t e \frac{\Gamma; \Pi; \Phi_{\mathcal{M}} \vdash V : \mathrm{ElemInst}}{\Gamma; \Pi; \Phi_{\mathcal{M}} \vdash\operatorname{click}_{id}\ V : 1\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Click}
\qquad
\frac{\Gamma; \Pi; \Phi_{\mathcal{M}} \vdash V : \mathrm{ElemInst}}{\Gamma; \Pi; \Phi_{\mathcal{M}} \vdash\operatorname{update}\ V : \mathrm{ElemInst}\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Update} Γ ; Π ; Φ M ⊢ click i d V : 1 ! Mut Γ ; Π ; Φ M ⊢ V : ElemInst TC - Click Γ ; Π ; Φ M ⊢ update V : ElemInst ! Mut Γ ; Π ; Φ M ⊢ V : ElemInst TC - Update
Γ ; Π ; Φ M ⊢ click i d V : 1 ! M u t Γ ; Π ; Φ M ⊢ update V : E l e m I n s t ! M u t Γ ; Π ; Φ M ⊢ let _ = click i d V in update V : E l e m I n s t ! M u t T C - L e t \frac{\Gamma; \Pi; \Phi_{\mathcal{M}} \vdash\operatorname{click}_{id}\ V : 1\ !\ \mathrm{Mut}
\qquad
\Gamma; \Pi; \Phi_{\mathcal{M}} \vdash\operatorname{update}\ V : \mathrm{ElemInst}\ !\ \mathrm{Mut}}
{\Gamma; \Pi; \Phi_{\mathcal{M}} \vdash\operatorname{let}\ \_ = \operatorname{click}_{id}\ V\ \operatorname{in}\ \operatorname{update}\ V : \mathrm{ElemInst}\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Let} Γ ; Π ; Φ M ⊢ let _ = click i d V in update V : ElemInst ! Mut Γ ; Π ; Φ M ⊢ click i d V : 1 ! Mut Γ ; Π ; Φ M ⊢ update V : ElemInst ! Mut TC - Let
Consistency
To prove consistency, since Init-phase evaluation updates the heap, we must reason about heaps with respect to a partial order:
Definition A.25 (Heap ordering). Define σ ⊆ σ ′ \sigma\subseteq\sigma' σ ⊆ σ ′ to hold iff σ [ ℓ ] = σ ′ [ ℓ ] \sigma[\ell] = \sigma'[\ell] σ [ ℓ ] = σ ′ [ ℓ ] for all ℓ ∈ dom ( σ ) \ell\in\operatorname{dom}(\sigma) ℓ ∈ dom ( σ ) . Define π ⊑ π ′ \pi\sqsubseteq\pi' π ⊑ π ′ to hold iff π . s t ⊆ π ′ . s t \pi.\mathrm{st} \subseteq\pi'.\mathrm{st} π . st ⊆ π ′ . st and π . r e r e n d e r = π ′ . r e r e n d e r \pi.\mathrm{rerender} = \pi'.\mathrm{rerender} π . rerender = π ′ . rerender . Finally, define H ⊑ H ′ \mathcal{H} \sqsubseteq\mathcal{H}' H ⊑ H ′ to hold iff H [ p ] ⊑ H ′ [ p ] \mathcal{H}[p] \sqsubseteq\mathcal{H}'[p] H [ p ] ⊑ H ′ [ p ] for all p ∈ dom ( H ) p \in\operatorname{dom}(\mathcal{H}) p ∈ dom ( H ) .
We prove that initialization ⇝ p I n i t \leadsto^{\mathrm{Init}}_{p} ⇝ p Init is monotonic with respect to this heap ordering.
Lemma A.26 (Initialization monotonicity, single-step). If
Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L \Gamma; \Pi; \Phi_{\mathcal{H}} ; \Phi_{\mathcal{D}} \vdash\mathcal{H} ; D : \mathcal{L} Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L ,
L ∩ Π [ p ] = ∅ \mathcal{L} \cap\Pi[p] = \varnothing L ∩ Π [ p ] = ∅ , and
H ; D ⇝ p I n i t D ′ ; H ′ \mathcal{H} ; D \leadsto^{\mathrm{Init}}_{p} D' ; \mathcal{H}' H ; D ⇝ p Init D ′ ; H ′ ,
then H ⊑ H ′ \mathcal{H} \sqsubseteq\mathcal{H}' H ⊑ H ′ .
Proof. By definition of premise (i), we have subpremises
(i-a) Γ ; Π ; Φ D ⊢ D : L \Gamma; \Pi; \Phi_{\mathcal{D}} \vdash D : \mathcal{L} Γ ; Π ; Φ D ⊢ D : L and
(i-b) Γ ; Π ; Φ H ⊨ H \Gamma; \Pi; \Phi_{\mathcal{H}} \models\mathcal{H} Γ ; Π ; Φ H ⊨ H . We proceed by induction on the derivation of the step premise (iii). It often suffices to show H ′ = H \mathcal{H}' = \mathcal{H} H ′ = H , which entails the conclusion by reflexivity of ⊑ \sqsubseteq ⊑ .
Case EB-Let: We have
H ; M ⇝ N ; H ′ H ; let x = M in D → I n i t p let x = N in D ; H ′ (5) \frac{\mathcal{H} \mathbin{;} M \leadsto N \mathbin{;} \mathcal{H}'}{\mathcal{H} \mathbin{;} \text{let }x=M\text{ in }D \mathrel{\xrightarrow{\mathrm{Init}}_{p}} \text{let }x=N\text{ in }D \mathbin{;} \mathcal{H}'} \tag*{(5)} H ; let x = M in D Init p let x = N in D ; H ′ H ; M ⇝ N ; H ′ (5)
Γ ; Π ; Φ 1 ⊢ M : A ! P u r e Γ , x : A ; Π ; Φ 2 ⊢ D : L Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in D : L (6) \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash M:A\mathbin{!}\mathrm{Pure} \qquad\Gamma,x:A\mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash D:\mathcal{L}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \bowtie\Phi_2 \vdash\text{let }x=M\text{ in }D:\mathcal{L}} \tag*{(6)} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in D : L Γ ; Π ; Φ 1 ⊢ M : A ! Pure Γ , x : A ; Π ; Φ 2 ⊢ D : L (6)
Case EB-Val: We have H ; let x = v a l V in D → I n i t p D [ V / x ] ; H \mathcal{H} \mathbin{;} \text{let }x=\mathrm{val}\ V\text{ in }D \mathrel{\xrightarrow{\mathrm{Init}}_{p}} D[V/x]\mathbin{;} \mathcal{H} H ; let x = val V in D Init p D [ V / x ] ; H , i.e. H ′ = H \mathcal{H}' = \mathcal{H} H ′ = H and we are done.
Case EB-StateI: We have H ; let x , x s e t = u s e S t a t e ℓ V in D → I n i t p D [ V / x , s e t p ℓ / x s e t ] ; H ′ \mathcal{H} \mathbin{;} \text{let }x,x_{\mathrm{set}}=\mathrm{useState}^{\ell}\ V\text{ in }D \mathrel{\xrightarrow{\mathrm{Init}}_{p}} D[V/x,\mathrm{set}_{p}^{\ell}/x_{\mathrm{set}}]\mathbin{;} \mathcal{H}' H ; let x , x set = useState ℓ V in D Init p D [ V / x , set p ℓ / x set ] ; H ′ , where H ′ = H ∣ H [ p ] . s t [ ℓ ] ↦ V \mathcal{H}'=\mathcal{H}\mid\mathcal{H}[p].\mathrm{st}[\ell]\mapsto V H ′ = H ∣ H [ p ] . st [ ℓ ] ↦ V , and
Γ ; Π ; Φ 1 ⊢ V : A Γ , x : A , x s e t : A → M u t 1 ; Π ; Φ 2 ⊢ D : L ℓ ∉ dom ( L ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x s e t = u s e S t a t e ℓ V in D : L , ℓ : A \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1\vdash V:A \qquad\Gamma,x:A,x_{\mathrm{set}}:A \mathrel{\xrightarrow{\mathrm{Mut}}} 1\mathbin{;} \Pi\mathbin{;} \Phi_2\vdash D:\mathcal{L} \qquad\ell\notin\operatorname{dom}(\mathcal{L})}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1\bowtie\Phi_2\vdash\text{let }x,x_{\mathrm{set}}=\mathrm{useState}^{\ell}\ V\text{ in }D:\mathcal{L},\ell:A} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x set = useState ℓ V in D : L , ℓ : A Γ ; Π ; Φ 1 ⊢ V : A Γ , x : A , x set : A Mut 1 ; Π ; Φ 2 ⊢ D : L ℓ ∈ / dom ( L )
By definition of H ′ \mathcal{H}' H ′ and ⊑ \sqsubseteq ⊑ , to show H ⊑ H ′ \mathcal{H}\sqsubseteq\mathcal{H}' H ⊑ H ′ , it suffices to show that ℓ ∉ dom ( H [ p ] . s t ) \ell\notin\operatorname{dom}(\mathcal{H}[p].\mathrm{st}) ℓ ∈ / dom ( H [ p ] . st ) .
Premise (ii) says that ( L , ℓ : A ) ∩ Π [ p ] = ∅ (\mathcal{L},\ell:A)\cap\Pi[p]=\varnothing ( L , ℓ : A ) ∩ Π [ p ] = ∅ , i.e. (1) ℓ ∉ dom ( Π [ p ] ) \ell\notin\operatorname{dom}(\Pi[p]) ℓ ∈ / dom ( Π [ p ]) .
By premise (i-b), (1) entails ℓ ∉ dom ( H [ p ] . s t ) \ell\notin\operatorname{dom}(\mathcal{H}[p].\mathrm{st}) ℓ ∈ / dom ( H [ p ] . st ) , which is what we needed to show.
Case EB-StateS is impossible, since the step rule requires that ϕ = I n i t \phi=\mathrm{Init} ϕ = Init . □
Lemma A.27 (Initialization monotonicity). If
Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_H\mathbin{;} \Phi_D\vdash\mathcal{H}\mathbin{;}D:\mathcal{L} Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L ,
L ∩ Π [ p ] = ∅ \mathcal{L}\cap\Pi[p]=\varnothing L ∩ Π [ p ] = ∅ ,
p ∉ dom ( Φ H ⋈ Φ D ) p\notin\operatorname{dom}(\Phi_H\bowtie\Phi_D) p ∈ / dom ( Φ H ⋈ Φ D ) , and
H ; D → ∗ I n i t p D ′ ; H ′ \mathcal{H}\mathbin{;}D\mathrel{\xrightarrow{\ast\mathrm{Init}}_{p}}D'\mathbin{;} \mathcal{H}' H ; D ∗ Init p D ′ ; H ′ ,
then H ⊑ H ′ \mathcal{H}\sqsubseteq\mathcal{H}' H ⊑ H ′ .
Proof. By induction on the length n n n of the reduction sequence.
Base case n = 0 n=0 n = 0 : We have H ′ = H \mathcal{H}'=\mathcal{H} H ′ = H , and the conclusion is trivial.
Inductive case n + 1 n+1 n + 1 : We have a single step (1) H 0 ; D 0 → I n i t p D 1 ; H 1 \mathcal{H}_0\mathbin{;}D_0\mathrel{\xrightarrow{\mathrm{Init}}_{p}}D_1\mathbin{;}\mathcal{H}_1 H 0 ; D 0 Init p D 1 ; H 1 and a sequence (2) H 1 ; D 1 → ∗ I n i t p D 2 ; H 2 \mathcal{H}_1\mathbin{;}D_1\mathrel{\xrightarrow{\ast\mathrm{Init}}_{p}}D_2\mathbin{;}\mathcal{H}_2 H 1 ; D 1 ∗ Init p D 2 ; H 2 of length n n n . (We want to show H 0 ⊑ H 2 \mathcal{H}_0\sqsubseteq\mathcal{H}_2 H 0 ⊑ H 2 .)
By Lemma A.26 (single-step monotonicity) on (1) and premises (i) and (ii), we get (3) that H 0 ⊑ H 1 \mathcal{H}_0\sqsubseteq\mathcal{H}_1 H 0 ⊑ H 1 .
By Theorem A.22 (preservation) on (1) and premises (i)-(iii), we get some Φ H ′ \Phi'_H Φ H ′ and Π ′ \Pi' Π ′ with: (4) Γ ; Π ′ ; Φ H ′ ; Φ D ⊢ H ; D 1 \Gamma\mathbin{;} \Pi'\mathbin{;} \Phi'_H\mathbin{;} \Phi_D\vdash\mathcal{H}\mathbin{;}D_1 Γ ; Π ′ ; Φ H ′ ; Φ D ⊢ H ; D 1 , (5) Φ H ′ ⋈ Φ D = Φ H ⋈ Φ D \Phi'_H\bowtie\Phi_D=\Phi_H\bowtie\Phi_D Φ H ′ ⋈ Φ D = Φ H ⋈ Φ D , and (6) L ′ ⊎ Π ′ [ p ] = L ⊎ Π [ p ] \mathcal{L}'\uplus\Pi'[p]=\mathcal{L}\uplus\Pi[p] L ′ ⊎ Π ′ [ p ] = L ⊎ Π [ p ] .
(5) and premise (iii) entail (7) that p ∉ dom ( Φ H ′ ⋈ Φ D ) p\notin\operatorname{dom}(\Phi'_H\bowtie\Phi_D) p ∈ / dom ( Φ H ′ ⋈ Φ D ) .
(6) implies (8) that L ′ ∩ Π ′ [ p ] = ∅ \mathcal{L}'\cap\Pi'[p]=\varnothing L ′ ∩ Π ′ [ p ] = ∅ .
Now by inductive hypothesis on (2), (4), (7), and (8), we get (9) that H 1 ⊑ H 2 \mathcal{H}_1\sqsubseteq\mathcal{H}_2 H 1 ⊑ H 2 .
The conclusion is given by (3), (9), and transitivity of ⊑ \sqsubseteq ⊑ . □
We next show that steps which do not change the heap H \mathcal{H} H (but may read from H \mathcal{H} H ) are preserved under a greater heap H ′ ⊒ H \mathcal{H}' \sqsupseteq\mathcal{H} H ′ ⊒ H .
Lemma A.28 (Heap lifting, computations). If
(i) H ; M ⇝ N ; H \mathcal{H} ; M \leadsto N ; \mathcal{H} H ; M ⇝ N ; H and
(ii) H ⊑ H ′ \mathcal{H} \sqsubseteq\mathcal{H}' H ⊑ H ′ ,
then H ′ ; M ⇝ N ; H ′ \mathcal{H}' ; M \leadsto N ; \mathcal{H}' H ′ ; M ⇝ N ; H ′ .
Proof. By mutual induction on the derivation of the step judgment with Theorem A.29.
Case EC-Let: We have
H ; M ⇝ M ′ ; H H ; l e t x = M i n N ⇝ l e t x = M ′ i n N ; H E C - L e t \frac{\mathcal{H} ; M \leadsto M' ; \mathcal{H}}{\mathcal{H} ; \mathop{\mathrm{let}} x = M \mathop{\mathrm{in}} N \leadsto\mathop{\mathrm{let}} x = M' \mathop{\mathrm{in}} N ; \mathcal{H}} \ \mathrm{EC\text{-}Let} H ; let x = M in N ⇝ let x = M ′ in N ; H H ; M ⇝ M ′ ; H EC - Let
By inductive hypothesis on (1) and premise (ii), we get (2) that H ′ ; M ⇝ M ′ ; H ′ \mathcal{H}' ; M \leadsto M' ; \mathcal{H}' H ′ ; M ⇝ M ′ ; H ′ .
We derive the conclusion as follows:
H ′ ; M ⇝ M ′ ; H ′ H ′ ; l e t x = M i n N ⇝ l e t x = M ′ i n N ; H ′ E C - L e t \frac{\mathcal{H}' ; M \leadsto M' ; \mathcal{H}'}{\mathcal{H}' ; \mathop{\mathrm{let}} x = M \mathop{\mathrm{in}} N \leadsto\mathop{\mathrm{let}} x = M' \mathop{\mathrm{in}} N ; \mathcal{H}'} \ \mathrm{EC\text{-}Let} H ′ ; let x = M in N ⇝ let x = M ′ in N ; H ′ H ′ ; M ⇝ M ′ ; H ′ EC - Let
Case EC-Eval: We have
H ; D ⇝ φ p D ′ ; H H ; [ D 0 ] ⇝ φ p [ D 0 ] ⇝ φ p D ′ ; H E C - E v a l \frac{\mathcal{H} ; D \mathrel{\leadsto_{\varphi_p}} D' ; \mathcal{H}}{\mathcal{H} ; [D_0] \mathrel{\leadsto_{\varphi_p}} [D_0] \mathrel{\leadsto_{\varphi_p}} D' ; \mathcal{H}} \ \mathrm{EC\text{-}Eval} H ; [ D 0 ] ⇝ φ p [ D 0 ] ⇝ φ p D ′ ; H H ; D ⇝ φ p D ′ ; H EC - Eval
By mutual inductive hypothesis on (1) and premise (ii), we get (2) that H ′ ; D ⇝ φ p D ′ ; H ′ \mathcal{H}' ; D \mathrel{\leadsto_{\varphi_p}} D' ; \mathcal{H}' H ′ ; D ⇝ φ p D ′ ; H ′ .
We derive the conclusion as follows:
H ′ ; D ⇝ φ p D ′ ; H ′ H ′ ; [ D 0 ] ⇝ φ p [ D 0 ] ⇝ φ p D ′ ; H ′ E C - E v a l \frac{\mathcal{H}' ; D \mathrel{\leadsto_{\varphi_p}} D' ; \mathcal{H}'}{\mathcal{H}' ; [D_0] \mathrel{\leadsto_{\varphi_p}} [D_0] \mathrel{\leadsto_{\varphi_p}} D' ; \mathcal{H}'} \ \mathrm{EC\text{-}Eval} H ′ ; [ D 0 ] ⇝ φ p [ D 0 ] ⇝ φ p D ′ ; H ′ H ′ ; D ⇝ φ p D ′ ; H ′ EC - Eval
Case EC-AppSet: We have H ; s e t p ℓ V ⇝ v a l ( ) ; H ′ ′ \mathcal{H} ; \mathop{\mathrm{set}}\nolimits^{\ell}_{p} V \leadsto\mathop{\mathrm{val}} () ; \mathcal{H}'' H ; set p ℓ V ⇝ val ( ) ; H ′′ , where H ′ ′ = H ∣ H [ p ] . s t [ ℓ ] ↦ V \mathcal{H}'' = \mathcal{H} \mid\mathcal{H}[p].\mathrm{st}[\ell] \mapsto V H ′′ = H ∣ H [ p ] . st [ ℓ ] ↦ V and H [ p ] . r e r e n d e r ↦ t t \mathcal{H}[p].\mathrm{rerender} \mapsto\mathrm{tt} H [ p ] . rerender ↦ tt .
By the step premise, we must have H ′ ′ = H \mathcal{H}'' = \mathcal{H} H ′′ = H , i.e. H [ p ] . s t [ ℓ ] = V \mathcal{H}[p].\mathrm{st}[\ell] = V H [ p ] . st [ ℓ ] = V and H [ p ] . r e r e n d e r = t t \mathcal{H}[p].\mathrm{rerender} = \mathrm{tt} H [ p ] . rerender = tt .
By premise (ii), we therefore also have H ′ [ p ] . s t [ ℓ ] = V \mathcal{H}'[p].\mathrm{st}[\ell] = V H ′ [ p ] . st [ ℓ ] = V and H ′ [ p ] . r e r e n d e r = t t \mathcal{H}'[p].\mathrm{rerender} = \mathrm{tt} H ′ [ p ] . rerender = tt .
We can reapply EC-AppSet using H ′ \mathcal{H}' H ′ , getting that H ′ ; s e t p ℓ V ⇝ v a l ( ) ; H ′ \mathcal{H}' ; \mathop{\mathrm{set}}\nolimits^{\ell}_{p} V \leadsto\mathop{\mathrm{val}} () ; \mathcal{H}' H ′ ; set p ℓ V ⇝ val ( ) ; H ′ , which satisfies the conclusion.
Case EC-InitComp: We have H ; i n i t c o m p o n e n t { D } ⇝ [ D ] ↓ p I n i t D ; H ′ ′ \mathcal{H} ; \mathop{\mathrm{init\ component}}\{D\} \leadsto[D] \mathrel{\downarrow^{\mathrm{Init}}_{p}} D ; \mathcal{H}'' H ; init component { D } ⇝ [ D ] ↓ p Init D ; H ′′ , where p p p is fresh and H ′ ′ = H , p ↦ { s t : ∅ , r e r e n d e r : f f } \mathcal{H}'' = \mathcal{H}, p \mapsto\{\mathrm{st} : \varnothing,\mathrm{rerender} : \mathrm{ff}\} H ′′ = H , p ↦ { st : ∅ , rerender : ff } .
To satisfy the step premise, we must have H ′ ′ = H \mathcal{H}'' = \mathcal{H} H ′′ = H . However, this is impossible , since p p p must be fresh, i.e. p ∉ dom ( H ) p \notin\operatorname{dom}(\mathcal{H}) p ∈ / dom ( H ) . Therefore, this case holds vacuously.
Case EC-Val: We have H ; l e t x = v a l V i n M ⇝ M [ V / x ] ; H \mathcal{H} ; \mathop{\mathrm{let}} x = \mathop{\mathrm{val}} V \mathop{\mathrm{in}} M \leadsto M[V/x] ; \mathcal{H} H ; let x = val V in M ⇝ M [ V / x ] ; H .
All other cases can be shown analogously to EC-Val.
Lemma A.29 (Heap lifting, bodies). If
(i) H ; D ⇝ S u c c p D ′ ; H \mathcal{H};D \mathrel{\overset{\mathrm{Succ}}{\leadsto}_{p}} D';\mathcal{H} H ; D ⇝ Succ p D ′ ; H and (ii) H ⊑ H ′ \mathcal{H}\sqsubseteq\mathcal{H}' H ⊑ H ′ , then H ′ ; D ⇝ S u c c p D ′ ; H ′ \mathcal{H}';D \mathrel{\overset{\mathrm{Succ}}{\leadsto}_{p}} D';\mathcal{H}' H ′ ; D ⇝ Succ p D ′ ; H ′ .
Proof. By mutual induction on the derivation of the step judgment with Theorem A.28.
Case EB-Let: We have
H ; M ⇝ N ; H H ; let x = M in D ⇝ S u c c p let x = N in D ; H EB-Let \frac{\mathcal{H};M \leadsto N;\mathcal{H}}{\mathcal{H};\operatorname{let}x=M\operatorname{in}D \mathrel{\overset{\mathrm{Succ}}{\leadsto}_{p}} \operatorname{let}x=N\operatorname{in}D;\mathcal{H}}
\quad\text{EB-Let} H ; let x = M in D ⇝ Succ p let x = N in D ; H H ; M ⇝ N ; H EB-Let
By mutual inductive hypothesis on (1) and premise (ii), we get (2) that H ′ ; M ⇝ N ; H ′ \mathcal{H}';M\leadsto N;\mathcal{H}' H ′ ; M ⇝ N ; H ′ .
We derive the conclusion as follows:
H ′ ; M ⇝ N ; H ′ H ′ ; let x = M in D ⇝ S u c c p let x = N in D ; H ′ EB-Let \frac{\mathcal{H}';M\leadsto N;\mathcal{H}'}{\mathcal{H}';\operatorname{let}x=M\operatorname{in}D \mathrel{\overset{\mathrm{Succ}}{\leadsto}_{p}} \operatorname{let}x=N\operatorname{in}D;\mathcal{H}'}
\quad\text{EB-Let} H ′ ; let x = M in D ⇝ Succ p let x = N in D ; H ′ H ′ ; M ⇝ N ; H ′ EB-Let
Case EB-Ret: We have H ; let x = val V in D ⇝ ϕ p D [ V / x ] ; H \mathcal{H};\operatorname{let}x=\operatorname{val}V\operatorname{in}D\mathrel{\overset{\phi}{\leadsto}_{p}}D[V/x];\mathcal{H} H ; let x = val V in D ⇝ ϕ p D [ V / x ] ; H .
Case EB-StateI: We have H ; let x , x s e t = useState ℓ V in D ⇝ I n i t p D [ V / x , set p ℓ / x s e t ] ; H ′ ′ , where H ′ ′ = H ∣ H [ p ] . s t [ ℓ ] ↦ V \mathcal{H};\operatorname{let}x,x_{\mathrm{set}}=\operatorname{useState}^{\ell}V\operatorname{in}D\mathrel{\overset{\mathrm{Init}}{\leadsto}_{p}}D[V/x,\operatorname{set}^{\ell}_{p}/x_{\mathrm{set}}];\mathcal{H}'',\text{ where }\mathcal{H}''=\mathcal{H}\mid\mathcal{H}[p].\mathrm{st}[\ell]\mapsto V H ; let x , x set = useState ℓ V in D ⇝ Init p D [ V / x , set p ℓ / x set ] ; H ′′ , where H ′′ = H ∣ H [ p ] . st [ ℓ ] ↦ V .
By the step premise, we also must have H ′ ′ = H \mathcal{H}''=\mathcal{H} H ′′ = H , i.e. H [ p ] . s t [ ℓ ] = V \mathcal{H}[p].\mathrm{st}[\ell]=V H [ p ] . st [ ℓ ] = V .
Note: this fact means that the configuration is inherently ill-typed, since our type system rules out re-initialization. Since this lemma does not concern typing, we must still show this case (and it is easy to do so).
By premise (ii), we also have H ′ [ p ] . s t [ ℓ ] = V \mathcal{H}'[p].\mathrm{st}[\ell]=V H ′ [ p ] . st [ ℓ ] = V .
We can reapply EB-StateI using H ′ \mathcal{H}' H ′ , getting that H ′ ; let x , x s e t = useState ℓ V in D ⇝ I n i t p D [ V / x , set p ℓ / x s e t ] ; H ′ \mathcal{H}';\operatorname{let}x,x_{\mathrm{set}}=\operatorname{useState}^{\ell}V\operatorname{in}D\mathrel{\overset{\mathrm{Init}}{\leadsto}_{p}}D[V/x,\operatorname{set}^{\ell}_{p}/x_{\mathrm{set}}];\mathcal{H}' H ′ ; let x , x set = useState ℓ V in D ⇝ Init p D [ V / x , set p ℓ / x set ] ; H ′ , which satisfies the conclusion.
Case EB-StateS: We have
H ; let x , x s e t = useState ℓ V in D ⇝ S u c c p D [ H [ p ] . s t [ ℓ ] / x , set p ℓ / x s e t ] ; H \mathcal{H};\operatorname{let}x,x_{\mathrm{set}}=\operatorname{useState}^{\ell}V\operatorname{in}D\mathrel{\overset{\mathrm{Succ}}{\leadsto}_{p}}D[\mathcal{H}[p].\mathrm{st}[\ell]/x,\operatorname{set}^{\ell}_{p}/x_{\mathrm{set}}];\mathcal{H} H ; let x , x set = useState ℓ V in D ⇝ Succ p D [ H [ p ] . st [ ℓ ] / x , set p ℓ / x set ] ; H
To show the conclusion (via EB-StateS), it suffices to show that H ′ [ p ] . s t [ ℓ ] = H [ p ] . s t [ ℓ ] \mathcal{H}'[p].\mathrm{st}[\ell]=\mathcal{H}[p].\mathrm{st}[\ell] H ′ [ p ] . st [ ℓ ] = H [ p ] . st [ ℓ ] .
This is given by definition of H ⊑ H ′ \mathcal{H}\sqsubseteq\mathcal{H}' H ⊑ H ′ , and we are done.
We now proceed to our main proofs of component consistency.
Lemma A.30 (Component consistency, single-step). If
(i) Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L \Gamma;\Pi;\Phi_{\mathcal{H}};\Phi_D\vdash\mathcal{H};D:\mathcal{L} Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L and (ii) H ; D ⇝ ϕ p D ′ ; H ′ \mathcal{H};D\mathrel{\overset{\phi}{\leadsto}_{p}}D';\mathcal{H}' H ; D ⇝ ϕ p D ′ ; H ′ ,
then H ′ ; D ⇝ S u c c p D ′ ; H ′ \mathcal{H}';D\mathrel{\overset{\mathrm{Succ}}{\leadsto}_{p}}D';\mathcal{H}' H ′ ; D ⇝ Succ p D ′ ; H ′ .
Proof. By definition of premise (i), we have subpremises (i-a) Γ ; Π ; Φ D ⊢ D : L \Gamma;\Pi;\Phi_D\vdash D:\mathcal{L} Γ ; Π ; Φ D ⊢ D : L and (i-b) Γ ; Π ; Φ H ⊨ H \Gamma;\Pi;\Phi_{\mathcal{H}}\vDash\mathcal{H} Γ ; Π ; Φ H ⊨ H . We proceed by case-analysis on the derivation of the step judgment.
Case EB-Let: We have
H ; M ⇝ N ; H ′ H ; let x = M in D ⇝ p ϕ let x = N in D ; H ′ EB-Let \frac{\mathcal{H};\,M \leadsto N;\,\mathcal{H}'}{\mathcal{H};\,\text{let }x=M\text{ in }D \mathrel{\leadsto^{\phi}_{p}} \text{let }x=N\text{ in }D;\,\mathcal{H}'}\quad\text{EB-Let} H ; let x = M in D ⇝ p ϕ let x = N in D ; H ′ H ; M ⇝ N ; H ′ EB-Let
Γ ; Π ; Φ 1 ⊢ M : A ! P u r e Γ , x : A ; Π ; Φ 2 ⊢ D : L Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in D : L TB-Let \frac{\Gamma;\,\Pi;\,\Phi_{1}\vdash M:A\mathbin{!}\mathrm{Pure}\qquad\Gamma,x:A;\,\Pi;\,\Phi_{2}\vdash D:L}{\Gamma;\,\Pi;\,\Phi_{1}\bowtie\Phi_{2}\vdash\text{let }x=M\text{ in }D:L}\quad\text{TB-Let} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in D : L Γ ; Π ; Φ 1 ⊢ M : A ! Pure Γ , x : A ; Π ; Φ 2 ⊢ D : L TB-Let
By Theorem A.21 (pure preservation) on (1) and (2), we get that H ′ = H \mathcal{H}'=\mathcal{H} H ′ = H .
We derive the conclusion as follows:
H ′ ; M ⇝ N ; H ′ H ′ ; let x = M in D ⇝ p S u c c let x = N in D ; H ′ EB-Let \frac{\mathcal{H}';\,M\leadsto N;\,\mathcal{H}'}{\mathcal{H}';\,\text{let }x=M\text{ in }D\mathrel{\leadsto^{\mathrm{Succ}}_{p}}\text{let }x=N\text{ in }D;\,\mathcal{H}'}\quad\text{EB-Let} H ′ ; let x = M in D ⇝ p Succ let x = N in D ; H ′ H ′ ; M ⇝ N ; H ′ EB-Let
Case EB-Ret: We have H ; let x = val V in D ⇝ p ϕ D [ V / x ] ; H \mathcal{H};\,\text{let }x=\text{val }V\text{ in }D\mathrel{\leadsto^{\phi}_{p}}D[V/x];\,\mathcal{H} H ; let x = val V in D ⇝ p ϕ D [ V / x ] ; H .
Case EB-StateI: We have H ; let x , x s e t = u s e S t a t e ℓ V in D ⇝ p I n i t D [ V / x , s e t p ℓ / x s e t ] ; H ′ \mathcal{H};\,\text{let }x,x_{\mathrm{set}}=\mathrm{useState}^{\ell}\,V\text{ in }D\mathrel{\leadsto^{\mathrm{Init}}_{p}}D[V/x,\mathrm{set}^{\ell}_{p}/x_{\mathrm{set}}];\,\mathcal{H}' H ; let x , x set = useState ℓ V in D ⇝ p Init D [ V / x , set p ℓ / x set ] ; H ′ , where H ′ = H ∣ H [ p ] . s t [ ℓ ] ↦ V \mathcal{H}'=\mathcal{H}\mid\mathcal{H}[p].\mathrm{st}[\ell]\mapsto V H ′ = H ∣ H [ p ] . st [ ℓ ] ↦ V .
H ′ ; let x , x s e t = u s e S t a t e ℓ V in D ⇝ p S u c c D [ V / x , s e t p ℓ / x s e t ] ; H ′ \mathcal{H}';\,\text{let }x,x_{\mathrm{set}}=\mathrm{useState}^{\ell}\,V\text{ in }D\mathrel{\leadsto^{\mathrm{Succ}}_{p}}D[V/x,\mathrm{set}^{\ell}_{p}/x_{\mathrm{set}}];\,\mathcal{H}' H ′ ; let x , x set = useState ℓ V in D ⇝ p Succ D [ V / x , set p ℓ / x set ] ; H ′
which satisfies the conclusion.
Case EB-StateS: We have H ; let x , x s e t = u s e S t a t e ℓ V in D ⇝ p S u c c D [ W / x , s e t p ℓ / x s e t ] ; H \mathcal{H};\,\text{let }x,x_{\mathrm{set}}=\mathrm{useState}^{\ell}\,V\text{ in }D\mathrel{\leadsto^{\mathrm{Succ}}_{p}}D[W/x,\mathrm{set}^{\ell}_{p}/x_{\mathrm{set}}];\,\mathcal{H} H ; let x , x set = useState ℓ V in D ⇝ p Succ D [ W / x , set p ℓ / x set ] ; H , where W = H [ p ] . s t [ ℓ ] W=\mathcal{H}[p].\mathrm{st}[\ell] W = H [ p ] . st [ ℓ ] .
Theorem 4.9 (Component consistency). If Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L \Gamma;\,\Pi;\,\Phi_{\mathcal{H}};\,\Phi_{D}\vdash\mathcal{H};\,D:L Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L with L ∩ Π [ p ] = ∅ L\cap\Pi[p]=\varnothing L ∩ Π [ p ] = ∅ , p ∉ dom ( Φ H ⋈ Φ D ) p\notin\operatorname{dom}(\Phi_{\mathcal{H}}\bowtie\Phi_{D}) p ∈ / dom ( Φ H ⋈ Φ D ) , and H ; D ⇝ p ∗ ϕ v a l V ; H ′ \mathcal{H};\,D\mathrel{\leadsto^{*\,\phi}_{p}}\mathrm{val}\,V;\,\mathcal{H}' H ; D ⇝ p ∗ ϕ val V ; H ′ , then H ′ ; D \mathcal{H}';\,D H ′ ; D is consistent with V V V at p p p .
Proof. We label the premises as follows:
(i) Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L \Gamma;\,\Pi;\,\Phi_{\mathcal{H}};\,\Phi_{D}\vdash\mathcal{H};\,D:L Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L ,
(ii) L ∩ Π [ p ] = ∅ L\cap\Pi[p]=\varnothing L ∩ Π [ p ] = ∅ ,
(iii) p ∉ dom ( Φ H ⋈ Φ D ) p\notin\operatorname{dom}(\Phi_{\mathcal{H}}\bowtie\Phi_{D}) p ∈ / dom ( Φ H ⋈ Φ D ) , and
(iv) H ; D ⇝ p ∗ ϕ v a l V ; H ′ \mathcal{H};\,D\mathrel{\leadsto^{*\,\phi}_{p}}\mathrm{val}\,V;\,\mathcal{H}' H ; D ⇝ p ∗ ϕ val V ; H ′ .
We proceed by induction on the length n n n of the reduction sequence.
Base case n = 0 n=0 n = 0 : We have H ; v a l V ⇝ p ∗ ϕ v a l V ; H \mathcal{H};\,\mathrm{val}\,V\mathrel{\leadsto^{*\,\phi}_{p}}\mathrm{val}\,V;\,\mathcal{H} H ; val V ⇝ p ∗ ϕ val V ; H .
Inductive case n + 1 n+1 n + 1 : We have a single step (1) H 0 ; D 0 ⇝ p I n i t D 1 ; H 1 \mathcal{H}_{0};\,D_{0}\mathrel{\leadsto^{\mathrm{Init}}_{p}}D_{1};\,\mathcal{H}_{1} H 0 ; D 0 ⇝ p Init D 1 ; H 1 and a sequence (2) H 1 ; D 1 ⇝ p ∗ I n i t v a l V ; H 2 \mathcal{H}_{1};\,D_{1}\mathrel{\leadsto^{*\mathrm{Init}}_{p}}\mathrm{val}\,V;\,\mathcal{H}_{2} H 1 ; D 1 ⇝ p ∗ Init val V ; H 2 of length n n n . (We want to show H 2 ; D 0 ⇝ p ∗ S u c c v a l V ; H 2 \mathcal{H}_{2};\,D_{0}\mathrel{\leadsto^{*\mathrm{Succ}}_{p}}\mathrm{val}\,V;\,\mathcal{H}_{2} H 2 ; D 0 ⇝ p ∗ Succ val V ; H 2 .)
(3) Γ ; Π ′ ; Φ H ′ ; Φ D ⊢ H 1 ; D 1 : L ′ \Gamma;\,\Pi';\,\Phi'_{\mathcal{H}};\,\Phi_{D}\vdash\mathcal{H}_{1};\,D_{1}:L' Γ ; Π ′ ; Φ H ′ ; Φ D ⊢ H 1 ; D 1 : L ′ ,
(4) Φ D ⋈ Φ H ′ = Φ D ⋈ Φ H \Phi_{D}\bowtie\Phi'_{\mathcal{H}}=\Phi_{D}\bowtie\Phi_{\mathcal{H}} Φ D ⋈ Φ H ′ = Φ D ⋈ Φ H , and
(5) L ′ ⊎ Π ′ [ p ] = L ⊎ Π [ p ] \mathcal{L}' \uplus\Pi'[p] = \mathcal{L} \uplus\Pi[p] L ′ ⊎ Π ′ [ p ] = L ⊎ Π [ p ] .
(4) and premise (i) entail (6) that p ∉ dom ( Φ H ′ ⋈ Φ D ) p \notin\operatorname{dom}(\Phi'_H \bowtie\Phi_D) p ∈ / dom ( Φ H ′ ⋈ Φ D ) .
(5) implies (7) that L ′ ∩ Π ′ [ p ] = ∅ \mathcal{L}' \cap\Pi'[p] = \varnothing L ′ ∩ Π ′ [ p ] = ∅ .
By inductive hypothesis on (2), (3), (6), and (7), we get (8) H 2 ; D 1 ⇝ p ∗ Succ v a l V ; H 2 \mathcal{H}_2 \mathbin{;} D_1 \mathrel{\mathop{\leadsto}\limits^{*}_{p}} \operatorname{Succ}_{\mathrm{val}}\ V \mathbin{;} \mathcal{H}_2 H 2 ; D 1 p ⇝ ∗ Succ val V ; H 2 .
By Lemma A.27 (initialization monotonicity) on (2), (3), (5), and (6), we get (9) that H 1 ⊑ H 2 \mathcal{H}_1 \sqsubseteq\mathcal{H}_2 H 1 ⊑ H 2 .
By Lemma A.30 (single-step consistency) on (1) and premise (i), we get (10) that H 1 ; D 0 ⇝ p S u c c D 1 ; H 1 \mathcal{H}_1 \mathbin{;} D_0 \mathrel{\mathop{\leadsto}\limits^{\mathrm{Succ}}_{p}} D_1 \mathbin{;} \mathcal{H}_1 H 1 ; D 0 p ⇝ Succ D 1 ; H 1 .
By Lemma A.29 (heap lifting) on (10) using (9), we get (11) that H 2 ; D 0 ⇝ p S u c c D 1 ; H 2 \mathcal{H}_2 \mathbin{;} D_0 \mathrel{\mathop{\leadsto}\limits^{\mathrm{Succ}}_{p}} D_1 \mathbin{;} \mathcal{H}_2 H 2 ; D 0 p ⇝ Succ D 1 ; H 2 .
We conclude by (11) and (8) that H 2 ; D 0 ⇝ p ∗ S u c c val V ; H 2 \mathcal{H}_2 \mathbin{;} D_0 \mathrel{\mathop{\leadsto}\limits^{*\mathrm{Succ}}_{p}} \operatorname{val}\ V \mathbin{;} \mathcal{H}_2 H 2 ; D 0 p ⇝ ∗ Succ val V ; H 2 , and we are done.
Translation Proofs
Type Preservation
We begin with a couple of lemmas which let us type the results of the δ \delta δ -function:
Lemma B.1 (Flag typing). If
(i) Γ ; Π ⊨ p δ : L \Gamma\mathbin{;} \Pi\models_p \delta: L Γ ; Π ⊨ p δ : L and
(ii) Π ; ∅ ⊢ ϱ \Pi\mathbin{;} \varnothing\vdash\varrho Π ; ∅ ⊢ ϱ ,
then Γ ; ⟦ Π ⟧ ϱ ⊢ δ ( p , ϱ ) : Ref Bool \Gamma\mathbin{;} \llbracket\Pi\rrbracket_\varrho\vdash\delta(p,\varrho) : \operatorname{Ref}\ \operatorname{Bool} Γ ; [ [ Π ] ] ϱ ⊢ δ ( p , ϱ ) : Ref Bool .
Proof. By case-analysis on premise (i), either:
(a) flag ↦ x ∈ δ \operatorname{flag} \mapsto x \in\delta flag ↦ x ∈ δ and x : Ref Bool ∈ Γ x : \operatorname{Ref}\ \operatorname{Bool} \in\Gamma x : Ref Bool ∈ Γ , or
(b) flag ∉ dom ( δ ) \operatorname{flag} \notin\operatorname{dom}(\delta) flag ∈ / dom ( δ ) and p ∈ dom ( Π ) p \in\operatorname{dom}(\Pi) p ∈ dom ( Π ) .
Case (a):
By definition, δ ( p , ϱ ) = x \delta(p,\varrho) = x δ ( p , ϱ ) = x .
From (a), we also have that x : Ref Bool ∈ Γ x : \operatorname{Ref}\ \operatorname{Bool} \in\Gamma x : Ref Bool ∈ Γ , i.e. (1) δ ( p , ϱ ) : Ref Bool ∈ Γ \delta(p,\varrho) : \operatorname{Ref}\ \operatorname{Bool} \in\Gamma δ ( p , ϱ ) : Ref Bool ∈ Γ .
We derive the conclusion as follows:
δ ( p , ϱ ) : Ref Bool ∈ Γ Γ ; ⟦ Π ⟧ ϱ ⊢ δ ( p , ϱ ) : Ref Bool T V - V a r (1) \frac{\delta(p,\varrho) : \operatorname{Ref}\ \operatorname{Bool} \in\Gamma}{\Gamma\mathbin{;} \llbracket\Pi\rrbracket_\varrho\vdash\delta(p,\varrho) : \operatorname{Ref}\ \operatorname{Bool}}\quad\mathrm{TV\text{-}Var}\qquad\text{(1)} Γ ; [ [ Π ] ] ϱ ⊢ δ ( p , ϱ ) : Ref Bool δ ( p , ϱ ) : Ref Bool ∈ Γ TV - Var (1)
Case (b):
By definition, δ ( p , ϱ ) = ϱ ( p ) \delta(p,\varrho) = \varrho(p) δ ( p , ϱ ) = ϱ ( p ) .
By premise (ii), since p ∈ dom ( Π ) p \in\operatorname{dom}(\Pi) p ∈ dom ( Π ) , we have that ϱ ( p ) \varrho(p) ϱ ( p ) is well-defined. Then by definition of ⟦ Π ⟧ ϱ \llbracket\Pi\rrbracket_\varrho [ [ Π ] ] ϱ , we get that ϱ ( p ) : Bool ∈ ⟦ Π ⟧ ϱ \varrho(p) : \operatorname{Bool} \in\llbracket\Pi\rrbracket_\varrho ϱ ( p ) : Bool ∈ [ [ Π ] ] ϱ , i.e. (2) δ ( p , ϱ ) : Bool ∈ ⟦ Π ⟧ ϱ \delta(p,\varrho) : \operatorname{Bool} \in\llbracket\Pi\rrbracket_\varrho δ ( p , ϱ ) : Bool ∈ [ [ Π ] ] ϱ .
We derive the conclusion as follows:
δ ( p , ϱ ) : Bool ∈ ⟦ Π ⟧ ϱ Γ ; ⟦ Π ⟧ ϱ ⊢ δ ( p , ϱ ) : Ref Bool T V - L o c (2) \frac{\delta(p,\varrho) : \operatorname{Bool} \in\llbracket\Pi\rrbracket_\varrho}{\Gamma\mathbin{;} \llbracket\Pi\rrbracket_\varrho\vdash\delta(p,\varrho) : \operatorname{Ref}\ \operatorname{Bool}}\quad\mathrm{TV\text{-}Loc}\qquad\text{(2)} Γ ; [ [ Π ] ] ϱ ⊢ δ ( p , ϱ ) : Ref Bool δ ( p , ϱ ) : Bool ∈ [ [ Π ] ] ϱ TV - Loc (2)
Lemma B.2 (Label typing). If
(i) Γ ; Π ⊨ p δ : ( L , ℓ : A ) \Gamma\mathbin{;} \Pi\models_p \delta: (L,\ell: A) Γ ; Π ⊨ p δ : ( L , ℓ : A ) and
(ii) Π ; ∅ ⊢ ϱ \Pi\mathbin{;} \varnothing\vdash\varrho Π ; ∅ ⊢ ϱ ,
then Γ ; ⟦ Π ⟧ ϱ ⊢ δ ( p , ℓ , ϱ ) : Ref ⟦ A ⟧ \Gamma\mathbin{;} \llbracket\Pi\rrbracket_\varrho\vdash\delta(p,\ell,\varrho) : \operatorname{Ref}\ \llbracket A \rrbracket Γ ; [ [ Π ] ] ϱ ⊢ δ ( p , ℓ , ϱ ) : Ref [ [ A ] ] .
Proof. By case-analysis on premise (i), either:
(a) x ↦ ℓ ∈ δ x \mapsto\ell\in\delta x ↦ ℓ ∈ δ and x : Ref ⟦ A ⟧ ∈ Γ x : \operatorname{Ref}\ \llbracket A \rrbracket\in\Gamma x : Ref [ [ A ] ] ∈ Γ , or (b) ℓ ∉ dom ( δ ) \ell\notin\operatorname{dom}(\delta) ℓ ∈ / dom ( δ ) and ℓ : A ∈ Π [ p ] \ell: A \in\Pi[p] ℓ : A ∈ Π [ p ] .
Case (a):
By definition, δ ( p , ℓ , ϱ ) = x \delta(p,\ell,\varrho) = x δ ( p , ℓ , ϱ ) = x .
From (a), we also have that x : Ref ⟦ A ⟧ ∈ Γ x : \operatorname{Ref}\llbracket A\rrbracket\in\Gamma x : Ref [ [ A ] ] ∈ Γ , i.e. (1) δ ( p , ℓ , ϱ ) : Ref ⟦ A ⟧ ∈ Γ \delta(p,\ell,\varrho) : \operatorname{Ref}\llbracket A\rrbracket\in\Gamma δ ( p , ℓ , ϱ ) : Ref [ [ A ] ] ∈ Γ .
We derive the conclusion as follows:
\frac{\frac{\delta(p,\ell,\varrho) : \operatorname{Ref}\llbracket A\rrbracket\in\Gamma}{\Gamma\,;\,\llbracket\Pi\rrbracket_{\varrho} \vdash\delta(p,\ell,\varrho) : \operatorname{Ref}\llbracket A\rrbracket}\ \textsc{TV-Var}}{}
Case (b):
By definition, δ ( p , ℓ , ϱ ) = ϱ ( p , ℓ ) \delta(p,\ell,\varrho) = \varrho(p,\ell) δ ( p , ℓ , ϱ ) = ϱ ( p , ℓ ) .
By premise (ii), since ℓ : A ∈ Π [ p ] \ell: A \in\Pi[p] ℓ : A ∈ Π [ p ] , we have that ϱ ( p , ℓ ) \varrho(p,\ell) ϱ ( p , ℓ ) is well-defined. Then by definition of ⟦ Π ⟧ ϱ \llbracket\Pi\rrbracket_{\varrho} [ [ Π ] ] ϱ , we get that ϱ ( p , ℓ ) : ⟦ A ⟧ ∈ ⟦ Π ⟧ ϱ \varrho(p,\ell) : \llbracket A\rrbracket\in\llbracket\Pi\rrbracket_{\varrho} ϱ ( p , ℓ ) : [ [ A ] ] ∈ [ [ Π ] ] ϱ , i.e. (2) δ ( p , ℓ , ϱ ) : ⟦ A ⟧ ∈ ⟦ Π ⟧ ϱ \delta(p,\ell,\varrho) : \llbracket A\rrbracket\in\llbracket\Pi\rrbracket_{\varrho} δ ( p , ℓ , ϱ ) : [ [ A ] ] ∈ [ [ Π ] ] ϱ .
We derive the conclusion as follows:
\frac{\frac{\delta(p,\ell,\varrho) : \llbracket A\rrbracket\in\llbracket\Pi\rrbracket_{\varrho}}{\Gamma\,;\,\llbracket\Pi\rrbracket_{\varrho} \vdash\delta(p,\ell,\varrho) : \operatorname{Ref}\llbracket A\rrbracket}\ \textsc{TV-Loc}}{}
We now proceed to the main proofs of type preservation.
Theorem B.3 (Type preservation, values). If
(i) Γ ; Π ; Φ ⊢ V : A \Gamma\,;\,\Pi\,;\,\Phi\vdash V : A Γ ; Π ; Φ ⊢ V : A and
(ii) Π ; ids ( V ) ⊨ ϱ \Pi\,;\,\operatorname{ids}(V) \models\varrho Π ; ids ( V ) ⊨ ϱ ,
then ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ V ⟧ ϱ : ⟦ A ⟧ \llbracket\Gamma\rrbracket\,;\,\llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket V\rrbracket_{\varrho} : \llbracket A\rrbracket [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ V ] ] ϱ : [ [ A ] ] .
Proof. By mutual induction on the derivation of the value typing judgment (i) with Theorems B.4, B.5, and 6.3
Case TV-Var: We have ⟦ x ⟧ ϱ = x \llbracket x\rrbracket_{\varrho} = x [ [ x ] ] ϱ = x and
\frac{x : A \in\Gamma}{\Gamma\,;\,\Pi\,;\,\Phi\vdash x : A}\ \textsc{TV-Var}
\qquad
\operatorname{Succ}(\Phi)
By (1) and definition of ⟦ Γ ⟧ \llbracket\Gamma\rrbracket [ [ Γ ] ] , we have (2) that x : ⟦ A ⟧ ∈ ⟦ Γ ⟧ x : \llbracket A\rrbracket\in\llbracket\Gamma\rrbracket x : [ [ A ] ] ∈ [ [ Γ ] ] .
We derive the conclusion as follows:
\frac{x : \llbracket A\rrbracket\in\llbracket\Gamma\rrbracket}{\llbracket\Gamma\rrbracket\,;\,\llbracket\Pi\rrbracket_{\varrho} \vdash x : \llbracket A\rrbracket}\ \textsc{TV-Var}
Case TV-Unit: ⟦ ( ) ⟧ ϱ = ( ) \llbracket()\rrbracket_{\varrho} = () [ [ ( ) ] ] ϱ = ( ) and ⟦ 1 ⟧ = 1 \llbracket1\rrbracket= 1 [ [ 1 ] ] = 1 , so the conclusion is easy:
\frac{\operatorname{Succ}(\Phi)}{\Gamma\,;\,\Pi\,;\,\Phi\vdash() : 1}\ \textsc{TV-Unit}
\qquad
\frac{}{\llbracket\Gamma\rrbracket\,;\,\llbracket\Pi\rrbracket_{\varrho} \vdash() : 1}\ \textsc{TV-Unit}
Cases TV-True, TV-False, TV-Str, and TV-Nil can all be shown analogously to the above case.
Case TV-Pair: We have
⟦ ( V , W ) ⟧ ϱ = ( ⟦ V ⟧ ϱ , ⟦ W ⟧ ϱ ) ⟦ A × B ⟧ = ⟦ A ⟧ × ⟦ B ⟧ ids ( ( V , W ) ) = ids ( V ) ∪ ids ( W ) \llbracket(V,W)\rrbracket_{\varrho} = (\llbracket V\rrbracket_{\varrho},\llbracket W\rrbracket_{\varrho})
\qquad
\llbracket A \times B\rrbracket= \llbracket A\rrbracket\times\llbracket B\rrbracket
\qquad
\operatorname{ids}((V,W)) = \operatorname{ids}(V) \cup\operatorname{ids}(W) [ [ ( V , W ) ] ] ϱ = ( [ [ V ] ] ϱ , [ [ W ] ] ϱ ) [ [ A × B ] ] = [ [ A ] ] × [ [ B ] ] ids (( V , W )) = ids ( V ) ∪ ids ( W )
Γ ; Π ; Φ 1 ⊢ V : A Γ ; Π ; Φ 2 ⊢ W : B Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B TV-Pair \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash V : A \quad\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash W : B}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \bowtie\Phi_2 \vdash(V,W) : A \times B}
\quad\text{TV-Pair} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B Γ ; Π ; Φ 1 ⊢ V : A Γ ; Π ; Φ 2 ⊢ W : B TV-Pair
By premise (ii) and definition of ids, we get (3) that Π ; ids ( V ) ⊨ ϱ \Pi\mathbin{;} \operatorname{ids}(V) \models\varrho Π ; ids ( V ) ⊨ ϱ and (4) that Π ; ids ( W ) ⊨ ϱ \Pi\mathbin{;} \operatorname{ids}(W) \models\varrho Π ; ids ( W ) ⊨ ϱ .
By inductive hypothesis on each of pairs (1)/(3) and (2)/(4), we get (5) that ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ V ⟧ ϱ : ⟦ A ⟧ \llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket V\rrbracket_{\varrho} : \llbracket A\rrbracket [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ V ] ] ϱ : [ [ A ] ] and (6) that ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ W ⟧ ϱ : ⟦ B ⟧ \llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket W\rrbracket_{\varrho} : \llbracket B\rrbracket [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ W ] ] ϱ : [ [ B ] ] , respectively.
We derive the conclusion as follows:
⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ V ⟧ ϱ : ⟦ A ⟧ ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ W ⟧ ϱ : ⟦ B ⟧ ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ( ⟦ V ⟧ ϱ , ⟦ W ⟧ ϱ ) : ⟦ A ⟧ × ⟦ B ⟧ TV-Pair \frac{\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket V\rrbracket_{\varrho} : \llbracket A\rrbracket\quad\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket W\rrbracket_{\varrho} : \llbracket B\rrbracket}{\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash(\llbracket V\rrbracket_{\varrho},\llbracket W\rrbracket_{\varrho}) : \llbracket A\rrbracket\times\llbracket B\rrbracket}
\quad\text{TV-Pair} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ ( [ [ V ] ] ϱ , [ [ W ] ] ϱ ) : [ [ A ] ] × [ [ B ] ] [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ V ] ] ϱ : [ [ A ] ] [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ W ] ] ϱ : [ [ B ] ] TV-Pair
Cases TV-Cons, TV-Attr, TV-OnClick, TV-Text, TV-Tag, TV-TextI, and TV-TagI can all be shown analogously to the above case.
Case TV-Lam: We have
⟦ λ x . M ⟧ ϱ = λ x . ⟦ M ⟧ ϱ ⟦ A → E B ⟧ = ⟦ A ⟧ → ⟦ B ⟧ ids ( λ x . M ) = ids ( M ) \llbracket\lambda x.M\rrbracket_{\varrho} = \lambda x.\llbracket M\rrbracket_{\varrho}
\qquad
\llbracket A \xrightarrow{E} B\rrbracket= \llbracket A\rrbracket\to\llbracket B\rrbracket
\qquad
\operatorname{ids}(\lambda x.M) = \operatorname{ids}(M) [ [ λ x . M ] ] ϱ = λ x . [ [ M ] ] ϱ [ [ A E B ] ] = [ [ A ] ] → [ [ B ] ] ids ( λ x . M ) = ids ( M )
Γ , x : A ; Π ; Φ ⊢ M : B ! E Γ ; Π ; Φ ⊢ λ x . M : A → E B Succ ( Φ ) TV-Lam \frac{\Gamma,x:A \mathbin{;} \Pi\mathbin{;} \Phi\vdash M : B \mathbin{!} E}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash\lambda x.M : A \xrightarrow{E} B}
\quad\text{Succ}(\Phi)
\quad\text{TV-Lam} Γ ; Π ; Φ ⊢ λ x . M : A E B Γ , x : A ; Π ; Φ ⊢ M : B ! E Succ ( Φ ) TV-Lam
By mutual inductive hypothesis (Theorem B.4 ) on (1) and premise (ii), we have (2) that ⟦ Γ ⟧ , x : ⟦ A ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ M ⟧ ϱ : ⟦ B ⟧ \llbracket\Gamma\rrbracket,x:\llbracket A\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket M\rrbracket_{\varrho} : \llbracket B\rrbracket [ [ Γ ] ] , x : [ [ A ] ] ; [ [ Π ] ] ϱ ⊢ [ [ M ] ] ϱ : [ [ B ] ] .
We derive the conclusion as follows:
⟦ Γ ⟧ , x : ⟦ A ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ M ⟧ ϱ : ⟦ B ⟧ ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ λ x . ⟦ M ⟧ ϱ : ⟦ A ⟧ → ⟦ B ⟧ TV-Lam \frac{\llbracket\Gamma\rrbracket,x:\llbracket A\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket M\rrbracket_{\varrho} : \llbracket B\rrbracket}{\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\lambda x.\llbracket M\rrbracket_{\varrho} : \llbracket A\rrbracket\to\llbracket B\rrbracket}
\quad\text{TV-Lam} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ λ x . [ [ M ] ] ϱ : [ [ A ] ] → [ [ B ] ] [ [ Γ ] ] , x : [ [ A ] ] ; [ [ Π ] ] ϱ ⊢ [ [ M ] ] ϱ : [ [ B ] ] TV-Lam
Case TV-Setter: We have
⟦ set p ℓ ⟧ ϱ = λ x . ( ϱ ( p , ℓ ) : = x ; ϱ ( p ) : = true ) ⟦ A → Mut 1 ⟧ = ⟦ A ⟧ → 1 \llbracket\operatorname{set}^{\ell}_{p}\rrbracket_{\varrho}
= \lambda x.(\varrho(p,\ell) := x \mathbin{;} \varrho(p) := \operatorname{true})
\qquad
\llbracket A \xrightarrow{\operatorname{Mut}} 1\rrbracket
= \llbracket A\rrbracket\to1 [ [ set p ℓ ] ] ϱ = λ x . ( ϱ ( p , ℓ ) := x ; ϱ ( p ) := true ) [ [ A Mut 1 ] ] = [ [ A ] ] → 1
ℓ : A ∈ Π [ p ] Γ ; Π ; Φ ⊢ set p ℓ : A → Mut 1 Succ ( Φ ) TV-Setter \frac{\ell: A \in\Pi[p]}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash\operatorname{set}^{\ell}_{p} : A \xrightarrow{\operatorname{Mut}} 1}
\quad\text{Succ}(\Phi)
\quad\text{TV-Setter} Γ ; Π ; Φ ⊢ set p ℓ : A Mut 1 ℓ : A ∈ Π [ p ] Succ ( Φ ) TV-Setter
By (1) and premise (ii), we have (2) that ϱ ( p ) \varrho(p) ϱ ( p ) is well-defined and (3) that ϱ ( p , ℓ ) \varrho(p,\ell) ϱ ( p , ℓ ) is well-defined.
By definition of ⟦ Π ⟧ ϱ \llbracket\Pi\rrbracket_{\varrho} [ [ Π ] ] ϱ , from (2) and (3) respectively we get (4) that ϱ ( p ) : Bool ∈ ⟦ Π ⟧ ϱ \varrho(p) : \operatorname{Bool} \in\llbracket\Pi\rrbracket_{\varrho} ϱ ( p ) : Bool ∈ [ [ Π ] ] ϱ and (5) that ϱ ( p , ℓ ) : ⟦ A ⟧ ∈ ⟦ Π ⟧ ϱ \varrho(p,\ell) : \llbracket A\rrbracket\in\llbracket\Pi\rrbracket_{\varrho} ϱ ( p , ℓ ) : [ [ A ] ] ∈ [ [ Π ] ] ϱ , noting that Π [ p ] [ ℓ ] = A \Pi[p][\ell] = A Π [ p ] [ ℓ ] = A by (1).
ϱ ( p , ℓ ) : ⟦ A ⟧ ∈ ⟦ Π ⟧ R Γ 6 ; ⟦ Π ⟧ ϱ ⊢ ϱ ( p , ℓ ) : Ref ⟦ A ⟧ TV-Loc x : ⟦ A ⟧ ∈ Γ 6 Γ 6 ; ⟦ Π ⟧ ϱ ⊢ x : ⟦ A ⟧ TV-Var Γ 6 ; ⟦ Π ⟧ ϱ ⊢ ϱ ( p , ℓ ) : = x : 1 Γ 6 ; ⟦ Π ⟧ ϱ ⊢ ϱ ( p , ℓ ) : = x : 1 TC-Set ( 6 ) Γ 6 ; ⟦ Π ⟧ ϱ ⊢ ϱ ( p , ℓ ) : = x : 1 \begin{aligned}
&\frac{\varrho(p,\ell) : \llbracket A\rrbracket\in\llbracket\Pi\rrbracket_R}{\Gamma_6 ; \llbracket\Pi\rrbracket_\varrho\vdash\varrho(p,\ell) : \operatorname{Ref}\llbracket A\rrbracket}\ \operatorname{TV\text{-}Loc}
\qquad
\frac{x : \llbracket A\rrbracket\in\Gamma_6}{\Gamma_6 ; \llbracket\Pi\rrbracket_\varrho\vdash x : \llbracket A\rrbracket}\ \operatorname{TV\text{-}Var}\\
&\frac{\Gamma_6 ; \llbracket\Pi\rrbracket_\varrho\vdash\varrho(p,\ell) := x : 1}{\phantom{\Gamma_6 ; \llbracket\Pi\rrbracket_\varrho\vdash\varrho(p,\ell) := x : 1}}\ \operatorname{TC\text{-}Set}\\
&(6)\quad\Gamma_6 ; \llbracket\Pi\rrbracket_\varrho\vdash\varrho(p,\ell) := x : 1
\end{aligned} Γ 6 ; [ [ Π ] ] ϱ ⊢ ϱ ( p , ℓ ) : Ref [ [ A ] ] ϱ ( p , ℓ ) : [ [ A ] ] ∈ [ [ Π ] ] R TV - Loc Γ 6 ; [ [ Π ] ] ϱ ⊢ x : [ [ A ] ] x : [ [ A ] ] ∈ Γ 6 TV - Var Γ 6 ; [ [ Π ] ] ϱ ⊢ ϱ ( p , ℓ ) := x : 1 Γ 6 ; [ [ Π ] ] ϱ ⊢ ϱ ( p , ℓ ) := x : 1 TC - Set ( 6 ) Γ 6 ; [ [ Π ] ] ϱ ⊢ ϱ ( p , ℓ ) := x : 1
ϱ ( p ) : Bool ∈ ⟦ Π ⟧ ϱ Γ 7 ; ⟦ Π ⟧ ϱ ⊢ ϱ ( p ) : Ref Bool TV-Loc Γ 7 ; ⟦ Π ⟧ ϱ ⊢ true : Bool Γ 7 ; ⟦ Π ⟧ ϱ ⊢ true : Bool TV-True ( 7 ) Γ 7 ; ⟦ Π ⟧ ϱ ⊢ ϱ ( p ) : = true : 1 TC-Set \begin{aligned}
&\frac{\varrho(p) : \operatorname{Bool} \in\llbracket\Pi\rrbracket_\varrho}{\Gamma_7 ; \llbracket\Pi\rrbracket_\varrho\vdash\varrho(p) : \operatorname{Ref}\operatorname{Bool}}\ \operatorname{TV\text{-}Loc}
\qquad
\frac{\Gamma_7 ; \llbracket\Pi\rrbracket_\varrho\vdash\operatorname{true} : \operatorname{Bool}}{\phantom{\Gamma_7 ; \llbracket\Pi\rrbracket_\varrho\vdash\operatorname{true} : \operatorname{Bool}}}\ \operatorname{TV\text{-}True}\\
&(7)\quad\Gamma_7 ; \llbracket\Pi\rrbracket_\varrho\vdash\varrho(p) := \operatorname{true} : 1\quad\operatorname{TC\text{-}Set}
\end{aligned} Γ 7 ; [ [ Π ] ] ϱ ⊢ ϱ ( p ) : Ref Bool ϱ ( p ) : Bool ∈ [ [ Π ] ] ϱ TV - Loc Γ 7 ; [ [ Π ] ] ϱ ⊢ true : Bool Γ 7 ; [ [ Π ] ] ϱ ⊢ true : Bool TV - True ( 7 ) Γ 7 ; [ [ Π ] ] ϱ ⊢ ϱ ( p ) := true : 1 TC - Set
[ ( 6 ) , Γ 6 = ⟦ Γ ⟧ , x : ⟦ A ⟧ ] [ ( 7 ) , Γ 7 = ⟦ Γ ⟧ , x : ⟦ A ⟧ ] Γ , x : ⟦ A ⟧ ; ⟦ Π ⟧ ϱ ⊢ ϱ ( p , ℓ ) : = x ; ϱ ( p ) : = true : 1 TC-Let \frac{[(6),\ \Gamma_6 = \llbracket\Gamma\rrbracket,\ x : \llbracket A\rrbracket]\qquad[(7),\ \Gamma_7 = \llbracket\Gamma\rrbracket,\ x : \llbracket A\rrbracket]}{\Gamma,\ x : \llbracket A\rrbracket; \llbracket\Pi\rrbracket_\varrho\vdash\varrho(p,\ell) := x\ ;\ \varrho(p) := \operatorname{true} : 1}\ \operatorname{TC\text{-}Let} Γ , x : [ [ A ] ] ; [ [ Π ] ] ϱ ⊢ ϱ ( p , ℓ ) := x ; ϱ ( p ) := true : 1 [( 6 ) , Γ 6 = [ [ Γ ] ] , x : [ [ A ] ] ] [( 7 ) , Γ 7 = [ [ Γ ] ] , x : [ [ A ] ] ] TC - Let
⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ λ x . ( ϱ ( p , ℓ ) : = x ; ϱ ( p ) : = true ) : ⟦ A ⟧ → 1 ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ λ x . ( ϱ ( p , ℓ ) : = x ; ϱ ( p ) : = true ) : ⟦ A ⟧ → 1 TV-Lam \frac{\llbracket\Gamma\rrbracket; \llbracket\Pi\rrbracket_\varrho\vdash\lambda x.(\varrho(p,\ell) := x\ ;\ \varrho(p) := \operatorname{true}) : \llbracket A\rrbracket\to1}{\phantom{\llbracket\Gamma\rrbracket; \llbracket\Pi\rrbracket_\varrho\vdash\lambda x.(\varrho(p,\ell) := x\ ;\ \varrho(p) := \operatorname{true}) : \llbracket A\rrbracket\to1}}\ \operatorname{TV\text{-}Lam} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ λ x . ( ϱ ( p , ℓ ) := x ; ϱ ( p ) := true ) : [ [ A ] ] → 1 [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ λ x . ( ϱ ( p , ℓ ) := x ; ϱ ( p ) := true ) : [ [ A ] ] → 1 TV - Lam
Case TV-Comp: We have
⟦ component { D } ⟧ ϱ = component ( λ ( ) . let x = ref ( false ) in I ⟦ D ⟧ ( D , ⊥ , ϱ , flag ↦ x ) ) ⟦ Element ⟧ = Element ids ( component { D } ) = ids ( D ) \begin{aligned}
\llbracket\operatorname{component}\ \{D\}\rrbracket_\varrho
&= \operatorname{component}\left(\lambda().\operatorname{let}\ x = \operatorname{ref}(\operatorname{false})\ \operatorname{in}\ I\llbracket D\rrbracket(D,\bot,\varrho,\operatorname{flag}\mapsto x)\right)\\
\llbracket\operatorname{Element}\rrbracket&= \operatorname{Element}\\
\operatorname{ids}(\operatorname{component}\ \{D\}) &= \operatorname{ids}(D)
\end{aligned} [ [ component { D } ] ] ϱ [ [ Element ] ] ids ( component { D }) = component ( λ ( ) . let x = ref ( false ) in I [ [ D ] ] ( D , ⊥ , ϱ , flag ↦ x ) ) = Element = ids ( D )
Γ ; Π ; Φ ⊢ D : L Γ ; Π ; Φ ⊢ component { D } : View TV-Comp \frac{\Gamma; \Pi; \Phi\vdash D : \mathcal{L}}{\Gamma; \Pi; \Phi\vdash\operatorname{component}\ \{D\} : \operatorname{View}}\ \operatorname{TV\text{-}Comp} Γ ; Π ; Φ ⊢ component { D } : View Γ ; Π ; Φ ⊢ D : L TV - Comp
By definition, we have (2) that x : Ref Bool ; Π ⊨ ⊥ flag ↦ x : ∅ x : \operatorname{Ref}\operatorname{Bool} ; \Pi\models_{\bot} \operatorname{flag}\mapsto x : \varnothing x : Ref Bool ; Π ⊨ ⊥ flag ↦ x : ∅ .
By Theorem 6.3 (initial-phase type preservation) on (1), (2), and premise (ii), we get (3) that
⟦ Γ ⟧ , x : Ref Bool ; ⟦ Π ⟧ ϱ ⊢ I ⟦ D ⟧ ( D , ⊥ , ϱ , flag ↦ x ) : A comp . \llbracket\Gamma\rrbracket,\ x : \operatorname{Ref}\operatorname{Bool} ; \llbracket\Pi\rrbracket_\varrho\vdash I\llbracket D\rrbracket(D,\bot,\varrho,\operatorname{flag}\mapsto x) : A_{\operatorname{comp}}. [ [ Γ ] ] , x : Ref Bool ; [ [ Π ] ] ϱ ⊢ I [ [ D ] ] ( D , ⊥ , ϱ , flag ↦ x ) : A comp .
⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ false : Bool ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ref ( false ) : Ref Bool TC-Ref \frac{\llbracket\Gamma\rrbracket; \llbracket\Pi\rrbracket_\varrho\vdash\operatorname{false} : \operatorname{Bool}}{\llbracket\Gamma\rrbracket; \llbracket\Pi\rrbracket_\varrho\vdash\operatorname{ref}(\operatorname{false}) : \operatorname{Ref}\operatorname{Bool}}\ \operatorname{TC\text{-}Ref} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ ref ( false ) : Ref Bool [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ false : Bool TC - Ref
⟦ Γ ⟧ , x : Ref Bool ; ⟦ Π ⟧ ϱ ⊢ I ⟦ D ⟧ ( D , ⊥ , ϱ , flag ↦ x ) : A comp ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ let x = ref ( false ) in I ⟦ D ⟧ ( D , ⊥ , ϱ , flag ↦ x ) : A comp TC-Let \frac{\llbracket\Gamma\rrbracket,\ x : \operatorname{Ref}\operatorname{Bool} ; \llbracket\Pi\rrbracket_\varrho\vdash I\llbracket D\rrbracket(D,\bot,\varrho,\operatorname{flag}\mapsto x) : A_{\operatorname{comp}}}{\llbracket\Gamma\rrbracket; \llbracket\Pi\rrbracket_\varrho\vdash\operatorname{let}\ x = \operatorname{ref}(\operatorname{false})\ \operatorname{in}\ I\llbracket D\rrbracket(D,\bot,\varrho,\operatorname{flag}\mapsto x) : A_{\operatorname{comp}}}\ \operatorname{TC\text{-}Let} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ let x = ref ( false ) in I [ [ D ] ] ( D , ⊥ , ϱ , flag ↦ x ) : A comp [ [ Γ ] ] , x : Ref Bool ; [ [ Π ] ] ϱ ⊢ I [ [ D ] ] ( D , ⊥ , ϱ , flag ↦ x ) : A comp TC - Let
⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ λ ( ) . let x = ref ( false ) in I ⟦ D ⟧ ( D , ⊥ , ϱ , flag ↦ x ) : 1 → A comp ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ component λ ( ) . let x = ref ( false ) in ⋯ : Element TV-Comp \frac{\llbracket\Gamma\rrbracket; \llbracket\Pi\rrbracket_\varrho\vdash\lambda().\operatorname{let}\ x = \operatorname{ref}(\operatorname{false})\ \operatorname{in}\ I\llbracket D\rrbracket(D,\bot,\varrho,\operatorname{flag}\mapsto x) : 1 \to A_{\operatorname{comp}}}{\llbracket\Gamma\rrbracket; \llbracket\Pi\rrbracket_\varrho\vdash\operatorname{component}\ \lambda().\operatorname{let}\ x = \operatorname{ref}(\operatorname{false})\ \operatorname{in}\ \cdots: \operatorname{Element}}\ \operatorname{TV\text{-}Comp} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ component λ ( ) . let x = ref ( false ) in ⋯ : Element [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ λ ( ) . let x = ref ( false ) in I [ [ D ] ] ( D , ⊥ , ϱ , flag ↦ x ) : 1 → A comp TV - Comp
Case TV-CompI: We have
⟦ compInst p ( ⌈ D ⌉ , V ) ⟧ ϱ = compInst ( λ ( ) . S ⟦ D ⟧ ( ⊥ , ϱ , ∅ ) , ϱ ( p ) , ⟦ V ⟧ ϱ ) ⟦ ElemInst ⟧ = ElemInst ids ( compInst p ( ⌈ D ⌉ , V ) ) = ids ( D ) ∪ ids ( V ) \begin{aligned}
\llbracket\operatorname{compInst}_p(\lceil D\rceil,V)\rrbracket_\varrho
&= \operatorname{compInst}(\lambda().S\llbracket D\rrbracket(\bot,\varrho,\varnothing),\varrho(p),\llbracket V\rrbracket_\varrho)\\
\llbracket\operatorname{ElemInst}\rrbracket&= \operatorname{ElemInst}\\
\operatorname{ids}(\operatorname{compInst}_p(\lceil D\rceil,V)) &= \operatorname{ids}(D)\cup\operatorname{ids}(V)
\end{aligned} [ [ compInst p (⌈ D ⌉ , V ) ] ] ϱ [ [ ElemInst ] ] ids ( compInst p (⌈ D ⌉ , V )) = compInst ( λ ( ) . S [ [ D ] ] ( ⊥ , ϱ , ∅ ) , ϱ ( p ) , [ [ V ] ] ϱ ) = ElemInst = ids ( D ) ∪ ids ( V )
Γ ; Π ; Φ 1 ⊢ D : Π [ p ] ( Φ 1 ⋈ Φ 2 ) [ p ] = Succ Γ ; Π ; Φ 2 ⊢ V : ElemInst Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ compInst p ( ⌈ D ⌉ , V ) : ElemInst TV-CompI \frac{\Gamma; \Pi; \Phi_1 \vdash D : \Pi[p]\qquad(\Phi_1 \mathbin{\bowtie} \Phi_2)[p] = \operatorname{Succ}\qquad\Gamma; \Pi; \Phi_2 \vdash V : \operatorname{ElemInst}}{\Gamma; \Pi; \Phi_1 \mathbin{\bowtie} \Phi_2 \vdash\operatorname{compInst}_p(\lceil D\rceil,V) : \operatorname{ElemInst}}\ \operatorname{TV\text{-}CompI} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ compInst p (⌈ D ⌉ , V ) : ElemInst Γ ; Π ; Φ 1 ⊢ D : Π [ p ] ( Φ 1 ⋈ Φ 2 ) [ p ] = Succ Γ ; Π ; Φ 2 ⊢ V : ElemInst TV - CompI
By premise (ii) and definition of ids, we have (3) that Π \Pi Π ; ids(D D D ) ⊨ ρ \models\rho ⊨ ρ and (4) that Π \Pi Π ; ids(V V V ) ⊨ ρ \models\rho ⊨ ρ .
By definition, we have (5) that ∅ \varnothing ∅ ; Π ⊢ p ∅ : Π [ p ] \Pi\vdash_p \varnothing: \Pi[p] Π ⊢ p ∅ : Π [ p ] .
By mutual inductive hypothesis (Theorem B.5) on (1), (3) and (5), we get (6) that ⟦ Γ ⟧ \llbracket\Gamma\rrbracket [ [ Γ ] ] ; ⟦ Π ⟧ ρ ⊢ S ⟦ D ⟧ ( ⊥ , ρ , ∅ ) : Element \llbracket\Pi\rrbracket_\rho\vdash S\llbracket D\rrbracket(\perp,\rho,\varnothing) : \operatorname{Element} [ [ Π ] ] ρ ⊢ S [ [ D ] ] ( ⊥ , ρ , ∅ ) : Element .
By inductive hypothesis on (2) and (4), we get (7) that ⟦ Γ ⟧ \llbracket\Gamma\rrbracket [ [ Γ ] ] ; ⟦ Π ⟧ ρ ⊢ ⟦ V ⟧ ρ : ElemInst \llbracket\Pi\rrbracket_\rho\vdash\llbracket V\rrbracket_\rho: \operatorname{ElemInst} [ [ Π ] ] ρ ⊢ [ [ V ] ] ρ : ElemInst .
By premise (ii), since p ∈ dom ( Π ) p \in\operatorname{dom}(\Pi) p ∈ dom ( Π ) (given by (1)), we have that ρ ( p ) \rho(p) ρ ( p ) is well-defined. Then by definition of ⟦ Π ⟧ ρ \llbracket\Pi\rrbracket_\rho [ [ Π ] ] ρ , we get (8) that ρ ( p ) : Bool ∈ ⟦ Π ⟧ ρ \rho(p) : \operatorname{Bool} \in\llbracket\Pi\rrbracket_\rho ρ ( p ) : Bool ∈ [ [ Π ] ] ρ .
We derive the conclusion by way of subderivation (9) as follows:
⟦ Γ ⟧ ; ⟦ Π ⟧ ρ ⊢ S ⟦ D ⟧ ( ⊥ , ρ , ∅ ) : Element ⟦ Γ ⟧ ; ⟦ Π ⟧ ρ ⊢ λ ( ) . S ⟦ D ⟧ ( ⊥ , ρ , ∅ ) : 1 → Element \begin{aligned}
&\llbracket\Gamma\rrbracket\,;\,\llbracket\Pi\rrbracket_\rho\vdash S\llbracket D\rrbracket(\perp,\rho,\varnothing) : \operatorname{Element}\\
&\llbracket\Gamma\rrbracket\,;\,\llbracket\Pi\rrbracket_\rho\vdash\lambda().S\llbracket D\rrbracket(\perp,\rho,\varnothing) : 1 \to\operatorname{Element}
\end{aligned} [ [ Γ ] ] ; [ [ Π ] ] ρ ⊢ S [ [ D ] ] ( ⊥ , ρ , ∅ ) : Element [ [ Γ ] ] ; [ [ Π ] ] ρ ⊢ λ ( ) . S [ [ D ] ] ( ⊥ , ρ , ∅ ) : 1 → Element
ρ ( p ) : Bool ∈ ⟦ Π ⟧ ρ ⟦ Γ ⟧ ; ⟦ Π ⟧ ρ ⊢ ρ ( p ) : Ref Bool \begin{aligned}
&\rho(p) : \operatorname{Bool} \in\llbracket\Pi\rrbracket_\rho\\
&\llbracket\Gamma\rrbracket\,;\,\llbracket\Pi\rrbracket_\rho\vdash\rho(p) : \operatorname{Ref}\ \operatorname{Bool}
\end{aligned} ρ ( p ) : Bool ∈ [ [ Π ] ] ρ [ [ Γ ] ] ; [ [ Π ] ] ρ ⊢ ρ ( p ) : Ref Bool
⟦ Γ ⟧ ; ⟦ Π ⟧ ρ ⊢ ⟦ V ⟧ ρ : ElemInst \llbracket\Gamma\rrbracket\,;\,\llbracket\Pi\rrbracket_\rho\vdash\llbracket V\rrbracket_\rho: \operatorname{ElemInst} [ [ Γ ] ] ; [ [ Π ] ] ρ ⊢ [ [ V ] ] ρ : ElemInst
⟦ Γ ⟧ ; ⟦ Π ⟧ ρ ⊢ compInst ( λ ( ) . S ⟦ D ⟧ ( ⊥ , ρ , ∅ ) , ρ ( p ) , ⟦ V ⟧ ρ ) : ElemInst \llbracket\Gamma\rrbracket\,;\,\llbracket\Pi\rrbracket_\rho\vdash\operatorname{compInst}(\lambda().S\llbracket D\rrbracket(\perp,\rho,\varnothing),\rho(p),\llbracket V\rrbracket_\rho) : \operatorname{ElemInst} [ [ Γ ] ] ; [ [ Π ] ] ρ ⊢ compInst ( λ ( ) . S [ [ D ] ] ( ⊥ , ρ , ∅ ) , ρ ( p ) , [ [ V ] ] ρ ) : ElemInst
Theorem B.4 (Type preservation, computations). If
(i) Γ \Gamma Γ ; Π \Pi Π ; Φ ⊢ M : A ! E \Phi\vdash M : A\ !\ E Φ ⊢ M : A ! E and
(ii) Π \Pi Π ; ids(M M M ) ⊨ ρ \models\rho ⊨ ρ ,
then ⟦ Γ ⟧ \llbracket\Gamma\rrbracket [ [ Γ ] ] ; ⟦ Π ⟧ ρ ⊢ ⟦ M ⟧ ρ : ⟦ A ⟧ \llbracket\Pi\rrbracket_\rho\vdash\llbracket M\rrbracket_\rho: \llbracket A\rrbracket [ [ Π ] ] ρ ⊢ [ [ M ] ] ρ : [ [ A ] ] .
Proof. By mutual induction on the derivation of the computation typing judgment (i) with Theorems B.3, B.5, and 6.3.
Case TC-Val: We have
⟦ val V ⟧ ρ = val ⟦ V ⟧ ρ ids ( val V ) = ids ( V ) \llbracket\operatorname{val}\ V\rrbracket_\rho= \operatorname{val}\ \llbracket V\rrbracket_\rho\qquad\operatorname{ids}(\operatorname{val}\ V) = \operatorname{ids}(V) [ [ val V ] ] ρ = val [ [ V ] ] ρ ids ( val V ) = ids ( V )
Γ ; Π ; Φ ⊢ V : A Γ ; Π ; Φ ⊢ val V : A ! Pure \begin{aligned}
\Gamma\,;\,\Pi\,;\,\Phi\vdash V : A\\
\Gamma\,;\,\Pi\,;\,\Phi\vdash\operatorname{val}\ V : A\ !\ \operatorname{Pure}
\end{aligned} Γ ; Π ; Φ ⊢ V : A Γ ; Π ; Φ ⊢ val V : A ! Pure
By mutual inductive hypothesis (Theorem B.3) on (1) and premise (ii), we have (2) that ⟦ Γ ⟧ \llbracket\Gamma\rrbracket [ [ Γ ] ] ; ⟦ Π ⟧ ρ ⊢ ⟦ V ⟧ ρ : ⟦ A ⟧ \llbracket\Pi\rrbracket_\rho\vdash\llbracket V\rrbracket_\rho: \llbracket A\rrbracket [ [ Π ] ] ρ ⊢ [ [ V ] ] ρ : [ [ A ] ] .
We derive the conclusion as follows:
⟦ Γ ⟧ ; ⟦ Π ⟧ ρ ⊢ ⟦ V ⟧ ρ : ⟦ A ⟧ ⟦ Γ ⟧ ; ⟦ Π ⟧ ρ ⊢ val ⟦ V ⟧ ρ : ⟦ A ⟧ \begin{aligned}
&\llbracket\Gamma\rrbracket\,;\,\llbracket\Pi\rrbracket_\rho\vdash\llbracket V\rrbracket_\rho: \llbracket A\rrbracket\\
&\llbracket\Gamma\rrbracket\,;\,\llbracket\Pi\rrbracket_\rho\vdash\operatorname{val}\ \llbracket V\rrbracket_\rho: \llbracket A\rrbracket
\end{aligned} [ [ Γ ] ] ; [ [ Π ] ] ρ ⊢ [ [ V ] ] ρ : [ [ A ] ] [ [ Γ ] ] ; [ [ Π ] ] ρ ⊢ val [ [ V ] ] ρ : [ [ A ] ]
Cases TC-Fst, TC-Snd, TC-Fold, TC-Init, TC-Click, TC-RunClick, and TC-Update can all be shown analogously to the above case.
Case TC-Let: We have
⟦ let x = M in N ⟧ ρ = let x = ⟦ M ⟧ ρ in ⟦ N ⟧ ρ ids ( let x = M in N ) = ids ( M ) ∪ ids ( N ) \llbracket\operatorname{let}\ x = M\ \operatorname{in}\ N\rrbracket_\rho= \operatorname{let}\ x = \llbracket M\rrbracket_\rho\ \operatorname{in}\ \llbracket N\rrbracket_\rho\qquad\operatorname{ids}(\operatorname{let}\ x = M\ \operatorname{in}\ N) = \operatorname{ids}(M) \cup\operatorname{ids}(N) [ [ let x = M in N ] ] ρ = let x = [ [ M ] ] ρ in [ [ N ] ] ρ ids ( let x = M in N ) = ids ( M ) ∪ ids ( N )
Γ ; Π ; Φ 1 ⊢ M : A ! E Γ , x : A ; Π ; Φ 2 ⊢ N : B ! E Γ ; Π ; Φ 1 ⋏ Φ 2 ⊢ let x = M in N : B ! E \begin{aligned}
\Gamma\,;\,\Pi\,;\,\Phi_1 \vdash M : A\ !\ E\\
\Gamma,x : A\,;\,\Pi\,;\,\Phi_2 \vdash N : B\ !\ E\\
\Gamma\,;\,\Pi\,;\,\Phi_1 \mathbin{\curlywedge} \Phi_2 \vdash\operatorname{let}\ x = M\ \operatorname{in}\ N : B\ !\ E
\end{aligned} Γ ; Π ; Φ 1 ⊢ M : A ! E Γ , x : A ; Π ; Φ 2 ⊢ N : B ! E Γ ; Π ; Φ 1 ⋏ Φ 2 ⊢ let x = M in N : B ! E
By inductive hypothesis on each of pairs (1)/(3) and (2)/(4), we get (5) that ⟦ Γ ⟧ \llbracket\Gamma\rrbracket [ [ Γ ] ] ; ⟦ Π ⟧ ϱ ⊢ ⟦ M ⟧ ϱ : ⟦ A ⟧ \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket M\rrbracket_{\varrho} : \llbracket A\rrbracket [ [ Π ] ] ϱ ⊢ [ [ M ] ] ϱ : [ [ A ] ] and (6) that ⟦ Γ ⟧ \llbracket\Gamma\rrbracket [ [ Γ ] ] , x x x : ⟦ A ⟧ \llbracket A\rrbracket [ [ A ] ] ; ⟦ Π ⟧ ϱ ⊢ ⟦ N ⟧ ϱ : \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket N\rrbracket_{\varrho} : [ [ Π ] ] ϱ ⊢ [ [ N ] ] ϱ : \llbracket B\rrbracket$, respectively.
⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ M ⟧ ϱ : ⟦ A ⟧ ⟦ Γ ⟧ , x : ⟦ A ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ N ⟧ ϱ : ⟦ B ⟧ ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ let x = ⟦ M ⟧ ϱ in ⟦ N ⟧ ϱ : ⟦ B ⟧ T C - L e t \frac{\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket M\rrbracket_{\varrho} : \llbracket A\rrbracket\qquad\llbracket\Gamma\rrbracket, x : \llbracket A\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket N\rrbracket_{\varrho} : \llbracket B\rrbracket}{\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\operatorname{let} x = \llbracket M\rrbracket_{\varrho}\ \operatorname{in}\ \llbracket N\rrbracket_{\varrho} : \llbracket B\rrbracket}\ \mathrm{TC\text{-}Let} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ let x = [ [ M ] ] ϱ in [ [ N ] ] ϱ : [ [ B ] ] [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ M ] ] ϱ : [ [ A ] ] [ [ Γ ] ] , x : [ [ A ] ] ; [ [ Π ] ] ϱ ⊢ [ [ N ] ] ϱ : [ [ B ] ] TC - Let
Case TC-App: We have
⟦ V W ⟧ ϱ = ⟦ V ⟧ ϱ ⟦ W ⟧ ϱ \llbracket V\ W\rrbracket_{\varrho} = \llbracket V\rrbracket_{\varrho}\ \llbracket W\rrbracket_{\varrho} [ [ V W ] ] ϱ = [ [ V ] ] ϱ [ [ W ] ] ϱ
ids ( V W ) = ids ( V ) ∪ ids ( W ) \operatorname{ids}(V\ W) = \operatorname{ids}(V) \cup\operatorname{ids}(W) ids ( V W ) = ids ( V ) ∪ ids ( W )
Γ ; Π ; Φ 1 ⊢ V : A → E B Γ ; Π ; Φ 2 ⊢ W : A Γ ; Π ; Φ 1 ⊔ Φ 2 ⊢ V W : B ! E T C - A p p \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash V : A \mathbin{\to^{E}} B \qquad\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash W : A}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \mathbin{\sqcup} \Phi_2 \vdash V\ W : B\ !\ E}\ \mathrm{TC\text{-}App} Γ ; Π ; Φ 1 ⊔ Φ 2 ⊢ V W : B ! E Γ ; Π ; Φ 1 ⊢ V : A → E B Γ ; Π ; Φ 2 ⊢ W : A TC - App
By mutual inductive hypothesis (Theorem B.3 ) on each of pairs (1)/(3) and (2)/(4), we get (5) that ⟦ Γ ⟧ \llbracket\Gamma\rrbracket [ [ Γ ] ] ; ⟦ Π ⟧ ϱ ⊢ ⟦ V ⟧ ϱ : ⟦ A ⟧ → ⟦ B ⟧ \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket V\rrbracket_{\varrho} : \llbracket A\rrbracket\to\llbracket B\rrbracket [ [ Π ] ] ϱ ⊢ [ [ V ] ] ϱ : [ [ A ] ] → [ [ B ] ] and (6) that ⟦ Γ ⟧ \llbracket\Gamma\rrbracket [ [ Γ ] ] ; ⟦ Π ⟧ ϱ ⊢ ⟦ W ⟧ ϱ : ⟦ A ⟧ \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket W\rrbracket_{\varrho} : \llbracket A\rrbracket [ [ Π ] ] ϱ ⊢ [ [ W ] ] ϱ : [ [ A ] ] , respectively.
⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ V ⟧ ϱ : ⟦ A ⟧ → ⟦ B ⟧ ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ W ⟧ ϱ : ⟦ A ⟧ ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ V ⟧ ϱ ⟦ W ⟧ ϱ : ⟦ B ⟧ T C - A p p \frac{\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket V\rrbracket_{\varrho} : \llbracket A\rrbracket\to\llbracket B\rrbracket\qquad\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket W\rrbracket_{\varrho} : \llbracket A\rrbracket}{\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket V\rrbracket_{\varrho}\ \llbracket W\rrbracket_{\varrho} : \llbracket B\rrbracket}\ \mathrm{TC\text{-}App} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ V ] ] ϱ [ [ W ] ] ϱ : [ [ B ] ] [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ V ] ] ϱ : [ [ A ] ] → [ [ B ] ] [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ W ] ] ϱ : [ [ A ] ] TC - App
Case TC-If: We have
⟦ if V then M 1 else M 2 ⟧ ϱ = if ⟦ V ⟧ ϱ then ⟦ M 1 ⟧ ϱ else ⟦ M 2 ⟧ ϱ \llbracket\operatorname{if}\ V\ \operatorname{then}\ M_1\ \operatorname{else}\ M_2\rrbracket_{\varrho}
=
\operatorname{if}\ \llbracket V\rrbracket_{\varrho}\ \operatorname{then}\ \llbracket M_1\rrbracket_{\varrho}\ \operatorname{else}\ \llbracket M_2\rrbracket_{\varrho} [ [ if V then M 1 else M 2 ] ] ϱ = if [ [ V ] ] ϱ then [ [ M 1 ] ] ϱ else [ [ M 2 ] ] ϱ
ids ( if V then M 1 else M 2 ) = ids ( V ) ∪ ids ( M 1 ) ∪ ids ( M 2 ) \operatorname{ids}(\operatorname{if}\ V\ \operatorname{then}\ M_1\ \operatorname{else}\ M_2)
=
\operatorname{ids}(V) \cup\operatorname{ids}(M_1) \cup\operatorname{ids}(M_2) ids ( if V then M 1 else M 2 ) = ids ( V ) ∪ ids ( M 1 ) ∪ ids ( M 2 )
Γ ; Π ; Φ 1 ⊢ V : Bool Γ ; Π ; Φ 2 ⊢ M 1 : A ! E Γ ; Π ; Φ 2 ⊢ M 2 : A ! E Γ ; Π ; Φ 1 ⊔ Φ 2 ⊢ if V then M 1 else M 2 : A ! E T C - I f \frac{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash V : \operatorname{Bool}
\qquad
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash M_1 : A\ !\ E
\qquad
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash M_2 : A\ !\ E
}{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \mathbin{\sqcup} \Phi_2 \vdash\operatorname{if}\ V\ \operatorname{then}\ M_1\ \operatorname{else}\ M_2 : A\ !\ E
}\ \mathrm{TC\text{-}If} Γ ; Π ; Φ 1 ⊔ Φ 2 ⊢ if V then M 1 else M 2 : A ! E Γ ; Π ; Φ 1 ⊢ V : Bool Γ ; Π ; Φ 2 ⊢ M 1 : A ! E Γ ; Π ; Φ 2 ⊢ M 2 : A ! E TC - If
By premise (i i ii ii ) and definition of ids, we have (4) that Π \Pi Π ; ids(V V V ) ⊨ ϱ \models\varrho ⊨ ϱ , (5) that Π \Pi Π ; ids(M 1 M_1 M 1 ) ⊨ ϱ \models\varrho ⊨ ϱ , and (6) that Π \Pi Π ; ids(M 2 M_2 M 2 ) ⊨ ϱ \models\varrho ⊨ ϱ .
By inductive hypothesis on each of pairs (2)/(5) and (3)/(6), we get (8) that ⟦ Γ ⟧ \llbracket\Gamma\rrbracket [ [ Γ ] ] ; ⟦ Π ⟧ ϱ ⊢ ⟦ M 1 ⟧ ϱ : ⟦ A ⟧ \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket M_1\rrbracket_{\varrho} : \llbracket A\rrbracket [ [ Π ] ] ϱ ⊢ [ [ M 1 ] ] ϱ : [ [ A ] ] and (9) that ⟦ Γ ⟧ \llbracket\Gamma\rrbracket [ [ Γ ] ] ; ⟦ Π ⟧ ϱ ⊢ ⟦ M 2 ⟧ ϱ : ⟦ A ⟧ \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket M_2\rrbracket_{\varrho} : \llbracket A\rrbracket [ [ Π ] ] ϱ ⊢ [ [ M 2 ] ] ϱ : [ [ A ] ] , respectively.
⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ V ⟧ ϱ : Bool ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ M i ⟧ ϱ : ⟦ A ⟧ ( i ∈ { 1 , 2 } ) ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ if ⟦ V ⟧ ϱ then ⟦ M 1 ⟧ ϱ else ⟦ M 2 ⟧ ϱ : ⟦ A ⟧ T C - I f \frac{
\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket V\rrbracket_{\varrho} : \operatorname{Bool}
\qquad
\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket M_i\rrbracket_{\varrho} : \llbracket A\rrbracket\quad(i \in\{1,2\})
}{
\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\operatorname{if}\ \llbracket V\rrbracket_{\varrho}\ \operatorname{then}\ \llbracket M_1\rrbracket_{\varrho}\ \operatorname{else}\ \llbracket M_2\rrbracket_{\varrho} : \llbracket A\rrbracket
}\ \mathrm{TC\text{-}If} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ if [ [ V ] ] ϱ then [ [ M 1 ] ] ϱ else [ [ M 2 ] ] ϱ : [ [ A ] ] [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ V ] ] ϱ : Bool [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ M i ] ] ϱ : [ [ A ] ] ( i ∈ { 1 , 2 }) TC - If
Case TC-Sub: We have
Γ ; Π ; Φ ⊢ M : A ! Pure Γ ; Π ; Φ ⊢ M : A ! Mut T C - S u b \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash M : A\ !\ \operatorname{Pure}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash M : A\ !\ \operatorname{Mut}}\ \mathrm{TC\text{-}Sub} Γ ; Π ; Φ ⊢ M : A ! Mut Γ ; Π ; Φ ⊢ M : A ! Pure TC - Sub
Case TC-EvalI: We have
⟦ [ D 0 ] ↓ p I n i t D ⟧ ϱ = let r r , f , x = I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) in compInst ( r r , f , init x ) \llbracket[D_0] \mathord{\downarrow^{\mathrm{Init}}_{p}} D \rrbracket_{\varrho} = \operatorname{let}\ rr,f,x = \mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\emptyset)\ \operatorname{in}\ \operatorname{compInst}(rr,f,\operatorname{init}\ x) [ [ [ D 0 ] ↓ p Init D ] ] ϱ = let r r , f , x = I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) in compInst ( r r , f , init x )
whose right-hand side desugars to
let x 0 = I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) in let r r = fst x 0 in let x 1 = snd x 0 in let f = fst x 1 in let x = snd x 1 in let x 2 = init x in val compInst ( r r , f , x 2 ) \begin{aligned}
&\operatorname{let}\ x_0 = \mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\emptyset)\ \operatorname{in}\ \operatorname{let}\ rr = \operatorname{fst}\ x_0\ \operatorname{in}\ \operatorname{let}\ x_1 = \operatorname{snd}\ x_0\ \operatorname{in}\\
&\operatorname{let}\ f = \operatorname{fst}\ x_1\ \operatorname{in}\ \operatorname{let}\ x = \operatorname{snd}\ x_1\ \operatorname{in}\ \operatorname{let}\ x_2 = \operatorname{init}\ x\ \operatorname{in}\ \operatorname{val}\ \operatorname{compInst}(rr,f,x_2)
\end{aligned} let x 0 = I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) in let r r = fst x 0 in let x 1 = snd x 0 in let f = fst x 1 in let x = snd x 1 in let x 2 = init x in val compInst ( r r , f , x 2 )
where all x i x_i x i are fresh (as are r r rr r r , f f f , and x x x ). We also have ids ( [ D 0 ] ↓ p I n i t D ) = ids ( D 0 ) ∪ ids ( D ) \operatorname{ids}([D_0] \mathord{\downarrow^{\mathrm{Init}}_{p}} D) = \operatorname{ids}(D_0) \cup\operatorname{ids}(D) ids ([ D 0 ] ↓ p Init D ) = ids ( D 0 ) ∪ ids ( D ) and
\frac{\Gamma;\Pi;\Phi_1 \vdash D_0 : \mathcal{L} \uplus\Pi[p]\qquad\Gamma;\Pi;\Phi_2 \vdash D : \mathcal{L}\qquad\operatorname{Succ}(\Phi)}
{\Gamma;\Pi;\Phi_1 \mathbin{\bowtie} \Phi_2,p:\operatorname{Init}\vdash[D_0] \mathord{\downarrow^{\mathrm{Init}}_{p}} D:\operatorname{ElemInst}\mathbin{!}\operatorname{Mut}}
\quad\mathrm{TC\mathchar`-EvalI}
Call L 0 = L ⊎ Π [ p ] \mathcal{L}_0 = \mathcal{L} \uplus\Pi[p] L 0 = L ⊎ Π [ p ] . By definition of ⊎ \uplus ⊎ , we get (3) that L 0 ∖ L = Π [ p ] \mathcal{L}_0 \setminus\mathcal{L} = \Pi[p] L 0 ∖ L = Π [ p ] and (4) L ⊆ L 0 \mathcal{L} \subseteq\mathcal{L}_0 L ⊆ L 0 .
By (3) and definition, we get (5) ∅ ; Π ⊨ p ∅ : L 0 ∖ L \emptyset;\Pi\models_p \emptyset:\mathcal{L}_0 \setminus\mathcal{L} ∅ ; Π ⊨ p ∅ : L 0 ∖ L .
By mutual inductive hypothesis (Theorem 6.3 ) on (1), (2), (4), (5), and premise (ii), we get (6) that ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) : A c o m p \llbracket\Gamma\rrbracket;\llbracket\Pi\rrbracket_{\varrho}\vdash\mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\emptyset):A_{\mathrm{comp}} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) : A comp .
We derive the conclusion by way of subderivations (7)-(12) as follows, recalling that A c o m p ≔ ( 1 → Element ) × Ref Bool × Element A_{\mathrm{comp}} \coloneqq(1 \to\operatorname{Element}) \times\operatorname{Ref}\operatorname{Bool} \times\operatorname{Element} A comp : = ( 1 → Element ) × Ref Bool × Element , and additionally abbreviating A c o m p ′ = Ref Bool × Element A'_{\mathrm{comp}} = \operatorname{Ref}\operatorname{Bool} \times\operatorname{Element} A comp ′ = Ref Bool × Element :
\frac{
\frac{
\Gamma_7;\llbracket\Pi\rrbracket_{\varrho}\vdash rr:1\to\operatorname{Element}
\qquad
\Gamma_7;\llbracket\Pi\rrbracket_{\varrho}\vdash f:\operatorname{Ref}\operatorname{Bool}
\qquad
\Gamma_7;\llbracket\Pi\rrbracket_{\varrho}\vdash x_2:\operatorname{ElemInst}
}{
\Gamma_7;\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{compInst}(rr,f,x_2):\operatorname{ElemInst}
}\ \mathrm{TV\mathchar`-CompI}
}{
\Gamma_7;\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{val}\ \operatorname{compInst}(rr,f,x_2):\operatorname{ElemInst}
}\ \mathrm{TC\mathchar`-Val}
\frac{
\frac{
\Gamma_8;\llbracket\Pi\rrbracket_{\varrho}\vdash x:\operatorname{Element}
}{\Gamma_8;\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{init}\ x:\operatorname{ElemInst}}\ \mathrm{TC\mathchar`-Init}
\quad
[(7),\ \Gamma_7=\Gamma_8,\ x_2:\operatorname{ElemInst}]
}{
\Gamma_8;\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{let}\ x_2=\operatorname{init}\ x\ \operatorname{in}\ \cdots:\operatorname{ElemInst}
}\ \mathrm{TC\mathchar`-Let}
\frac{
\frac{
\Gamma_9;\llbracket\Pi\rrbracket_{\varrho}\vdash x_1:A'_{\mathrm{comp}}
}{\Gamma_9;\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{snd}\ x_1:\operatorname{Element}}\ \mathrm{TC\mathchar`-Snd}
\quad
[(8),\ \Gamma_8=\Gamma_9,\ x:\operatorname{Element}]
}{
\Gamma_9;\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{let}\ x=\operatorname{snd}\ x_1\ \operatorname{in}\ \cdots:\operatorname{ElemInst}
}\ \mathrm{TC\mathchar`-Let}
Γ 10 ; ⟦ Π ⟧ ϱ ⊢ x 1 : A c o m p ′ Γ 10 ; ⟦ Π ⟧ ϱ ⊢ fst x 1 : Ref Bool [ ( 9 ) , Γ 9 = Γ 10 , f : Ref Bool ] Γ 10 ; ⟦ Π ⟧ ϱ ⊢ let f = fst x 1 in ⋯ : ElemInst \frac{\Gamma_{10};\llbracket\Pi\rrbracket_{\varrho}\vdash x_1:A'_{\mathrm{comp}}}{\Gamma_{10};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{fst}x_1:\operatorname{Ref}\ \operatorname{Bool}}
\quad
\frac{[(9),\ \Gamma_9=\Gamma_{10},\ f:\operatorname{Ref}\ \operatorname{Bool}]}{\Gamma_{10};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{let}\ f=\operatorname{fst}\ x_1\ \operatorname{in}\ \cdots:\operatorname{ElemInst}} Γ 10 ; [ [ Π ] ] ϱ ⊢ fst x 1 : Ref Bool Γ 10 ; [ [ Π ] ] ϱ ⊢ x 1 : A comp ′ Γ 10 ; [ [ Π ] ] ϱ ⊢ let f = fst x 1 in ⋯ : ElemInst [( 9 ) , Γ 9 = Γ 10 , f : Ref Bool ]
Γ 11 ; ⟦ Π ⟧ ϱ ⊢ x 0 : A c o m p Γ 11 ; ⟦ Π ⟧ ϱ ⊢ snd x 0 : A c o m p ′ [ ( 10 ) , Γ 10 = Γ 11 , x 1 : A c o m p ′ ] Γ 11 ; ⟦ Π ⟧ ϱ ⊢ let x 1 = snd x 0 in ⋯ : ElemInst \frac{\Gamma_{11};\llbracket\Pi\rrbracket_{\varrho}\vdash x_0:A_{\mathrm{comp}}}{\Gamma_{11};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{snd}x_0:A'_{\mathrm{comp}}}
\quad
\frac{[(10),\ \Gamma_{10}=\Gamma_{11},\ x_1:A'_{\mathrm{comp}}]}{\Gamma_{11};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{let}\ x_1=\operatorname{snd}\ x_0\ \operatorname{in}\ \cdots:\operatorname{ElemInst}} Γ 11 ; [ [ Π ] ] ϱ ⊢ snd x 0 : A comp ′ Γ 11 ; [ [ Π ] ] ϱ ⊢ x 0 : A comp Γ 11 ; [ [ Π ] ] ϱ ⊢ let x 1 = snd x 0 in ⋯ : ElemInst [( 10 ) , Γ 10 = Γ 11 , x 1 : A comp ′ ]
Γ 12 ; ⟦ Π ⟧ ϱ ⊢ x 0 : A c o m p Γ 12 ; ⟦ Π ⟧ ϱ ⊢ fst x 0 : 1 → Element [ ( 11 ) , Γ 12 = Γ 12 , r r : 1 → Element ] Γ 12 ; ⟦ Π ⟧ ϱ ⊢ let r r = fst x 0 in ⋯ : ElemInst \frac{\Gamma_{12};\llbracket\Pi\rrbracket_{\varrho}\vdash x_0:A_{\mathrm{comp}}}{\Gamma_{12};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{fst}x_0:1\to\operatorname{Element}}
\quad
\frac{[(11),\ \Gamma_{12}=\Gamma_{12},\ rr:1\to\operatorname{Element}]}{\Gamma_{12};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{let}\ rr=\operatorname{fst}\ x_0\ \operatorname{in}\ \cdots:\operatorname{ElemInst}} Γ 12 ; [ [ Π ] ] ϱ ⊢ fst x 0 : 1 → Element Γ 12 ; [ [ Π ] ] ϱ ⊢ x 0 : A comp Γ 12 ; [ [ Π ] ] ϱ ⊢ let r r = fst x 0 in ⋯ : ElemInst [( 11 ) , Γ 12 = Γ 12 , r r : 1 → Element ]
⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) : A c o m p ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ let x 0 = I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) in ⋯ : ElemInst \frac{\llbracket\Gamma\rrbracket;\llbracket\Pi\rrbracket_{\varrho}\vdash I\llbracket D\rrbracket(D_0,p,\varrho,\varnothing):A_{\mathrm{comp}}}{\llbracket\Gamma\rrbracket;\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{let}\ x_0=I\llbracket D\rrbracket(D_0,p,\varrho,\varnothing)\ \operatorname{in}\ \cdots:\operatorname{ElemInst}} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ let x 0 = I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) in ⋯ : ElemInst [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) : A comp
Case TC-EvalS: We have
⟦ ⌈ D 0 ⌉ ↓ p S u c c D ⟧ ϱ = compInst ( λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , init S ⟦ D ⟧ ( p , ϱ , ∅ ) ) \llbracket\lceil D_0\rceil\mathrel{\downarrow^{\mathrm{Succ}}_p}D\rrbracket_{\varrho}
=\operatorname{compInst}\left(\lambda().S\llbracket D_0\rrbracket(p,\varrho,\varnothing),\varrho(p),\operatorname{init}\ S\llbracket D\rrbracket(p,\varrho,\varnothing)\right) [ [ ⌈ D 0 ⌉ ↓ p Succ D ] ] ϱ = compInst ( λ ( ) . S [ [ D 0 ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , init S [ [ D ] ] ( p , ϱ , ∅ ) )
whose right-hand side desugars to
let x 0 = S ⟦ D ⟧ ( p , ϱ , ∅ ) in let x 1 = init x 0 in val compInst ( λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , x 1 ) \begin{aligned}
&\operatorname{let}\ x_0=S\llbracket D\rrbracket(p,\varrho,\varnothing)\ \operatorname{in}\ \operatorname{let}\ x_1=\operatorname{init}\ x_0\ \operatorname{in}\\
&\operatorname{val}\ \operatorname{compInst}\left(\lambda().S\llbracket D_0\rrbracket(p,\varrho,\varnothing),\varrho(p),x_1\right)
\end{aligned} let x 0 = S [ [ D ] ] ( p , ϱ , ∅ ) in let x 1 = init x 0 in val compInst ( λ ( ) . S [ [ D 0 ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , x 1 )
where all x i x_i x i are fresh. We also have ids ( ⌈ D 0 ⌉ ↓ p S u c c D ) = ids ( D 0 ) ∪ ids ( D ) \operatorname{ids}(\lceil D_0\rceil\mathrel{\downarrow^{\mathrm{Succ}}_p}D)=\operatorname{ids}(D_0)\cup\operatorname{ids}(D) ids (⌈ D 0 ⌉ ↓ p Succ D ) = ids ( D 0 ) ∪ ids ( D ) and
Γ ; Π ; Φ 1 ⊢ D 0 : Π [ p ] Γ ; Π ; Φ 2 ⊢ D : L L ⊆ Π [ p ] ( Φ 1 ▹ ◃ Φ 2 ) [ p ] = Succ Γ ; Π ; Φ 1 ▹ ◃ Φ 2 ⊢ ⌈ D 0 ⌉ ↓ p S u c c D : ElemInst ! Mut \begin{aligned}
&\Gamma;\Pi;\Phi_1\vdash D_0:\Pi[p] \qquad\Gamma;\Pi;\Phi_2\vdash D:\mathcal{L}\\
&\mathcal{L}\subseteq\Pi[p]\qquad(\Phi_1\mathbin{\triangleright\!\triangleleft}\Phi_2)[p]=\operatorname{Succ}\\
&\Gamma;\Pi;\Phi_1\mathbin{\triangleright\!\triangleleft}\Phi_2\vdash\lceil D_0\rceil\mathrel{\downarrow^{\mathrm{Succ}}_p}D:\operatorname{ElemInst}\ !\ \operatorname{Mut}
\end{aligned} Γ ; Π ; Φ 1 ⊢ D 0 : Π [ p ] Γ ; Π ; Φ 2 ⊢ D : L L ⊆ Π [ p ] ( Φ 1 ▹ ◃ Φ 2 ) [ p ] = Succ Γ ; Π ; Φ 1 ▹ ◃ Φ 2 ⊢ ⌈ D 0 ⌉ ↓ p Succ D : ElemInst ! Mut
By premise (ii) and definition of ids, we have (4) that Π ; ids ( D 0 ) ⊨ ϱ \Pi;\operatorname{ids}(D_0)\models\varrho Π ; ids ( D 0 ) ⊨ ϱ and (5) that Π ; ids ( D ) ⊨ ϱ \Pi;\operatorname{ids}(D)\models\varrho Π ; ids ( D ) ⊨ ϱ .
By definition, we have (6) that ∅ ; Π ⊨ p ∅ : Π [ p ] \varnothing;\Pi\models_p\varnothing:\Pi[p] ∅ ; Π ⊨ p ∅ : Π [ p ] .
By (3), we also have (7) that ∅ ; Π ⊨ p ∅ : L \varnothing;\Pi\models_p\varnothing:\mathcal{L} ∅ ; Π ⊨ p ∅ : L .
By mutual inductive hypothesis (Theorem B.5 ) on (1), (4) and (6), we get (8) that ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) : Element \llbracket\Gamma\rrbracket;\llbracket\Pi\rrbracket_{\varrho}\vdash S\llbracket D_0\rrbracket(p,\varrho,\varnothing):\operatorname{Element} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ S [ [ D 0 ] ] ( p , ϱ , ∅ ) : Element .
By mutual inductive hypothesis (Theorem B.5 ) on (2), (5), and (7), we get (9) that ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ S ⟦ D ⟧ ( p , ϱ , ∅ ) : Element \llbracket\Gamma\rrbracket;\llbracket\Pi\rrbracket_{\varrho}\vdash S\llbracket D\rrbracket(p,\varrho,\varnothing):\operatorname{Element} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ S [ [ D ] ] ( p , ϱ , ∅ ) : Element .
By premise (ii), since p ∈ dom ( Π ) p\in\operatorname{dom}(\Pi) p ∈ dom ( Π ) (given e.g. by (3)), we have that ϱ ( p ) \varrho(p) ϱ ( p ) is well-defined. Then by definition of ⟦ Π ⟧ ϱ \llbracket\Pi\rrbracket_{\varrho} [ [ Π ] ] ϱ , we get (10) that ϱ ( p ) : Bool ∈ ⟦ Π ⟧ ϱ \varrho(p):\operatorname{Bool}\in\llbracket\Pi\rrbracket_{\varrho} ϱ ( p ) : Bool ∈ [ [ Π ] ] ϱ .
We derive the conclusion by way of subderivations (11)-(13) as follows, weakening (6) on Γ \Gamma Γ appropriately:
Γ 11 ; ⟦ Π ⟧ ϱ ⊢ S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) : E l e m e n t ( 8 ) \frac{\Gamma_{11};\llbracket\Pi\rrbracket_{\varrho}\vdash S\llbracket D_0\rrbracket(p,\varrho,\emptyset):\mathrm{Element}}{} \quad(8) Γ 11 ; [ [ Π ] ] ϱ ⊢ S [ [ D 0 ] ] ( p , ϱ , ∅ ) : Element ( 8 )
Γ 11 ; ⟦ Π ⟧ ϱ ⊢ S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) : E l e m e n t Γ 11 ; ⟦ Π ⟧ ϱ ⊢ λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) : 1 → E l e m e n t T V - L a m (7) \frac{\Gamma_{11};\llbracket\Pi\rrbracket_{\varrho}\vdash S\llbracket D_0\rrbracket(p,\varrho,\emptyset):\mathrm{Element}}{\Gamma_{11};\llbracket\Pi\rrbracket_{\varrho}\vdash\lambda().S\llbracket D_0\rrbracket(p,\varrho,\emptyset):1\to\mathrm{Element}}\quad\mathrm{TV\text{-}Lam} \tag*{(7)} Γ 11 ; [ [ Π ] ] ϱ ⊢ λ ( ) . S [ [ D 0 ] ] ( p , ϱ , ∅ ) : 1 → Element Γ 11 ; [ [ Π ] ] ϱ ⊢ S [ [ D 0 ] ] ( p , ϱ , ∅ ) : Element TV - Lam (7)
ϱ ( p ) : B o o l ∈ ⟦ Π ⟧ ϱ Γ 12 ; ⟦ Π ⟧ ϱ ⊢ ϱ ( p ) : R e f B o o l T V - L o c Γ 12 ; ⟦ Π ⟧ ϱ ⊢ x 1 : E l e m I n s t T V - V a r (8) \frac{\varrho(p):\mathrm{Bool}\in\llbracket\Pi\rrbracket_{\varrho}}{\Gamma_{12};\llbracket\Pi\rrbracket_{\varrho}\vdash\varrho(p):\mathrm{Ref\ Bool}}\quad\mathrm{TV\text{-}Loc}
\qquad
\frac{\Gamma_{12};\llbracket\Pi\rrbracket_{\varrho}\vdash x_1:\mathrm{ElemInst}}{}\quad\mathrm{TV\text{-}Var} \tag*{(8)} Γ 12 ; [ [ Π ] ] ϱ ⊢ ϱ ( p ) : Ref Bool ϱ ( p ) : Bool ∈ [ [ Π ] ] ϱ TV - Loc Γ 12 ; [ [ Π ] ] ϱ ⊢ x 1 : ElemInst TV - Var (8)
Γ 12 ; ⟦ Π ⟧ ϱ ⊢ λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) : 1 → E l e m e n t Γ 12 ; ⟦ Π ⟧ ϱ ⊢ ϱ ( p ) : R e f B o o l Γ 12 ; ⟦ Π ⟧ ϱ ⊢ x 1 : E l e m I n s t Γ 12 ; ⟦ Π ⟧ ϱ ⊢ compInst ( λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , x 1 ) : E l e m I n s t T V - C o m p I \frac{
\begin{gathered}
\Gamma_{12};\llbracket\Pi\rrbracket_{\varrho}\vdash\lambda().S\llbracket D_0\rrbracket(p,\varrho,\emptyset):1\to\mathrm{Element}\\
\Gamma_{12};\llbracket\Pi\rrbracket_{\varrho}\vdash\varrho(p):\mathrm{Ref\ Bool}\\
\Gamma_{12};\llbracket\Pi\rrbracket_{\varrho}\vdash x_1:\mathrm{ElemInst}
\end{gathered}
}{\Gamma_{12};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{compInst}(\lambda().S\llbracket D_0\rrbracket(p,\varrho,\emptyset),\varrho(p),x_1):\mathrm{ElemInst}}\quad\mathrm{TV\text{-}CompI} Γ 12 ; [ [ Π ] ] ϱ ⊢ compInst ( λ ( ) . S [ [ D 0 ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , x 1 ) : ElemInst Γ 12 ; [ [ Π ] ] ϱ ⊢ λ ( ) . S [ [ D 0 ] ] ( p , ϱ , ∅ ) : 1 → Element Γ 12 ; [ [ Π ] ] ϱ ⊢ ϱ ( p ) : Ref Bool Γ 12 ; [ [ Π ] ] ϱ ⊢ x 1 : ElemInst TV - CompI
Γ 12 ; ⟦ Π ⟧ ϱ ⊢ compInst ( λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , x 1 ) : E l e m I n s t Γ 12 ; ⟦ Π ⟧ ϱ ⊢ val compInst ( λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , x 1 ) : E l e m I n s t T C - V a l (9) \frac{\Gamma_{12};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{compInst}(\lambda().S\llbracket D_0\rrbracket(p,\varrho,\emptyset),\varrho(p),x_1):\mathrm{ElemInst}}{\Gamma_{12};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{val\ compInst}(\lambda().S\llbracket D_0\rrbracket(p,\varrho,\emptyset),\varrho(p),x_1):\mathrm{ElemInst}}\quad\mathrm{TC\text{-}Val} \tag*{(9)} Γ 12 ; [ [ Π ] ] ϱ ⊢ val compInst ( λ ( ) . S [ [ D 0 ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , x 1 ) : ElemInst Γ 12 ; [ [ Π ] ] ϱ ⊢ compInst ( λ ( ) . S [ [ D 0 ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , x 1 ) : ElemInst TC - Val (9)
Γ 13 ; ⟦ Π ⟧ ϱ ⊢ x 0 : E l e m e n t T V - V a r \frac{\Gamma_{13};\llbracket\Pi\rrbracket_{\varrho}\vdash x_0:\mathrm{Element}}{}\quad\mathrm{TV\text{-}Var} Γ 13 ; [ [ Π ] ] ϱ ⊢ x 0 : Element TV - Var
Γ 13 ; ⟦ Π ⟧ ϱ ⊢ x 0 : E l e m e n t Γ 13 ; ⟦ Π ⟧ ϱ ⊢ init x 0 : E l e m I n s t T C - I n i t \frac{\Gamma_{13};\llbracket\Pi\rrbracket_{\varrho}\vdash x_0:\mathrm{Element}}{\Gamma_{13};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{init}x_0:\mathrm{ElemInst}}\quad\mathrm{TC\text{-}Init} Γ 13 ; [ [ Π ] ] ϱ ⊢ init x 0 : ElemInst Γ 13 ; [ [ Π ] ] ϱ ⊢ x 0 : Element TC - Init
Γ 12 ; ⟦ Π ⟧ ϱ ⊢ val compInst ( λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , x 1 ) : E l e m I n s t Γ 13 ; ⟦ Π ⟧ ϱ ⊢ init x 0 : E l e m I n s t Γ 13 ; ⟦ Π ⟧ ϱ ⊢ let x 1 = init x 0 in ⋯ : E l e m I n s t T C - L e t (10) \frac{\Gamma_{12};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{val\ compInst}(\lambda().S\llbracket D_0\rrbracket(p,\varrho,\emptyset),\varrho(p),x_1):\mathrm{ElemInst}
\qquad
\Gamma_{13};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{init}x_0:\mathrm{ElemInst}}
{\Gamma_{13};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{let}x_1=\operatorname{init}x_0\operatorname{\ in}\cdots:\mathrm{ElemInst}}\quad\mathrm{TC\text{-}Let} \tag*{(10)} Γ 13 ; [ [ Π ] ] ϱ ⊢ let x 1 = init x 0 in ⋯ : ElemInst Γ 12 ; [ [ Π ] ] ϱ ⊢ val compInst ( λ ( ) . S [ [ D 0 ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , x 1 ) : ElemInst Γ 13 ; [ [ Π ] ] ϱ ⊢ init x 0 : ElemInst TC - Let (10)
⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ S ⟦ D ⟧ ( p , ϱ , ∅ ) : E l e m e n t ( 7 ) \frac{\llbracket\Gamma\rrbracket;\llbracket\Pi\rrbracket_{\varrho}\vdash S\llbracket D\rrbracket(p,\varrho,\emptyset):\mathrm{Element}}{}\quad(7) [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ S [ [ D ] ] ( p , ϱ , ∅ ) : Element ( 7 )
⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ S ⟦ D ⟧ ( p , ϱ , ∅ ) : E l e m e n t ⟦ Γ ⟧ = ⟦ Γ ⟧ , x 0 : E l e m e n t ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ let x 0 = S ⟦ D ⟧ ( p , ϱ , ∅ ) in ⋯ : E l e m I n s t T C - L e t \frac{\llbracket\Gamma\rrbracket;\llbracket\Pi\rrbracket_{\varrho}\vdash S\llbracket D\rrbracket(p,\varrho,\emptyset):\mathrm{Element}
\qquad
\llbracket\Gamma\rrbracket=\llbracket\Gamma\rrbracket,\ x_0:\mathrm{Element}}
{\llbracket\Gamma\rrbracket;\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{let}x_0=S\llbracket D\rrbracket(p,\varrho,\emptyset)\operatorname{\ in}\cdots:\mathrm{ElemInst}}\quad\mathrm{TC\text{-}Let} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ let x 0 = S [ [ D ] ] ( p , ϱ , ∅ ) in ⋯ : ElemInst [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ S [ [ D ] ] ( p , ϱ , ∅ ) : Element [ [ Γ ] ] = [ [ Γ ] ] , x 0 : Element TC - Let
Theorem B.5 (Type preservation, bodies, successor). If
(i) Γ ; Π ; Φ ⊢ D : L \Gamma;\Pi;\Phi\vdash D:L Γ ; Π ; Φ ⊢ D : L ,
(ii) Π ; ids ( D ) ⊨ ϱ \Pi;\operatorname{ids}(D)\models\varrho Π ; ids ( D ) ⊨ ϱ , and
(iii) Γ ′ ; Π ⊨ p δ : L \Gamma';\Pi\models_p\delta:L Γ ′ ; Π ⊨ p δ : L ,
then ⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ S ⟦ D ⟧ ( p , ϱ , δ ) : E l e m e n t \llbracket\Gamma\rrbracket,\Gamma';\llbracket\Pi\rrbracket_{\varrho}\vdash S\llbracket D\rrbracket(p,\varrho,\delta):\mathrm{Element} [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ S [ [ D ] ] ( p , ϱ , δ ) : Element .
Proof. By mutual induction on the derivation of the body typing judgment (i) with Theorems B.3 , B.4 , and 6.3 .
Case TB-Val: We have S ⟦ val V ⟧ ( p , ϱ , δ ) = val ⟦ V ⟧ ϱ S\llbracket\operatorname{val}\ V\rrbracket(p,\varrho,\delta)=\operatorname{val}\ \llbracket V\rrbracket_{\varrho} S [ [ val V ] ] ( p , ϱ , δ ) = val [ [ V ] ] ϱ and
Γ ; Π ; Φ ⊢ V : E l e m e n t Γ ; Π ; Φ ⊢ V : ∅ T B - V a l (11) \frac{\Gamma;\Pi;\Phi\vdash V:\mathrm{Element}}{\Gamma;\Pi;\Phi\vdash V:\emptyset}\quad\mathrm{TB\text{-}Val} \tag*{(11)} Γ ; Π ; Φ ⊢ V : ∅ Γ ; Π ; Φ ⊢ V : Element TB - Val (11) By mutual inductive hypothesis (Theorem B.3 ) on (1) and premise (ii), we have (2) that ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ V ⟧ ϱ : E l e m e n t \llbracket\Gamma\rrbracket;\llbracket\Pi\rrbracket_{\varrho}\vdash\llbracket V\rrbracket_{\varrho}:\mathrm{Element} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ V ] ] ϱ : Element .
Weakening (2) on Γ ′ \Gamma' Γ ′ gives us (12) that ⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ ⟦ V ⟧ ϱ : E l e m e n t \llbracket\Gamma\rrbracket,\Gamma';\llbracket\Pi\rrbracket_{\varrho}\vdash\llbracket V\rrbracket_{\varrho}:\mathrm{Element} [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ [ [ V ] ] ϱ : Element .
We derive the conclusion as follows:
⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ ⟦ V ⟧ ϱ : E l e m e n t ⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ val ⟦ V ⟧ ϱ : E l e m e n t T C - V a l (12) \frac{\llbracket\Gamma\rrbracket,\Gamma';\llbracket\Pi\rrbracket_{\varrho}\vdash\llbracket V\rrbracket_{\varrho}:\mathrm{Element}}{\llbracket\Gamma\rrbracket,\Gamma';\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{val}\ \llbracket V\rrbracket_{\varrho}:\mathrm{Element}}\quad\mathrm{TC\text{-}Val} \tag*{(12)} [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ val [ [ V ] ] ϱ : Element [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ [ [ V ] ] ϱ : Element TC - Val (12) Case TB-Let: We have
S ⟦ let x = M in D ⟧ ( p , ϱ , δ ) = let x = ⟦ M ⟧ ϱ in S ⟦ D ⟧ ( p , ϱ , δ ) S\llbracket\operatorname{let}\ x=M\operatorname{\ in}D\rrbracket(p,\varrho,\delta)=\operatorname{let}\ x=\llbracket M\rrbracket_{\varrho}\operatorname{\ in}S\llbracket D\rrbracket(p,\varrho,\delta) S [ [ let x = M in D ] ] ( p , ϱ , δ ) = let x = [ [ M ] ] ϱ in S [ [ D ] ] ( p , ϱ , δ ) ids ( let x = M in D ) = ids ( M ) ∪ ids ( D ) \operatorname{ids}(\operatorname{let}\ x=M\operatorname{\ in}D)=\operatorname{ids}(M)\cup\operatorname{ids}(D) ids ( let x = M in D ) = ids ( M ) ∪ ids ( D )
Γ ; Π ; Φ 1 ⊢ M : A ! P u r e Γ , x : A ; Π ; Φ 2 ⊢ D : L Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ l e t x = M i n D : L T B - L e t \frac{\Gamma; \Pi; \Phi_1 \vdash M : A\ {!}\ \mathrm{Pure}\qquad\Gamma,x:A ; \Pi; \Phi_2 \vdash D : L}{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\mathrm{let}\ x=M\ \mathrm{in}\ D : L}\ \mathrm{TB\text{-}Let} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in D : L Γ ; Π ; Φ 1 ⊢ M : A ! Pure Γ , x : A ; Π ; Φ 2 ⊢ D : L TB - Let
By premise ( i i ) (ii) ( ii ) and definition of ids, we have (3) that Π ; ids ( M ) ⊨ ϱ \Pi; \operatorname{ids}(M) \models\varrho Π ; ids ( M ) ⊨ ϱ and (4) that Π ; ids ( D ) ⊨ ϱ \Pi; \operatorname{ids}(D) \models\varrho Π ; ids ( D ) ⊨ ϱ .
By mutual inductive hypothesis (Theorem B.4 ) on (1) and (3), we get (5) that ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ M ⟧ ϱ : ⟦ A ⟧ \llbracket\Gamma\rrbracket; \llbracket\Pi\rrbracket_\varrho\vdash\llbracket M\rrbracket_\varrho: \llbracket A\rrbracket [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ M ] ] ϱ : [ [ A ] ] .
By inductive hypothesis on (2), (4), and premise ( i i i ) (iii) ( iii ) , we get (6) that ⟦ Γ ⟧ , x : ⟦ A ⟧ ; ⟦ Π ⟧ ϱ ⊢ S ⟦ D ⟧ ( p , ϱ , δ ) : E l e m e n t \llbracket\Gamma\rrbracket,x:\llbracket A\rrbracket; \llbracket\Pi\rrbracket_\varrho\vdash S\llbracket D\rrbracket(p,\varrho,\delta) : \mathrm{Element} [ [ Γ ] ] , x : [ [ A ] ] ; [ [ Π ] ] ϱ ⊢ S [ [ D ] ] ( p , ϱ , δ ) : Element .
We derive the conclusion as follows:
⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ M ⟧ ϱ : ⟦ A ⟧ ⟦ Γ ⟧ , x : ⟦ A ⟧ ; ⟦ Π ⟧ ϱ ⊢ S ⟦ D ⟧ ( p , ϱ , δ ) : E l e m e n t ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ l e t x = ⟦ M ⟧ ϱ i n S ⟦ D ⟧ ( p , ϱ , δ ) : E l e m e n t T C - L e t \frac{\llbracket\Gamma\rrbracket; \llbracket\Pi\rrbracket_\varrho\vdash\llbracket M\rrbracket_\varrho: \llbracket A\rrbracket\qquad\llbracket\Gamma\rrbracket,x:\llbracket A\rrbracket; \llbracket\Pi\rrbracket_\varrho\vdash S\llbracket D\rrbracket(p,\varrho,\delta) : \mathrm{Element}}{\llbracket\Gamma\rrbracket; \llbracket\Pi\rrbracket_\varrho\vdash\mathrm{let}\ x=\llbracket M\rrbracket_\varrho\ \mathrm{in}\ S\llbracket D\rrbracket(p,\varrho,\delta) : \mathrm{Element}}\ \mathrm{TC\text{-}Let} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ let x = [ [ M ] ] ϱ in S [ [ D ] ] ( p , ϱ , δ ) : Element [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ M ] ] ϱ : [ [ A ] ] [ [ Γ ] ] , x : [ [ A ] ] ; [ [ Π ] ] ϱ ⊢ S [ [ D ] ] ( p , ϱ , δ ) : Element TC - Let
Case TB-State: We have
S ⟦ l e t x , x s e t = u s e S t a t e ℓ V i n D ⟧ ( p , ϱ , δ ) = l e t x = ! δ ( p , ℓ , ϱ ) i n l e t x s e t = v a l λ y . ( δ ( p , ℓ , ϱ ) : = y ; δ ( p , ϱ ) : = t r u e ) i n S ⟦ D ⟧ ( p , ϱ , δ ) S\llbracket\mathrm{let}\ x,x_{\mathrm{set}}=\mathrm{useState}^{\ell}\ V\ \mathrm{in}\ D\rrbracket(p,\varrho,\delta)
=
\mathrm{let}\ x=! \delta(p,\ell,\varrho)\ \mathrm{in}
\mathrm{let}\ x_{\mathrm{set}}=\mathrm{val}\ \lambda y.(\delta(p,\ell,\varrho):=y\ ;\ \delta(p,\varrho):=\mathrm{true})\ \mathrm{in}
S\llbracket D\rrbracket(p,\varrho,\delta) S [ [ let x , x set = useState ℓ V in D ] ] ( p , ϱ , δ ) = let x = ! δ ( p , ℓ , ϱ ) in let x set = val λ y . ( δ ( p , ℓ , ϱ ) := y ; δ ( p , ϱ ) := true ) in S [ [ D ] ] ( p , ϱ , δ )
ids ( l e t x , x s e t = u s e S t a t e ℓ V i n D ) = ids ( V ) ∪ ids ( D ) \operatorname{ids}(\mathrm{let}\ x,x_{\mathrm{set}}=\mathrm{useState}^{\ell}\ V\ \mathrm{in}\ D)
=
\operatorname{ids}(V)\cup\operatorname{ids}(D) ids ( let x , x set = useState ℓ V in D ) = ids ( V ) ∪ ids ( D )
Γ ; Π ; Φ 1 ⊢ V : A Γ , x : A , x s e t : A → M u t 1 ; Π ; Φ 2 ⊢ D : L ℓ ∉ dom ( L ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ l e t x , x s e t = u s e S t a t e ℓ V i n D : L , ℓ : A T B - S t a t e \frac{\Gamma; \Pi; \Phi_1 \vdash V:A\qquad\Gamma,x:A,x_{\mathrm{set}}:A \xrightarrow{\mathrm{Mut}} 1 ; \Pi; \Phi_2 \vdash D:L\qquad\ell\notin\operatorname{dom}(L)}{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\mathrm{let}\ x,x_{\mathrm{set}}=\mathrm{useState}^{\ell}\ V\ \mathrm{in}\ D : L,\ell:A}\ \mathrm{TB\text{-}State} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x set = useState ℓ V in D : L , ℓ : A Γ ; Π ; Φ 1 ⊢ V : A Γ , x : A , x set : A Mut 1 ; Π ; Φ 2 ⊢ D : L ℓ ∈ / dom ( L ) TB - State
By premise ( i i ) (ii) ( ii ) and definition of ids, we have (2) that Π ; ids ( D ) ⊨ ϱ \Pi; \operatorname{ids}(D) \models\varrho Π ; ids ( D ) ⊨ ϱ .
From premise ( i i ) (ii) ( ii ) it also follows that (3) Π ; ∅ ⊨ ϱ \Pi; \varnothing\models\varrho Π ; ∅ ⊨ ϱ .
Since we have Γ ′ ; Π ⊨ p δ : L , ℓ : A \Gamma' ; \Pi\models_p \delta: L,\ell:A Γ ′ ; Π ⊨ p δ : L , ℓ : A from premise ( i i i ) (iii) ( iii ) , by definition we also have (4) that Γ ′ ; Π ⊨ p δ : L \Gamma' ; \Pi\models_p \delta: L Γ ′ ; Π ⊨ p δ : L .
By inductive hypothesis on (1), (2), and (4), we get (5) that ⟦ Γ , x : A , x s e t : A → M u t 1 ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ S ⟦ D ⟧ ( p , ϱ , δ ) : E l e m e n t \llbracket\Gamma,x:A,x_{\mathrm{set}}:A \xrightarrow{\mathrm{Mut}} 1\rrbracket,\Gamma' ; \llbracket\Pi\rrbracket_\varrho\vdash S\llbracket D\rrbracket(p,\varrho,\delta) : \mathrm{Element} [ [ Γ , x : A , x set : A Mut 1 ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ S [ [ D ] ] ( p , ϱ , δ ) : Element .
By definition, (5) is equivalent to (6) that ⟦ Γ ⟧ , Γ ′ , x : ⟦ A ⟧ , x s e t : ⟦ A ⟧ → 1 ; ⟦ Π ⟧ ϱ ⊢ S ⟦ D ⟧ ( p , ϱ , δ ) : E l e m e n t \llbracket\Gamma\rrbracket,\Gamma',x:\llbracket A\rrbracket,x_{\mathrm{set}}:\llbracket A\rrbracket\to1 ; \llbracket\Pi\rrbracket_\varrho\vdash S\llbracket D\rrbracket(p,\varrho,\delta) : \mathrm{Element} [ [ Γ ] ] , Γ ′ , x : [ [ A ] ] , x set : [ [ A ] ] → 1 ; [ [ Π ] ] ϱ ⊢ S [ [ D ] ] ( p , ϱ , δ ) : Element .
By Lemma B.2 (label typing) on (3) and premise ( i i i ) (iii) ( iii ) , we get (7) that Γ ′ ; ⟦ Π ⟧ ϱ ⊢ δ ( p , ℓ , ϱ ) : R e f ⟦ A ⟧ \Gamma' ; \llbracket\Pi\rrbracket_\varrho\vdash\delta(p,\ell,\varrho) : \mathrm{Ref}\ \llbracket A\rrbracket Γ ′ ; [ [ Π ] ] ϱ ⊢ δ ( p , ℓ , ϱ ) : Ref [ [ A ] ] .
By B.1 (flag typing) on (3) and premise ( i i i ) (iii) ( iii ) , we get (8) that Γ ′ ; ⟦ Π ⟧ ϱ ⊢ δ ( p , ϱ ) : R e f B o o l \Gamma' ; \llbracket\Pi\rrbracket_\varrho\vdash\delta(p,\varrho) : \mathrm{Ref}\ \mathrm{Bool} Γ ′ ; [ [ Π ] ] ϱ ⊢ δ ( p , ϱ ) : Ref Bool .
Γ 9 ; ⟦ Π ⟧ ϱ ⊢ δ ( p , ℓ , ϱ ) : Ref ⟦ A ⟧ Γ 9 ; ⟦ Π ⟧ ϱ ⊢ y : ⟦ A ⟧ Γ 9 ; ⟦ Π ⟧ ϱ ⊢ δ ( p , ℓ , ϱ ) : = y : 1 TV-Var (13) \frac{\Gamma_9 ; \llbracket\Pi\rrbracket_\varrho\vdash\delta(p,\ell,\varrho) : \operatorname{Ref}\llbracket A \rrbracket\qquad\Gamma_9 ; \llbracket\Pi\rrbracket_\varrho\vdash y : \llbracket A \rrbracket}{\Gamma_9 ; \llbracket\Pi\rrbracket_\varrho\vdash\delta(p,\ell,\varrho) := y : 1}
\quad\text{TV-Var} \tag*{(13)} Γ 9 ; [ [ Π ] ] ϱ ⊢ δ ( p , ℓ , ϱ ) := y : 1 Γ 9 ; [ [ Π ] ] ϱ ⊢ δ ( p , ℓ , ϱ ) : Ref [ [ A ] ] Γ 9 ; [ [ Π ] ] ϱ ⊢ y : [ [ A ] ] TV-Var (13)
Γ 10 ; ⟦ Π ⟧ ϱ ⊢ δ ( p , ϱ ) : Ref Bool Γ 10 ; ⟦ Π ⟧ ϱ ⊢ true : Bool Γ 10 ; ⟦ Π ⟧ ϱ ⊢ δ ( p , ϱ ) : = true : 1 TV-True (14) \frac{\Gamma_{10} ; \llbracket\Pi\rrbracket_\varrho\vdash\delta(p,\varrho) : \operatorname{Ref}\operatorname{Bool} \qquad\Gamma_{10} ; \llbracket\Pi\rrbracket_\varrho\vdash\operatorname{true} : \operatorname{Bool}}{\Gamma_{10} ; \llbracket\Pi\rrbracket_\varrho\vdash\delta(p,\varrho) := \operatorname{true} : 1}
\quad\text{TV-True} \tag*{(14)} Γ 10 ; [ [ Π ] ] ϱ ⊢ δ ( p , ϱ ) := true : 1 Γ 10 ; [ [ Π ] ] ϱ ⊢ δ ( p , ϱ ) : Ref Bool Γ 10 ; [ [ Π ] ] ϱ ⊢ true : Bool TV-True (14)
[ ( 9 ) , Γ 9 = Γ 11 , y : ⟦ A ⟧ ] [ ( 10 ) , Γ 10 = Γ 11 , y : ⟦ A ⟧ ] Γ 11 , y : ⟦ A ⟧ ; ⟦ Π ⟧ ϱ ⊢ δ ( p , ℓ , ϱ ) : = y ; δ ( p , ϱ ) : = true : 1 TC-Let \frac{[(9),\ \Gamma_9=\Gamma_{11},\ y:\llbracket A\rrbracket]\qquad[(10),\ \Gamma_{10}=\Gamma_{11},\ y:\llbracket A\rrbracket]}{\Gamma_{11},y:\llbracket A\rrbracket; \llbracket\Pi\rrbracket_\varrho\vdash\delta(p,\ell,\varrho):=y\ ;\ \delta(p,\varrho):=\operatorname{true}:1}
\quad\text{TC-Let} Γ 11 , y : [ [ A ] ] ; [ [ Π ] ] ϱ ⊢ δ ( p , ℓ , ϱ ) := y ; δ ( p , ϱ ) := true : 1 [( 9 ) , Γ 9 = Γ 11 , y : [ [ A ] ] ] [( 10 ) , Γ 10 = Γ 11 , y : [ [ A ] ] ] TC-Let
Γ 11 ; ⟦ Π ⟧ ϱ ⊢ λ y . ( δ ( p , ℓ , ϱ ) : = y ; δ ( p , ϱ ) : = true ) : ⟦ A ⟧ → 1 Γ 11 ; ⟦ Π ⟧ ϱ ⊢ val λ y . ( δ ( p , ℓ , ϱ ) : = y ; δ ( p , ϱ ) : = true ) : ⟦ A ⟧ → 1 TV-Lam \frac{\Gamma_{11};\llbracket\Pi\rrbracket_\varrho\vdash\lambda y.(\delta(p,\ell,\varrho):=y\ ;\ \delta(p,\varrho):=\operatorname{true}):\llbracket A\rrbracket\to1}{\Gamma_{11};\llbracket\Pi\rrbracket_\varrho\vdash\operatorname{val}\lambda y.(\delta(p,\ell,\varrho):=y\ ;\ \delta(p,\varrho):=\operatorname{true}):\llbracket A\rrbracket\to1}
\quad\text{TV-Lam} Γ 11 ; [ [ Π ] ] ϱ ⊢ val λ y . ( δ ( p , ℓ , ϱ ) := y ; δ ( p , ϱ ) := true ) : [ [ A ] ] → 1 Γ 11 ; [ [ Π ] ] ϱ ⊢ λ y . ( δ ( p , ℓ , ϱ ) := y ; δ ( p , ϱ ) := true ) : [ [ A ] ] → 1 TV-Lam
Γ 11 ; ⟦ Π ⟧ ϱ ⊢ val λ y . ( δ ( p , ℓ , ϱ ) : = y ; δ ( p , ϱ ) : = true ) : ⟦ A ⟧ → 1 \Gamma_{11};\llbracket\Pi\rrbracket_\varrho\vdash\operatorname{val}\lambda y.(\delta(p,\ell,\varrho):=y\ ;\ \delta(p,\varrho):=\operatorname{true}):\llbracket A\rrbracket\to1 Γ 11 ; [ [ Π ] ] ϱ ⊢ val λ y . ( δ ( p , ℓ , ϱ ) := y ; δ ( p , ϱ ) := true ) : [ [ A ] ] → 1
[ ( 11 ) , Γ 11 = Γ 12 ] Γ 12 , x s e t : ⟦ A ⟧ → 1 ; ⟦ Π ⟧ ϱ ⊢ S ⟦ D ⟧ ( p , ϱ , δ ) : Element Γ 12 ; ⟦ Π ⟧ ϱ ⊢ let x s e t = ⋯ in S ⟦ D ⟧ ( p , ϱ , δ ) : Element TC-Let (15) \frac{[(11),\ \Gamma_{11}=\Gamma_{12}]\qquad\Gamma_{12},x_{\mathrm{set}}:\llbracket A\rrbracket\to1\ ;\ \llbracket\Pi\rrbracket_\varrho\vdash S\llbracket D\rrbracket(p,\varrho,\delta):\operatorname{Element}}{\Gamma_{12};\llbracket\Pi\rrbracket_\varrho\vdash\operatorname{let}\ x_{\mathrm{set}}=\cdots\ \operatorname{in}\ S\llbracket D\rrbracket(p,\varrho,\delta):\operatorname{Element}}
\quad\text{TC-Let} \tag*{(15)} Γ 12 ; [ [ Π ] ] ϱ ⊢ let x set = ⋯ in S [ [ D ] ] ( p , ϱ , δ ) : Element [( 11 ) , Γ 11 = Γ 12 ] Γ 12 , x set : [ [ A ] ] → 1 ; [ [ Π ] ] ϱ ⊢ S [ [ D ] ] ( p , ϱ , δ ) : Element TC-Let (15)
⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ δ ( p , ℓ , ϱ ) : Ref ⟦ A ⟧ ⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ ! δ ( p , ℓ , ϱ ) : ⟦ A ⟧ TC-Get \frac{\llbracket\Gamma\rrbracket,\Gamma' ; \llbracket\Pi\rrbracket_\varrho\vdash\delta(p,\ell,\varrho):\operatorname{Ref}\llbracket A\rrbracket}{\llbracket\Gamma\rrbracket,\Gamma' ; \llbracket\Pi\rrbracket_\varrho\vdash{!}\delta(p,\ell,\varrho):\llbracket A\rrbracket}
\quad\text{TC-Get} [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ ! δ ( p , ℓ , ϱ ) : [ [ A ] ] [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ δ ( p , ℓ , ϱ ) : Ref [ [ A ] ] TC-Get
[ ( 12 ) , Γ 12 = ⟦ Γ ⟧ , Γ ′ , x : ⟦ A ⟧ ] ⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ let x = ! δ ( p , ℓ , ϱ ) in ⋯ : Element TC-Let \frac{[(12),\ \Gamma_{12}=\llbracket\Gamma\rrbracket,\Gamma',x:\llbracket A\rrbracket]\qquad\llbracket\Gamma\rrbracket,\Gamma' ; \llbracket\Pi\rrbracket_\varrho\vdash\operatorname{let}\ x={!}\delta(p,\ell,\varrho)\ \operatorname{in}\ \cdots:\operatorname{Element}}{}
\quad\text{TC-Let} [( 12 ) , Γ 12 = [ [ Γ ] ] , Γ ′ , x : [ [ A ] ] ] [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ let x = ! δ ( p , ℓ , ϱ ) in ⋯ : Element TC-Let
Type preservation, bodies, initial
Theorem 6.3 (Type preservation, bodies, initial). If
Γ ; Π ; Φ 1 ⊢ D : L \Gamma;\Pi;\Phi_1\vdash D:L Γ ; Π ; Φ 1 ⊢ D : L ,
Γ ; Π ; Φ 2 ⊢ D 0 : L 0 \Gamma;\Pi;\Phi_2\vdash D_0:L_0 Γ ; Π ; Φ 2 ⊢ D 0 : L 0 (where L ⊆ L 0 L\subseteq L_0 L ⊆ L 0 ),
Π ; ids ( D ) ∪ ids ( D 0 ) ⊨ ϱ \Pi;\operatorname{ids}(D)\cup\operatorname{ids}(D_0)\models\varrho Π ; ids ( D ) ∪ ids ( D 0 ) ⊨ ϱ , and
Γ ′ ; Π ⊨ p δ : ( L 0 ∖ L ) \Gamma';\Pi\models_p\delta:(L_0\setminus L) Γ ′ ; Π ⊨ p δ : ( L 0 ∖ L ) ,
then ⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ I ⟦ D ⟧ ( D 0 , p , ϱ , δ ) : A c o m p \llbracket\Gamma\rrbracket,\Gamma';\llbracket\Pi\rrbracket_\varrho\vdash I\llbracket D\rrbracket(D_0,p,\varrho,\delta):A_{\mathrm{comp}} [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ I [ [ D ] ] ( D 0 , p , ϱ , δ ) : A comp .
Proof. By mutual induction on the derivation of the body typing judgment (i) with Theorems Theorems B.3 , B.4 , and B.5 . (Recall that A c o m p ≜ ( 1 → Element ) × Ref Bool × Element A_{\mathrm{comp}}\triangleq(1\to\operatorname{Element})\times\operatorname{Ref}\operatorname{Bool}\times\operatorname{Element} A comp ≜ ( 1 → Element ) × Ref Bool × Element .)
Case TB-Val: We have
I ⟦ val V ⟧ ( D 0 , p , ϱ , δ ) = val ( λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , δ ) , δ ( p , ϱ ) , ⟦ V ⟧ ϱ ) I\llbracket\operatorname{val}\ V\rrbracket(D_0,p,\varrho,\delta)=\operatorname{val}\left(\lambda().S\llbracket D_0\rrbracket(p,\varrho,\delta),\delta(p,\varrho),\llbracket V\rrbracket_\varrho\right) I [ [ val V ] ] ( D 0 , p , ϱ , δ ) = val ( λ ( ) . S [ [ D 0 ] ] ( p , ϱ , δ ) , δ ( p , ϱ ) , [ [ V ] ] ϱ )
Γ ; Π ; Φ 1 ⊢ V : Element Γ ; Π ; Φ 1 ⊢ val V : ∅ TB-Val (16) \frac{\Gamma;\Pi;\Phi_1\vdash V:\operatorname{Element}}{\Gamma;\Pi;\Phi_1\vdash\operatorname{val}\ V:\varnothing}
\quad\text{TB-Val} \tag*{(16)} Γ ; Π ; Φ 1 ⊢ val V : ∅ Γ ; Π ; Φ 1 ⊢ V : Element TB-Val (16)
By premise (iii) and definition of ids, we have (2) that Π ; ids ( V ) ⊨ ϱ \Pi;\operatorname{ids}(V)\models\varrho Π ; ids ( V ) ⊨ ϱ , (3) that Π ; ids ( D 0 ) ⊨ ϱ \Pi;\operatorname{ids}(D_0)\models\varrho Π ; ids ( D 0 ) ⊨ ϱ , and (4) that Π ; ∅ ⊨ ϱ \Pi;\varnothing\models\varrho Π ; ∅ ⊨ ϱ .
By mutual inductive hypothesis (Theorem B.3 ) on (1) and (2), we have (5) that ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ V ⟧ ϱ : Element \llbracket\Gamma\rrbracket;\llbracket\Pi\rrbracket_\varrho\vdash\llbracket V\rrbracket_\varrho:\operatorname{Element} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ V ] ] ϱ : Element .
Since we have L = ∅ L=\varnothing L = ∅ , premise (iv) reduces to (6) that Γ ′ ; Π ⊨ p δ : L 0 \Gamma';\Pi\models_p\delta:L_0 Γ ′ ; Π ⊨ p δ : L 0 .
By mutual inductive hypothesis (Theorem B.5 ) on (3), (6), and premise (ii) we have (7) that ⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ S ⟦ D 0 ⟧ ( p , ϱ , δ ) : Element \llbracket\Gamma\rrbracket,\Gamma';\llbracket\Pi\rrbracket_\varrho\vdash S\llbracket D_0\rrbracket(p,\varrho,\delta):\operatorname{Element} [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ S [ [ D 0 ] ] ( p , ϱ , δ ) : Element .
By Lemma B.1 (flag typing) on (4) and (6), we get (8) that Γ ′ ; ⟦ Π ⟧ ϱ ⊢ δ ( p , ϱ ) : Ref Bool \Gamma';\llbracket\Pi\rrbracket_\varrho\vdash\delta(p,\varrho):\operatorname{Ref}\operatorname{Bool} Γ ′ ; [ [ Π ] ] ϱ ⊢ δ ( p , ϱ ) : Ref Bool .
⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ S ⟦ D 0 ⟧ ( p , ϱ , δ ) : E l e m e n t ⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , δ ) : 1 → E l e m e n t (17) \frac{\llbracket\Gamma\rrbracket,\Gamma';\llbracket\Pi\rrbracket_{\varrho}\vdash S\llbracket D_0\rrbracket(p,\varrho,\delta):\mathrm{Element}}{\llbracket\Gamma\rrbracket,\Gamma';\llbracket\Pi\rrbracket_{\varrho}\vdash\lambda().S\llbracket D_0\rrbracket(p,\varrho,\delta):1\to\mathrm{Element}} \tag*{(17)} [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ λ ( ) . S [ [ D 0 ] ] ( p , ϱ , δ ) : 1 → Element [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ S [ [ D 0 ] ] ( p , ϱ , δ ) : Element (17)
⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ δ ( p , ϱ ) : R e f B o o l ⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ ⟦ V ⟧ ϱ : E l e m e n t ⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ ( δ ( p , ϱ ) , ⟦ V ⟧ ϱ ) : R e f B o o l × E l e m e n t (18) \frac{\llbracket\Gamma\rrbracket,\Gamma';\llbracket\Pi\rrbracket_{\varrho}\vdash\delta(p,\varrho):\mathrm{Ref\ Bool}\qquad\llbracket\Gamma\rrbracket,\Gamma';\llbracket\Pi\rrbracket_{\varrho}\vdash\llbracket V\rrbracket_{\varrho}:\mathrm{Element}}{\llbracket\Gamma\rrbracket,\Gamma';\llbracket\Pi\rrbracket_{\varrho}\vdash(\delta(p,\varrho),\llbracket V\rrbracket_{\varrho}):\mathrm{Ref\ Bool}\times\mathrm{Element}} \tag*{(18)} [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ ( δ ( p , ϱ ) , [ [ V ] ] ϱ ) : Ref Bool × Element [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ δ ( p , ϱ ) : Ref Bool [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ [ [ V ] ] ϱ : Element (18)
⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ ( λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , δ ) , δ ( p , ϱ ) , ⟦ V ⟧ ϱ ) : A c o m p ⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ v a l ( λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , δ ) , δ ( p , ϱ ) , ⟦ V ⟧ ϱ ) : A c o m p \frac{\llbracket\Gamma\rrbracket,\Gamma';\llbracket\Pi\rrbracket_{\varrho}\vdash(\lambda().S\llbracket D_0\rrbracket(p,\varrho,\delta),\delta(p,\varrho),\llbracket V\rrbracket_{\varrho}):A_{\mathrm{comp}}}{\llbracket\Gamma\rrbracket,\Gamma';\llbracket\Pi\rrbracket_{\varrho}\vdash\mathrm{val}\,(\lambda().S\llbracket D_0\rrbracket(p,\varrho,\delta),\delta(p,\varrho),\llbracket V\rrbracket_{\varrho}):A_{\mathrm{comp}}} [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ val ( λ ( ) . S [ [ D 0 ] ] ( p , ϱ , δ ) , δ ( p , ϱ ) , [ [ V ] ] ϱ ) : A comp [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ ( λ ( ) . S [ [ D 0 ] ] ( p , ϱ , δ ) , δ ( p , ϱ ) , [ [ V ] ] ϱ ) : A comp
Case TB-Let: We have I ⟦ l e t x = M i n D ⟧ ( D 0 , p , ϱ , δ ) = l e t x = ⟦ M ⟧ ϱ i n I ⟦ D ⟧ ( D 0 , p , ϱ , δ ) \mathcal{I}\llbracket\mathrm{let}\ x=M\ \mathrm{in}\ D\rrbracket(D_0,p,\varrho,\delta)=\mathrm{let}\ x=\llbracket M\rrbracket_{\varrho}\ \mathrm{in}\ \mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\delta) I [ [ let x = M in D ] ] ( D 0 , p , ϱ , δ ) = let x = [ [ M ] ] ϱ in I [ [ D ] ] ( D 0 , p , ϱ , δ ) and
Γ ; Π ; Φ 1 ⊢ M : A ! P u r e Γ , x : A ; Π ; Φ 1 ′ ⊢ D : L Γ ; Π ; Φ 1 ⋈ Φ 1 ′ ⊢ l e t x = M i n D : L \frac{\Gamma;\Pi;\Phi_1\vdash M:A\ !\ \mathrm{Pure}\qquad\Gamma,x:A;\Pi;\Phi'_1\vdash D:L}{\Gamma;\Pi;\Phi_1\bowtie\Phi'_1\vdash\mathrm{let}\ x=M\ \mathrm{in}\ D:L} Γ ; Π ; Φ 1 ⋈ Φ 1 ′ ⊢ let x = M in D : L Γ ; Π ; Φ 1 ⊢ M : A ! Pure Γ , x : A ; Π ; Φ 1 ′ ⊢ D : L
By premise (iii) and definition of ids, we have (3) that Π ; i d s ( M ) ⊨ ϱ \Pi;\mathrm{ids}(M)\models\varrho Π ; ids ( M ) ⊨ ϱ and (4) that Π ; i d s ( D ) ⊨ ϱ \Pi;\mathrm{ids}(D)\models\varrho Π ; ids ( D ) ⊨ ϱ .
By mutual inductive hypothesis (Theorem B.4 ) on (1) and (3), we have (5) that ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ M ⟧ ϱ : ⟦ A ⟧ \llbracket\Gamma\rrbracket;\llbracket\Pi\rrbracket_{\varrho}\vdash\llbracket M\rrbracket_{\varrho}:\llbracket A\rrbracket [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ M ] ] ϱ : [ [ A ] ] .
We weaken premise (ii) on Γ \Gamma Γ to get (6) that Γ , x : A ; Π ⊢ D 0 : L 0 \Gamma,x:A;\Pi\vdash D_0:L_0 Γ , x : A ; Π ⊢ D 0 : L 0 .
By inductive hypothesis on (2), (4), (6), and premise (iv), we get (7) that ⟦ Γ ⟧ , Γ , x : ⟦ A ⟧ ; ⟦ Π ⟧ ϱ ⊢ I ⟦ D ⟧ ( D 0 , p , ϱ , δ ) : A c o m p \llbracket\Gamma\rrbracket,\Gamma,x:\llbracket A\rrbracket;\llbracket\Pi\rrbracket_{\varrho}\vdash\mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\delta):A_{\mathrm{comp}} [ [ Γ ] ] , Γ , x : [ [ A ] ] ; [ [ Π ] ] ϱ ⊢ I [ [ D ] ] ( D 0 , p , ϱ , δ ) : A comp .
We derive the conclusion as follows, weakening (5) on Γ \Gamma Γ as appropriate:
(TC-Let)
⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ ⟦ M ⟧ ϱ : ⟦ A ⟧ ⟦ Γ ⟧ , Γ ′ , x : ⟦ A ⟧ ; ⟦ Π ⟧ ϱ ⊢ I ⟦ D ⟧ ( D 0 , p , ϱ , δ ) : A c o m p ⟦ Γ ⟧ , Γ ′ ; ⟦ Π ⟧ ϱ ⊢ l e t x = ⟦ M ⟧ ϱ i n I ⟦ D ⟧ ( D 0 , p , ϱ , δ ) : A c o m p \frac{\llbracket\Gamma\rrbracket,\Gamma';\llbracket\Pi\rrbracket_{\varrho}\vdash\llbracket M\rrbracket_{\varrho}:\llbracket A\rrbracket\qquad\llbracket\Gamma\rrbracket,\Gamma',x:\llbracket A\rrbracket;\llbracket\Pi\rrbracket_{\varrho}\vdash\mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\delta):A_{\mathrm{comp}}}{\llbracket\Gamma\rrbracket,\Gamma';\llbracket\Pi\rrbracket_{\varrho}\vdash\mathrm{let}\ x=\llbracket M\rrbracket_{\varrho}\ \mathrm{in}\ \mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\delta):A_{\mathrm{comp}}} [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ let x = [ [ M ] ] ϱ in I [ [ D ] ] ( D 0 , p , ϱ , δ ) : A comp [ [ Γ ] ] , Γ ′ ; [ [ Π ] ] ϱ ⊢ [ [ M ] ] ϱ : [ [ A ] ] [ [ Γ ] ] , Γ ′ , x : [ [ A ] ] ; [ [ Π ] ] ϱ ⊢ I [ [ D ] ] ( D 0 , p , ϱ , δ ) : A comp
Case TB-State: We have
I ⟦ l e t x , x s e t = u s e S t a t e ℓ V i n D ⟧ ( D 0 , p , ϱ , δ ) ≜ l e t x ℓ = r e f ( ⟦ V ⟧ ϱ ) i n l e t x = ! x ℓ i n l e t x s e t = v a l λ y . ( x ℓ : = y ; δ ( p , ϱ ) : = t r u e ) i n I ⟦ D ⟧ ( D 0 , p , ϱ , δ , ℓ ↦ x ℓ ) \begin{aligned}
\mathcal{I}\llbracket\mathrm{let}\ x,x_{\mathrm{set}}=\mathrm{useState}^{\ell}\ V\ \mathrm{in}\ D\rrbracket(D_0,p,\varrho,\delta)
&\triangleq\mathrm{let}\ x_{\ell}=\mathrm{ref}(\llbracket V\rrbracket_{\varrho})\ \mathrm{in}\\
&\quad\mathrm{let}\ x=!x_{\ell}\ \mathrm{in}\\
&\quad\mathrm{let}\ x_{\mathrm{set}}=\mathrm{val}\ \lambda y.(x_{\ell}:=y;\delta(p,\varrho):=\mathrm{true})\ \mathrm{in}\\
&\quad\mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\delta,\ell\mapsto x_{\ell})
\end{aligned} I [ [ let x , x set = useState ℓ V in D ] ] ( D 0 , p , ϱ , δ ) ≜ let x ℓ = ref ( [ [ V ] ] ϱ ) in let x = ! x ℓ in let x set = val λ y . ( x ℓ := y ; δ ( p , ϱ ) := true ) in I [ [ D ] ] ( D 0 , p , ϱ , δ , ℓ ↦ x ℓ )
i d s ( l e t x , x s e t = u s e S t a t e ℓ V i n D ) = i d s ( V ) ∪ i d s ( D ) \mathrm{ids}(\mathrm{let}\ x,x_{\mathrm{set}}=\mathrm{useState}^{\ell}\ V\ \mathrm{in}\ D)=\mathrm{ids}(V)\cup\mathrm{ids}(D) ids ( let x , x set = useState ℓ V in D ) = ids ( V ) ∪ ids ( D )
Γ ; Π ; Φ 1 ⊢ V : A Γ , x : A , x s e t : A → M u t 1 ; Π ; Φ 1 ′ ⊢ D : L ℓ ∉ dom ( L ) Γ ; Π ; Φ 1 ⋈ Φ 1 ′ ⊢ l e t x , x s e t = u s e S t a t e ℓ V i n D : L , ℓ : A \frac{\Gamma;\Pi;\Phi_1\vdash V:A\qquad\Gamma,x:A,x_{\mathrm{set}}:A\xrightarrow{\mathrm{Mut}}1;\Pi;\Phi'_1\vdash D:L\qquad\ell\notin\operatorname{dom}(L)}{\Gamma;\Pi;\Phi_1\bowtie\Phi'_1\vdash\mathrm{let}\ x,x_{\mathrm{set}}=\mathrm{useState}^{\ell}\ V\ \mathrm{in}\ D:L,\ell:A} Γ ; Π ; Φ 1 ⋈ Φ 1 ′ ⊢ let x , x set = useState ℓ V in D : L , ℓ : A Γ ; Π ; Φ 1 ⊢ V : A Γ , x : A , x set : A Mut 1 ; Π ; Φ 1 ′ ⊢ D : L ℓ ∈ / dom ( L )
By premise (iii) and definition of ids, we have (4) that Π ; i d s ( V ) ⊨ ϱ \Pi;\mathrm{ids}(V)\models\varrho Π ; ids ( V ) ⊨ ϱ , (5) that Π ; i d s ( D ) ⊨ ϱ \Pi;\mathrm{ids}(D)\models\varrho Π ; ids ( D ) ⊨ ϱ , and (6) that Π ; ∅ ⊨ ϱ \Pi;\varnothing\models\varrho Π ; ∅ ⊨ ϱ .
By mutual inductive hypothesis (Theorem B.3 ) on (1) and (4), we have (7) that $\llbracket\Gamma\rrbracket;\llbracket\Pi\rrbracket_{\varrho}\vdash\llbracket V\rrbracket_{\varrho}:\llbracket A\rrbracket.
Let δ ′ = δ \delta' = \delta δ ′ = δ , ℓ ↦ x ℓ \ell\mapsto x_{\ell} ℓ ↦ x ℓ and Γ ′ ′ = Γ ′ , x ℓ : Ref ⟦ A ⟧ \Gamma'' = \Gamma', x_{\ell} : \operatorname{Ref} \llbracket A \rrbracket Γ ′′ = Γ ′ , x ℓ : Ref [ [ A ] ] . We want to show (8) that Γ ′ ′ ; Π ⊨ p δ ′ : ( L 0 ∖ L ) \Gamma'' ; \Pi\models_p \delta' : (L_0 \setminus L) Γ ′′ ; Π ⊨ p δ ′ : ( L 0 ∖ L ) :
Premise (ii) gives us that L , ℓ : A ⊆ L 0 L, \ell: A \subseteq L_0 L , ℓ : A ⊆ L 0 . (3) says that ℓ ∉ dom ( L ) \ell\notin\operatorname{dom}(L) ℓ ∈ / dom ( L ) .
Therefore, we must have ℓ : A ∈ L 0 ∖ L \ell: A \in L_0 \setminus L ℓ : A ∈ L 0 ∖ L , and clearly ℓ : A ∉ L 0 ∖ ( L , ℓ : A ) \ell: A \notin L_0 \setminus(L, \ell: A) ℓ : A ∈ / L 0 ∖ ( L , ℓ : A ) .
Then by premise (iv) and definition, since ℓ ↦ x ℓ ∈ δ ′ \ell\mapsto x_{\ell} \in\delta' ℓ ↦ x ℓ ∈ δ ′ , it suffices to show that x ℓ : Ref ⟦ A ⟧ ∈ Γ ′ ′ x_{\ell} : \operatorname{Ref} \llbracket A \rrbracket\in\Gamma'' x ℓ : Ref [ [ A ] ] ∈ Γ ′′ . This is given by definition of Γ ′ ′ \Gamma'' Γ ′′ .
We weaken premise (ii) on Γ \Gamma Γ to get (9) that Γ , x : A , x s e t : A → Mut 1 ; Π ⊢ D 0 : L 0 \Gamma, x : A, x_{\mathrm{set}} : A \mathbin{\xrightarrow{\operatorname{Mut}}} 1 ; \Pi\vdash D_0 : L_0 Γ , x : A , x set : A Mut 1 ; Π ⊢ D 0 : L 0 .
Now by inductive hypothesis on (2), (5), (8), and (9), we have (10) that ⟦ Γ , x : A , x s e t : A → Mut 1 ⟧ , Γ ′ ′ ; ⟦ Π ⟧ ϱ ⊢ I ⟦ D ⟧ ( D 0 , p , ϱ , δ ′ ) : A c o m p \llbracket\Gamma, x : A, x_{\mathrm{set}} : A \mathbin{\xrightarrow{\operatorname{Mut}}} 1 \rrbracket, \Gamma'' ; \llbracket\Pi\rrbracket_{\varrho} \vdash I\llbracket D \rrbracket(D_0,p,\varrho,\delta') : A_{\mathrm{comp}} [ [ Γ , x : A , x set : A Mut 1 ] ] , Γ ′′ ; [ [ Π ] ] ϱ ⊢ I [ [ D ] ] ( D 0 , p , ϱ , δ ′ ) : A comp .
By definition, (10) is equivalent to (11) that ⟦ Γ ⟧ , Γ ′ , x : ⟦ A ⟧ , x s e t : ⟦ A ⟧ → 1 , x ℓ : Ref ⟦ A ⟧ ; ⟦ Π ⟧ ϱ ⊢ I ⟦ D ⟧ ( D 0 , p , ϱ , δ ′ ) : A c o m p \llbracket\Gamma\rrbracket, \Gamma', x : \llbracket A \rrbracket, x_{\mathrm{set}} : \llbracket A \rrbracket\to1, x_{\ell} : \operatorname{Ref} \llbracket A \rrbracket; \llbracket\Pi\rrbracket_{\varrho} \vdash I\llbracket D \rrbracket(D_0,p,\varrho,\delta') : A_{\mathrm{comp}} [ [ Γ ] ] , Γ ′ , x : [ [ A ] ] , x set : [ [ A ] ] → 1 , x ℓ : Ref [ [ A ] ] ; [ [ Π ] ] ϱ ⊢ I [ [ D ] ] ( D 0 , p , ϱ , δ ′ ) : A comp .
Finally, we apply Lemma B.1 (flag typing) to (6) and premise (iv) to get (12) that Γ ′ ; ⟦ Π ⟧ ϱ ⊢ δ ( p , ϱ ) : Ref Bool \Gamma' ; \llbracket\Pi\rrbracket_{\varrho} \vdash\delta(p,\varrho) : \operatorname{Ref}\operatorname{Bool} Γ ′ ; [ [ Π ] ] ϱ ⊢ δ ( p , ϱ ) : Ref Bool .
\begin{aligned}
&\frac{\Gamma_{13};\llbracket\Pi\rrbracket_{\varrho}\vdash x_{\ell}:\operatorname{Ref}\llbracket A\rrbracket\ \mathrm{TV\text{-}VAR}
\qquad
\Gamma_{13};\llbracket\Pi\rrbracket_{\varrho}\vdash y:\llbracket A\rrbracket\ \mathrm{TV\text{-}VAR}}
{\Gamma_{13};\llbracket\Pi\rrbracket_{\varrho}\vdash x_{\ell}:=y:1\ \mathrm{TC\text{-}SET}
\quad(13)}\\
&\frac{\Gamma_{14};\llbracket\Pi\rrbracket_{\varrho}\vdash\delta(p,\varrho):\operatorname{Ref}\operatorname{Bool}\quad(12)
\qquad
\Gamma_{14};\llbracket\Pi\rrbracket_{\varrho}\vdash\mathrm{true}:\operatorname{Bool}\ \mathrm{TV\text{-}TRUE}}
{\Gamma_{14};\llbracket\Pi\rrbracket_{\varrho}\vdash\delta(p,\varrho):=\mathrm{true}:1\ \mathrm{TC\text{-}SET}
\quad(14)}\\
&\frac{[(13),\ \Gamma_{13}=\Gamma_{15},y:\llbracket A\rrbracket]\qquad[(14),\ \Gamma_{14}=\Gamma_{15},y:\llbracket A\rrbracket]}
{\Gamma_{15},y:\llbracket A\rrbracket;\llbracket\Pi\rrbracket_{\varrho}\vdash x_{\ell}:=y;\delta(p,\varrho):=\mathrm{true}:1\ \mathrm{TC\text{-}LET}}\\
&\frac{\Gamma_{15};\llbracket\Pi\rrbracket_{\varrho}\vdash\lambda y.(x_{\ell}:=y;\delta(p,\varrho):=\mathrm{true}):\llbracket A\rrbracket\to1\ \mathrm{TV\text{-}LAM}}
{\Gamma_{15};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{val}\lambda y.(x_{\ell}:=y;\delta(p,\varrho):=\mathrm{true}):\llbracket A\rrbracket\to1\ \mathrm{TC\text{-}VAL}
\quad(15)\\
&\frac{[(15),\ \Gamma_{15}=\Gamma_{16}]\qquad
\Gamma_{16},x_{\mathrm{set}}:\llbracket A\rrbracket\to1;\llbracket\Pi\rrbracket_{\varrho}\vdash I\llbracket D\rrbracket(D_0,p,\varrho,\delta') : A_{\mathrm{comp}}\quad(11)}
{\Gamma_{16};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{let}x_{\mathrm{set}}=\cdots\operatorname{in}I\llbracket D\rrbracket(D_0,p,\varrho,\delta'):A_{\mathrm{comp}}\ \mathrm{TC\text{-}LET}
\quad(16)\\
&\frac{\Gamma_{17};\llbracket\Pi\rrbracket_{\varrho}\vdash x_{\ell}:\operatorname{Ref}\llbracket A\rrbracket\ \mathrm{TV\text{-}VAR}}
{\Gamma_{17};\llbracket\Pi\rrbracket_{\varrho}\vdash!x_{\ell}:\llbracket A\rrbracket\ \mathrm{TC\text{-}GET}}\\
&\frac{[(16),\ \Gamma_{16}=\Gamma_{17},x:\llbracket A\rrbracket]}
{\Gamma_{17};\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{let}x=!x_{\ell}\operatorname{in}\cdots:A_{\mathrm{comp}}\ \mathrm{TC\text{-}LET}
\quad(17)\\
&\frac{\llbracket\Gamma\rrbracket,\Delta;\llbracket\Pi\rrbracket_{\varrho}\vdash\llbracket V\rrbracket_{\varrho}:\llbracket A\rrbracket\quad(7)}
{\llbracket\Gamma\rrbracket,\Delta;\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{ref}(\llbracket V\rrbracket_{\varrho}):\operatorname{Ref}\llbracket A\rrbracket\ \mathrm{TC\text{-}REF}}
\quad
\frac{[(17),\ \Gamma_{17}=\llbracket\Gamma\rrbracket,\Delta,x_{\ell}:\operatorname{Ref}\llbracket A\rrbracket]}
{\llbracket\Gamma\rrbracket,\Delta;\llbracket\Pi\rrbracket_{\varrho}\vdash\operatorname{let}x_{\ell}=\operatorname{ref}(\llbracket V\rrbracket_{\varrho})\operatorname{in}\cdots:A_{\mathrm{comp}}\ \mathrm{TC\text{-}LET}
\end{aligned}}}}}
Heap/Store Preservation. We need one final lemma regarding the appending of well-formed stores in order to prove type preservation for heaps:
Lemma B.6 (Store appending). If (i) Γ ; Σ 0 ⊢ σ : Σ , \Gamma\mathbin{;} \Sigma_{0} \vdash\sigma: \Sigma, Γ ; Σ 0 ⊢ σ : Σ , (ii) Γ ; Σ 0 ⊢ σ ′ : Σ ′ \Gamma\mathbin{;} \Sigma_{0} \vdash\sigma^{\prime} : \Sigma^{\prime} Γ ; Σ 0 ⊢ σ ′ : Σ ′ , and (iii) dom ( σ ) ∩ dom ( σ ′ ) = ∅ , \operatorname{dom}(\sigma) \cap\operatorname{dom}(\sigma^{\prime}) = \emptyset, dom ( σ ) ∩ dom ( σ ′ ) = ∅ , then Γ ; Σ 0 ; Φ ⊢ σ ⊎ σ ′ : Σ ⊎ Σ ′ \Gamma\mathbin{;} \Sigma_{0} \mathbin{;} \Phi\vdash\sigma\uplus\sigma^{\prime} : \Sigma\uplus\Sigma^{\prime} Γ ; Σ 0 ; Φ ⊢ σ ⊎ σ ′ : Σ ⊎ Σ ′ .
Proof. By induction on the derivation of typing premise (ii). At each step, well-formedness is preserved by premise (iii). □
Lemma B.7 (Type preservation, state stores). If
(i) Γ ; Π ; Φ ⊢ σ : L , \Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash\sigma: \mathcal{L}, Γ ; Π ; Φ ⊢ σ : L , (ii) Π ; ids ( σ ) ⊢ ϱ \Pi\mathbin{;} \operatorname{ids}(\sigma) \vdash\varrho Π ; ids ( σ ) ⊢ ϱ , and (iii) L ⊆ Π [ p ] \mathcal{L} \subseteq\Pi[p] L ⊆ Π [ p ] (for some p p p ),
then ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ σ ⟧ ϱ : ⟦ L ⟧ \llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket\sigma\rrbracket_{\varrho} : \llbracket\mathcal{L}\rrbracket [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ σ ] ] ϱ : [ [ L ] ] .
Proof. By induction on the derivation of the typing premise (i).
Case TS-Nil: We have
Succ ( Φ ) Γ ; Π ; Φ ⊢ ∅ : ∅ TS-Nil \frac{\operatorname{Succ}(\Phi)}
{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash\emptyset: \emptyset}
\text{TS-Nil} Γ ; Π ; Φ ⊢ ∅ : ∅ Succ ( Φ ) TS-Nil By definition, ⟦ L ⟧ ϱ = ∅ \llbracket\mathcal{L}\rrbracket_{\varrho} = \emptyset [ [ L ] ] ϱ = ∅ and ⟦ σ ⟧ ϱ = ∅ \llbracket\sigma\rrbracket_{\varrho} = \emptyset [ [ σ ] ] ϱ = ∅ .
We immediately rederive the conclusion via the corresponding target-language rule:
⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ∅ : ∅ TS-Nil \frac{}
{\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\emptyset: \emptyset}
\text{TS-Nil} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ ∅ : ∅ TS-Nil Case TS-Cons: We have
⟦ σ , ℓ ↦ V ⟧ ϱ = ⟦ σ ⟧ ϱ , ϱ ( p , ℓ ) ↦ ⟦ V ⟧ ϱ ⟦ L , ℓ : A ⟧ ϱ = ⟦ L ⟧ ϱ , ϱ ( p , ℓ ) : ⟦ A ⟧ \llbracket\sigma, \ell\mapsto V\rrbracket_{\varrho}
= \llbracket\sigma\rrbracket_{\varrho}, \varrho(p,\ell) \mapsto\llbracket V\rrbracket_{\varrho}
\qquad
\llbracket\mathcal{L}, \ell: A\rrbracket_{\varrho}
= \llbracket\mathcal{L}\rrbracket_{\varrho}, \varrho(p,\ell) : \llbracket A\rrbracket [ [ σ , ℓ ↦ V ] ] ϱ = [ [ σ ] ] ϱ , ϱ ( p , ℓ ) ↦ [ [ V ] ] ϱ [ [ L , ℓ : A ] ] ϱ = [ [ L ] ] ϱ , ϱ ( p , ℓ ) : [ [ A ] ] Γ ; Π ; Φ 1 ⊢ V : A ( 1 ) Γ ; Π ; Φ 2 ⊢ σ : L ( 2 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ σ , ℓ ↦ V : L , ℓ : A TS-Cons \frac{
\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \vdash V : A}{(1)}
\qquad
\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{2} \vdash\sigma: \mathcal{L}}{(2)}
}{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \mathbin{\mathbin{\bowtie}} \Phi_{2} \vdash\sigma, \ell\mapsto V : \mathcal{L}, \ell: A
}
\text{TS-Cons} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ σ , ℓ ↦ V : L , ℓ : A ( 1 ) Γ ; Π ; Φ 1 ⊢ V : A ( 2 ) Γ ; Π ; Φ 2 ⊢ σ : L TS-Cons By premise (ii) and definition of ids, we have (3) that Π ; ids ( V ) ⊢ ϱ \Pi\mathbin{;} \operatorname{ids}(V) \vdash\varrho Π ; ids ( V ) ⊢ ϱ and (4) that Π ; ids ( σ ) ⊢ ϱ \Pi\mathbin{;} \operatorname{ids}(\sigma) \vdash\varrho Π ; ids ( σ ) ⊢ ϱ .
By Lemma B.3 (value type preservation) on (1) and (3), we get (5) that ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ V ⟧ ϱ : ⟦ A ⟧ \llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket V\rrbracket_{\varrho} : \llbracket A\rrbracket [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ V ] ] ϱ : [ [ A ] ] .
By inductive hypothesis on (2) and (4), we get (6) that ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ σ ⟧ ϱ : ⟦ L ⟧ ϱ \llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket\sigma\rrbracket_{\varrho} : \llbracket\mathcal{L}\rrbracket_{\varrho} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ σ ] ] ϱ : [ [ L ] ] ϱ .
By premises (ii) and (iii), we get that ϱ ( p , ℓ ) \varrho(p,\ell) ϱ ( p , ℓ ) is well-defined. By injectivity of ϱ \varrho ϱ and definition of translation, we further get that ϱ ( p , ℓ ) ∉ dom ⟦ σ ⟧ ϱ \varrho(p,\ell) \notin\operatorname{dom}\llbracket\sigma\rrbracket_{\varrho} ϱ ( p , ℓ ) ∈ / dom [ [ σ ] ] ϱ and ϱ ( p , ℓ ) ∉ dom ⟦ L ⟧ ϱ \varrho(p,\ell) \notin\operatorname{dom}\llbracket\mathcal{L}\rrbracket_{\varrho} ϱ ( p , ℓ ) ∈ / dom [ [ L ] ] ϱ , i.e. ⟦ σ ⟧ ϱ , ϱ ( p , ℓ ) ↦ ⟦ V ⟧ ϱ \llbracket\sigma\rrbracket_{\varrho}, \varrho(p,\ell) \mapsto\llbracket V\rrbracket_{\varrho} [ [ σ ] ] ϱ , ϱ ( p , ℓ ) ↦ [ [ V ] ] ϱ and ⟦ L ⟧ ϱ , ϱ ( p , ℓ ) : ⟦ A ⟧ \llbracket\mathcal{L}\rrbracket_{\varrho}, \varrho(p,\ell) : \llbracket A\rrbracket [ [ L ] ] ϱ , ϱ ( p , ℓ ) : [ [ A ] ] are well-formed.
We derive the conclusion as follows:
⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ V ⟧ ϱ : ⟦ A ⟧ ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ σ ⟧ ϱ : ⟦ L ⟧ ϱ ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ⟦ σ ⟧ ϱ , ϱ ( p , ℓ ) ↦ ⟦ V ⟧ ϱ : ⟦ L ⟧ ϱ , ( ϱ ( p , ℓ ) : ⟦ A ⟧ ) TS-Cons \frac{
\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket V\rrbracket_{\varrho} : \llbracket A\rrbracket
\qquad
\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket\sigma\rrbracket_{\varrho} : \llbracket\mathcal{L}\rrbracket_{\varrho}
}{
\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\llbracket\sigma\rrbracket_{\varrho}, \varrho(p,\ell) \mapsto\llbracket V\rrbracket_{\varrho} : \llbracket\mathcal{L}\rrbracket_{\varrho}, \left(\varrho(p,\ell) : \llbracket A\rrbracket\right)
}
\text{TS-Cons} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ σ ] ] ϱ , ϱ ( p , ℓ ) ↦ [ [ V ] ] ϱ : [ [ L ] ] ϱ , ( ϱ ( p , ℓ ) : [ [ A ] ] ) [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ V ] ] ϱ : [ [ A ] ] [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ [ [ σ ] ] ϱ : [ [ L ] ] ϱ TS-Cons
Lemma B.8 (Type preservation, heaps, intermediate). If
(i) Γ ; Π 0 ; Φ ⊢ H : Π , \Gamma\mathbin{;} \Pi_{0} \mathbin{;} \Phi\vdash\mathcal{H} : \Pi, Γ ; Π 0 ; Φ ⊢ H : Π , (ii) Π 0 ; ids ( H ) ⊢ ϱ \Pi_{0} \mathbin{;} \operatorname{ids}(\mathcal{H}) \vdash\varrho Π 0 ; ids ( H ) ⊢ ϱ , and (iii) Π ⊆ Π 0 , \Pi\subseteq\Pi_{0}, Π ⊆ Π 0 ,
then ⟦ Γ ⟧ \llbracket\Gamma\rrbracket [ [ Γ ] ] ; ⟦ Π 0 ⟧ ϱ ⊨ ⟦ H ⟧ ϱ : ⟦ Π ⟧ ϱ \llbracket\Pi_0 \rrbracket_{\varrho} \vDash\llbracket H \rrbracket_{\varrho} : \llbracket\Pi\rrbracket_{\varrho} [ [ Π 0 ] ] ϱ ⊨ [ [ H ] ] ϱ : [ [ Π ] ] ϱ .
Proof. By induction on the derivation of the typing premise ( i ) (i) ( i ) .
Case TH-Nil: We have
Succ ( Φ ) Γ ; Π 0 ; Φ ⊢ ∅ : ∅ TH-Nil \frac{\operatorname{Succ}(\Phi)}
{\Gamma\mathbin{;} \Pi_0 \mathbin{;} \Phi\vdash\varnothing: \varnothing}
\quad\text{TH-Nil} Γ ; Π 0 ; Φ ⊢ ∅ : ∅ Succ ( Φ ) TH-Nil
By definition, ⟦ Π ⟧ ϱ = ∅ \llbracket\Pi\rrbracket_{\varrho} = \varnothing [ [ Π ] ] ϱ = ∅ and ⟦ H ⟧ ϱ = ∅ \llbracket H \rrbracket_{\varrho} = \varnothing [ [ H ] ] ϱ = ∅ .
We immediately rederive the conclusion via the corresponding target-language rule:
⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊢ ∅ : ∅ TH-Nil \frac{}
{\llbracket\Gamma\rrbracket\mathbin{;} \llbracket\Pi\rrbracket_{\varrho} \vdash\varnothing: \varnothing}
\quad\text{TH-Nil} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊢ ∅ : ∅ TH-Nil
Case TH-Cons: We have
⟦ H , p ↦ π ⟧ ϱ = ⟦ H ⟧ ϱ ∪ ⟦ π . s t ⟧ ϱ , ϱ ( p ) ↦ ⟦ π . r e r e n d e r ⟧ \llbracket H, p \mapsto\pi\rrbracket_{\varrho}
= \llbracket H \rrbracket_{\varrho} \cup\llbracket\pi.\mathrm{st} \rrbracket_{\varrho},
\varrho(p) \mapsto\llbracket\pi.\mathrm{rerender} \rrbracket [ [ H , p ↦ π ] ] ϱ = [ [ H ] ] ϱ ∪ [ [ π . st ] ] ϱ , ϱ ( p ) ↦ [ [ π . rerender ] ]
⟦ Π , p : L ⟧ ϱ = ⟦ Π ⟧ ϱ ∪ ⟦ L ⟧ ϱ , ϱ ( p ) : B o o l \llbracket\Pi, p : \mathcal{L} \rrbracket_{\varrho}
= \llbracket\Pi\rrbracket_{\varrho} \cup\llbracket\mathcal{L} \rrbracket_{\varrho},
\varrho(p) : \mathrm{Bool} [ [ Π , p : L ] ] ϱ = [ [ Π ] ] ϱ ∪ [ [ L ] ] ϱ , ϱ ( p ) : Bool
Γ ; Π 0 ; Φ 1 ⊢ π . s t : L Γ ; Π 0 ; Φ 2 ⊨ H : Π Γ ; Π 0 ; Φ 1 ⋈ Φ 2 ⊨ H , p ↦ π : Π , p : L TH-Cons \frac{
\begin{array}{c}
\Gamma\mathbin{;} \Pi_0 \mathbin{;} \Phi_1 \vdash\pi.\mathrm{st} : \mathcal{L}
\qquad
\Gamma\mathbin{;} \Pi_0 \mathbin{;} \Phi_2 \vDash H : \Pi
\\
\Gamma\mathbin{;} \Pi_0 \mathbin{;} \Phi_1 \bowtie\Phi_2 \vDash H, p \mapsto\pi: \Pi, p : \mathcal{L}
\end{array}}
{\text{TH-Cons}} TH-Cons Γ ; Π 0 ; Φ 1 ⊢ π . st : L Γ ; Π 0 ; Φ 2 ⊨ H : Π Γ ; Π 0 ; Φ 1 ⋈ Φ 2 ⊨ H , p ↦ π : Π , p : L
By premise ( i i ) (ii) ( ii ) and definition of ids, we have (3) that Π 0 ; ids ( π . s t ) ⊨ ϱ \Pi_0 ; \operatorname{ids}(\pi.\mathrm{st}) \vDash\varrho Π 0 ; ids ( π . st ) ⊨ ϱ and (4) that Π 0 ; ids ( H ) ⊨ ϱ \Pi_0 ; \operatorname{ids}(H) \vDash\varrho Π 0 ; ids ( H ) ⊨ ϱ .
By Lemma B.7 (state store type preservation) on (1) and (3), noting that L = Π [ p ] = Π 0 [ p ] \mathcal{L} = \Pi[p] = \Pi_0[p] L = Π [ p ] = Π 0 [ p ] by premise ( i i i ) (iii) ( iii ) , we have (5) ⟦ Γ ⟧ ; ⟦ Π 0 ⟧ ϱ ⊨ ⟦ π . s t ⟧ ϱ : ⟦ L ⟧ ϱ \llbracket\Gamma\rrbracket; \llbracket\Pi_0 \rrbracket_{\varrho} \vDash\llbracket\pi.\mathrm{st} \rrbracket_{\varrho} : \llbracket\mathcal{L} \rrbracket_{\varrho} [ [ Γ ] ] ; [ [ Π 0 ] ] ϱ ⊨ [ [ π . st ] ] ϱ : [ [ L ] ] ϱ .
By inductive hypothesis on (2) and (4), noting that transitivity of ⊑ \sqsubseteq ⊑ satisfies the third premise, we get (6) that ⟦ Γ ⟧ ; ⟦ Π 0 ⟧ ϱ ⊨ ⟦ H ⟧ ϱ : ⟦ Π ⟧ ϱ \llbracket\Gamma\rrbracket; \llbracket\Pi_0 \rrbracket_{\varrho} \vDash\llbracket H \rrbracket_{\varrho} : \llbracket\Pi\rrbracket_{\varrho} [ [ Γ ] ] ; [ [ Π 0 ] ] ϱ ⊨ [ [ H ] ] ϱ : [ [ Π ] ] ϱ .
By injectivity of ϱ \varrho ϱ and translation definitions, we get (7) dom ( ⟦ H ⟧ ϱ ) ∩ dom ( ⟦ π . s t ⟧ ϱ ) = ∅ \operatorname{dom}(\llbracket H \rrbracket_{\varrho}) \cap\operatorname{dom}(\llbracket\pi.\mathrm{st} \rrbracket_{\varrho}) = \varnothing dom ( [ [ H ] ] ϱ ) ∩ dom ( [ [ π . st ] ] ϱ ) = ∅ .
By Lemma B.6 (store appending) on (5)–(7), we get (8) that
⟦ Γ ⟧ ; ⟦ Π 0 ⟧ ϱ ⊨ ⟦ H ⟧ ϱ ⊎ ⟦ π . s t ⟧ ϱ : ⟦ Π ⟧ ϱ ⊎ ⟦ L ⟧ ϱ . \llbracket\Gamma\rrbracket; \llbracket\Pi_0 \rrbracket_{\varrho}
\vDash\llbracket H \rrbracket_{\varrho} \uplus\llbracket\pi.\mathrm{st} \rrbracket_{\varrho}
:
\llbracket\Pi\rrbracket_{\varrho} \uplus\llbracket\mathcal{L} \rrbracket_{\varrho}. [ [ Γ ] ] ; [ [ Π 0 ] ] ϱ ⊨ [ [ H ] ] ϱ ⊎ [ [ π . st ] ] ϱ : [ [ Π ] ] ϱ ⊎ [ [ L ] ] ϱ .
By definition, either ⟦ π . r e r e n d e r ⟧ = t r u e \llbracket\pi.\mathrm{rerender} \rrbracket= \mathrm{true} [ [ π . rerender ] ] = true or ⟦ π . r e r e n d e r ⟧ = f a l s e \llbracket\pi.\mathrm{rerender} \rrbracket= \mathrm{false} [ [ π . rerender ] ] = false . In either case, (9)
⟦ Γ ⟧ ; ⟦ Π 0 ⟧ ϱ ⊢ ⟦ r r ⟧ : B o o l . \llbracket\Gamma\rrbracket; \llbracket\Pi_0 \rrbracket_{\varrho}
\vdash\llbracket rr \rrbracket: \mathrm{Bool}. [ [ Γ ] ] ; [ [ Π 0 ] ] ϱ ⊢ [ [ r r ] ] : Bool .
By premise ( i i ) (ii) ( ii ) , we have ϱ ( p ) \varrho(p) ϱ ( p ) is well-defined.
We derive the conclusion as follows, again getting well-formedness by injectivity of ϱ \varrho ϱ , and abbreviating r r ≔ π . r e r e n d e r rr \coloneqq\pi.\mathrm{rerender} r r : = π . rerender :
⟦ Γ ⟧ ; ⟦ Π 0 ⟧ ϱ ⊢ ⟦ r r ⟧ : B o o l ⟦ Γ ⟧ ; ⟦ Π 0 ⟧ ϱ ⊨ ⟦ H ⟧ ϱ ⊎ ⟦ π . s t ⟧ ϱ : ⟦ Π ⟧ ϱ ⊎ ⟦ L ⟧ ϱ ⟦ Γ ⟧ ; ⟦ Π 0 ⟧ ϱ ⊨ ⟦ H ⟧ ϱ ⊎ ⟦ π . s t ⟧ ϱ , ϱ ( p ) ↦ ⟦ r r ⟧ : ⟦ Π ⟧ ϱ ⊎ ⟦ L ⟧ ϱ , ( ϱ ( p ) : B o o l ) TS-Cons \frac{
\begin{array}{c}
\llbracket\Gamma\rrbracket; \llbracket\Pi_0 \rrbracket_{\varrho} \vdash\llbracket rr \rrbracket: \mathrm{Bool}
\\
\llbracket\Gamma\rrbracket; \llbracket\Pi_0 \rrbracket_{\varrho}
\vDash\llbracket H \rrbracket_{\varrho} \uplus\llbracket\pi.\mathrm{st} \rrbracket_{\varrho}
:
\llbracket\Pi\rrbracket_{\varrho} \uplus\llbracket\mathcal{L} \rrbracket_{\varrho}
\end{array}}
{\llbracket\Gamma\rrbracket; \llbracket\Pi_0 \rrbracket_{\varrho}
\vDash\llbracket H \rrbracket_{\varrho} \uplus\llbracket\pi.\mathrm{st} \rrbracket_{\varrho},
\varrho(p) \mapsto\llbracket rr \rrbracket
:
\llbracket\Pi\rrbracket_{\varrho} \uplus\llbracket\mathcal{L} \rrbracket_{\varrho},
(\varrho(p) : \mathrm{Bool})}
\quad\text{TS-Cons} [ [ Γ ] ] ; [ [ Π 0 ] ] ϱ ⊨ [ [ H ] ] ϱ ⊎ [ [ π . st ] ] ϱ , ϱ ( p ) ↦ [ [ r r ] ] : [ [ Π ] ] ϱ ⊎ [ [ L ] ] ϱ , ( ϱ ( p ) : Bool ) [ [ Γ ] ] ; [ [ Π 0 ] ] ϱ ⊢ [ [ r r ] ] : Bool [ [ Γ ] ] ; [ [ Π 0 ] ] ϱ ⊨ [ [ H ] ] ϱ ⊎ [ [ π . st ] ] ϱ : [ [ Π ] ] ϱ ⊎ [ [ L ] ] ϱ TS-Cons
□ \square □
Theorem B.9 (Type preservation, heaps). If
Γ ; Π ; Φ ⊨ H \Gamma; \Pi; \Phi\vDash H Γ ; Π ; Φ ⊨ H and
Π ; ids ( H ) ⊨ ϱ \Pi; \operatorname{ids}(H) \vDash\varrho Π ; ids ( H ) ⊨ ϱ ,
then ⟦ Γ ⟧ ; ⟦ Π ⟧ ϱ ⊨ ⟦ H ⟧ ϱ \llbracket\Gamma\rrbracket; \llbracket\Pi\rrbracket_{\varrho} \vDash\llbracket H \rrbracket_{\varrho} [ [ Γ ] ] ; [ [ Π ] ] ϱ ⊨ [ [ H ] ] ϱ .
Proof. Corollary of Lemma B.8, choosing Π 0 = Π \Pi_0 = \Pi Π 0 = Π and noting that Π ⊑ Π \Pi\sqsubseteq\Pi Π ⊑ Π .
Simulation
We begin with an assortment of “equivalence lemmas”, which help us assert the equivalence of terms under various translation-related operations.
Substitution
Substitution. We prove that substitution commutes with all five term translation functions. The lemma statements and proofs for values and computations are fairly standard. Those for bodies additionally require that the target variable is not in the range of δ \delta δ : we treat those variables separately via a series of δ \delta δ -elimination lemmas, to be presented later.
By the Barendregt variable convention, we are free to assume in our lemmas that the target variable is not in the bound variables of the term: we guarantee this by appropriately α \alpha α -converting any terms which violate this assumption.
We additionally remark that, in the translation I ⟦ D ⟧ ( D 0 , p , ϱ , δ ) \mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\delta) I [ [ D ] ] ( D 0 , p , ϱ , δ ) , the body D 0 D_0 D 0 is in scope of all bindings of D D D . We thus stipulate by convention that bv ( D ) ∩ fv ( D 0 ) = ∅ \operatorname{bv}(D) \cap\operatorname{fv}(D_0) = \varnothing bv ( D ) ∩ fv ( D 0 ) = ∅ ; this can likewise be achieved by α \alpha α -conversion on D D D . (This stipulation excludes those variables introduced by δ \delta δ in the translation: these δ \delta δ -variables are the only way to “pass information” between the translation phases.)
Lemma B.10 (Substitution, values). If
⟦ V ⟧ ϱ \llbracket V\rrbracket_\varrho [ [ V ] ] ϱ is well-defined and
⟦ W ⟧ ϱ \llbracket W\rrbracket_\varrho [ [ W ] ] ϱ is well-defined,
then ⟦ W [ V / x ] ⟧ ϱ = ⟦ W ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket W[V/x]\rrbracket_\varrho= \llbracket W\rrbracket_\varrho[\llbracket V\rrbracket_\varrho/x] [ [ W [ V / x ] ] ] ϱ = [ [ W ] ] ϱ [ [ [ V ] ] ϱ / x ] .
Proof. By mutual induction on the structure of W W W with Lemmas Lemmas B.11 , B.12 , and B.13 . (Premise (i) allows us to safely expand ⟦ W ⟧ ϱ \llbracket W\rrbracket_\varrho [ [ W ] ] ϱ .)
Case W = x ′ W = x' W = x ′ : We subcase on whether x ′ = x x' = x x ′ = x .
⟦ x ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] = x [ ⟦ V ⟧ ϱ / x ] def. of translation = ⟦ V ⟧ ϱ def. of substitution = ⟦ x [ V / x ] ⟧ ϱ def. of substitution \begin{aligned}
\llbracket x\rrbracket_\varrho[\llbracket V\rrbracket_\varrho/x] &= x[\llbracket V\rrbracket_\varrho/x] && \text{def. of translation}\\
&= \llbracket V\rrbracket_\varrho&& \text{def. of substitution}\\
&= \llbracket x[V/x]\rrbracket_\varrho&& \text{def. of substitution}
\end{aligned} [ [ x ] ] ϱ [ [ [ V ] ] ϱ / x ] = x [ [ [ V ] ] ϱ / x ] = [ [ V ] ] ϱ = [ [ x [ V / x ] ] ] ϱ def. of translation def. of substitution def. of substitution
⟦ x ′ ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] = x ′ [ ⟦ V ⟧ ϱ / x ] def. of translation = x ′ def. of substitution = ⟦ x ′ ⟧ ϱ def. of translation = ⟦ x ′ [ V / x ] ⟧ ϱ def. of substitution \begin{aligned}
\llbracket x'\rrbracket_\varrho[\llbracket V\rrbracket_\varrho/x] &= x'[\llbracket V\rrbracket_\varrho/x] && \text{def. of translation}\\
&= x' && \text{def. of substitution}\\
&= \llbracket x'\rrbracket_\varrho&& \text{def. of translation}\\
&= \llbracket x'[V/x]\rrbracket_\varrho&& \text{def. of substitution}
\end{aligned} [ [ x ′ ] ] ϱ [ [ [ V ] ] ϱ / x ] = x ′ [ [ [ V ] ] ϱ / x ] = x ′ = [ [ x ′ ] ] ϱ = [ [ x ′ [ V / x ] ] ] ϱ def. of translation def. of substitution def. of translation def. of substitution
Cases W = ( ) , W = t r u e , W = f a l s e , W = s , W = [ ] , W = (), W = \mathrm{true}, W = \mathrm{false}, W = s, W = [], W = ( ) , W = true , W = false , W = s , W = [ ] , and W = set ρ ℓ W = \operatorname{set}^{\ell}_{\rho} W = set ρ ℓ are all shown analogously to the latter subcase above.
Case W = tagInst i d ( W 1 , W 2 ) W = \operatorname{tagInst}_{id}(W_1,W_2) W = tagInst i d ( W 1 , W 2 ) :
By premise (i), we have (1) that ⟦ W 1 ⟧ ϱ \llbracket W_1\rrbracket_\varrho [ [ W 1 ] ] ϱ is well-defined and (2) that ⟦ W 2 ⟧ ϱ \llbracket W_2\rrbracket_\varrho [ [ W 2 ] ] ϱ is well-defined.
By inductive hypothesis on each of (1) and (2) alongside premise (ii), we get (3) that ⟦ W 1 [ V / x ] ⟧ ϱ = ⟦ W 1 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket W_1[V/x]\rrbracket_\varrho= \llbracket W_1\rrbracket_\varrho[\llbracket V\rrbracket_\varrho/x] [ [ W 1 [ V / x ] ] ] ϱ = [ [ W 1 ] ] ϱ [ [ [ V ] ] ϱ / x ] and (4) that ⟦ W 2 [ V / x ] ⟧ ϱ = ⟦ W 2 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket W_2[V/x]\rrbracket_\varrho= \llbracket W_2\rrbracket_\varrho[\llbracket V\rrbracket_\varrho/x] [ [ W 2 [ V / x ] ] ] ϱ = [ [ W 2 ] ] ϱ [ [ [ V ] ] ϱ / x ] , respectively.
⟦ tagInst i d ( W 1 , W 2 ) ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] = tagInst i d ( ⟦ W 1 ⟧ ϱ , ⟦ W 2 ⟧ ϱ ) [ ⟦ V ⟧ ϱ / x ] def. of translation = tagInst ϱ ( i d ) ( ⟦ W 1 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] , ⟦ W 2 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] ) def. of substitution = tagInst ϱ ( i d ) ( ⟦ W 1 [ V / x ] ⟧ ϱ , ⟦ W 2 [ V / x ] ⟧ ϱ ) by (3) and (4) = ⟦ tagInst i d ( W 1 [ V / x ] , W 2 [ V / x ] ) ⟧ ϱ def. of translation = ⟦ tagInst i d ( W 1 , W 2 ) [ V / x ] ⟧ ϱ def. of substitution \begin{aligned}
\llbracket\operatorname{tagInst}_{id}(W_1,W_2)\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]
= \operatorname{tagInst}_{id}(\llbracket W_1\rrbracket_{\varrho},\llbracket W_2\rrbracket_{\varrho})[\llbracket V\rrbracket_{\varrho}/x] \qquad\text{def. of translation} \\
&= \operatorname{tagInst}_{\varrho(id)}(\llbracket W_1\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x],\llbracket W_2\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]) \qquad\text{def. of substitution} \\
&= \operatorname{tagInst}_{\varrho(id)}(\llbracket W_1[V/x]\rrbracket_{\varrho},\llbracket W_2[V/x]\rrbracket_{\varrho}) \qquad\text{by (3) and (4)} \\
&= \llbracket\operatorname{tagInst}_{id}(W_1[V/x],W_2[V/x])\rrbracket_{\varrho} \qquad\text{def. of translation} \\
&= \llbracket\operatorname{tagInst}_{id}(W_1,W_2)[V/x]\rrbracket_{\varrho} \qquad\text{def. of substitution}
\end{aligned} [ [ tagInst i d ( W 1 , W 2 ) ] ] ϱ [ [ [ V ] ] ϱ / x ] = tagInst i d ( [ [ W 1 ] ] ϱ , [ [ W 2 ] ] ϱ ) [ [ [ V ] ] ϱ / x ] def. of translation = tagInst ϱ ( i d ) ( [ [ W 1 ] ] ϱ [ [ [ V ] ] ϱ / x ] , [ [ W 2 ] ] ϱ [ [ [ V ] ] ϱ / x ]) def. of substitution = tagInst ϱ ( i d ) ( [ [ W 1 [ V / x ] ] ] ϱ , [ [ W 2 [ V / x ] ] ] ϱ ) by (3) and (4) = [ [ tagInst i d ( W 1 [ V / x ] , W 2 [ V / x ]) ] ] ϱ def. of translation = [ [ tagInst i d ( W 1 , W 2 ) [ V / x ] ] ] ϱ def. of substitution
Cases W = ( W 1 , W 2 ) W=(W_1,W_2) W = ( W 1 , W 2 ) , W = W 1 : : W 2 W=W_1::W_2 W = W 1 :: W 2 , W = text W 1 W=\text{text }W_1 W = text W 1 , W = tag ( W 1 , W 2 ) W=\operatorname{tag}(W_1,W_2) W = tag ( W 1 , W 2 ) , W = attr ( W 1 , W 2 ) W=\operatorname{attr}(W_1,W_2) W = attr ( W 1 , W 2 ) , W = onClick W 1 W=\operatorname{onClick }W_1 W = onClick W 1 , and W = textInst W 1 W=\operatorname{textInst }W_1 W = textInst W 1 are all shown analogously to the above case.
Case W = λ y . M W=\lambda y.M W = λ y . M :
By premise ( i ) (i) ( i ) , we have (1) that ⟦ M ⟧ ϱ \llbracket M\rrbracket_{\varrho} [ [ M ] ] ϱ is well-defined.
By mutual inductive hypothesis (Lemma B.11 ) on (1) and premise ( i i ) (ii) ( ii ) , we get (2) that ⟦ M [ V / x ] ⟧ ϱ = ⟦ M ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket M[V/x]\rrbracket_{\varrho}=\llbracket M\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] [ [ M [ V / x ] ] ] ϱ = [ [ M ] ] ϱ [ [ [ V ] ] ϱ / x ] .
By convention, x ≠ x ′ x\ne x' x = x ′ , so we show the conclusion as follows:
⟦ λ y . M ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] = ( λ y . ⟦ M ⟧ ϱ ) [ ⟦ V ⟧ ϱ / x ] def. of translation = λ y . ( ⟦ M ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] ) def. of substitution = λ y . ( ⟦ M [ V / x ] ⟧ ϱ ) by (4) = ⟦ λ y . M [ V / x ] ⟧ ϱ def. of translation = ⟦ ( λ y . M ) [ V / x ] ⟧ ϱ def. of substitution \begin{aligned}
\llbracket\lambda y.M\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]
=(\lambda y.\llbracket M\rrbracket_{\varrho})[\llbracket V\rrbracket_{\varrho}/x] \qquad\text{def. of translation} \\
&=\lambda y.(\llbracket M\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]) \qquad\text{def. of substitution} \\
&=\lambda y.(\llbracket M[V/x]\rrbracket_{\varrho}) \qquad\text{by (4)} \\
&=\llbracket\lambda y.M[V/x]\rrbracket_{\varrho} \qquad\text{def. of translation} \\
&=\llbracket(\lambda y.M)[V/x]\rrbracket_{\varrho} \qquad\text{def. of substitution}
\end{aligned} [ [ λ y . M ] ] ϱ [ [ [ V ] ] ϱ / x ] = ( λ y . [ [ M ] ] ϱ ) [ [ [ V ] ] ϱ / x ] def. of translation = λ y . ( [ [ M ] ] ϱ [ [ [ V ] ] ϱ / x ]) def. of substitution = λ y . ( [ [ M [ V / x ] ] ] ϱ ) by (4) = [ [ λ y . M [ V / x ] ] ] ϱ def. of translation = [ [ ( λ y . M ) [ V / x ] ] ] ϱ def. of substitution
Case W = component { D } W=\operatorname{component}\{D\} W = component { D } :
By premise ( i ) (i) ( i ) , we have (1) that I ⟦ D ⟧ ( D , ⊥ , ϱ , ∅ ) \mathcal{I}\llbracket D\rrbracket(D,\perp,\varrho,\varnothing) I [ [ D ] ] ( D , ⊥ , ϱ , ∅ ) is well-defined.
By mutual inductive hypothesis (Lemma B.13 ) on (1) and premise ( i i ) (ii) ( ii ) , we get (2) that I ⟦ D [ V / x ] ⟧ ( D [ V / x ] , ⊥ , ϱ , ∅ ) = I ⟦ D ⟧ ( D , ⊥ , ϱ , ∅ ) [ ⟦ V ⟧ ϱ / x ] \mathcal{I}\llbracket D[V/x]\rrbracket(D[V/x],\perp,\varrho,\varnothing)=\mathcal{I}\llbracket D\rrbracket(D,\perp,\varrho,\varnothing)[\llbracket V\rrbracket_{\varrho}/x] I [ [ D [ V / x ] ] ] ( D [ V / x ] , ⊥ , ϱ , ∅ ) = I [ [ D ] ] ( D , ⊥ , ϱ , ∅ ) [ [ [ V ] ] ϱ / x ] .
We show the conclusion as follows:
⟦ component { D } ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] = ( component λ ( ) . let y = ref ( false ) in I ⟦ D ⟧ ( D , ⊥ , ϱ , ∅ ) ) [ ⟦ V ⟧ ϱ / x ] def. of translation = component λ ( ) . let y = ref ( false ) in I ⟦ D [ V / x ] ⟧ ( D [ V / x ] , ⊥ , ϱ , ∅ ) [ ⟦ V ⟧ ϱ / x ] def. of substitution = component λ ( ) . let y = ref ( false ) in I ⟦ D [ V / x ] ⟧ ( D [ V / x ] , ⊥ , ϱ , ∅ ) by (2) = ⟦ component { D [ V / x ] } ⟧ ϱ def. of translation = ⟦ ( component { D } ) [ V / x ] ⟧ ϱ def. of substitution \begin{aligned}
\llbracket\operatorname{component}\{D\}\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] \\
&=(\operatorname{component}\ \lambda().\operatorname{let}\ y=\operatorname{ref}(\operatorname{false})\ \operatorname{in}\ \mathcal{I}\llbracket D\rrbracket(D,\perp,\varrho,\varnothing))[\llbracket V\rrbracket_{\varrho}/x] \qquad\text{def. of translation} \\
&=\operatorname{component}\ \lambda().\operatorname{let}\ y=\operatorname{ref}(\operatorname{false})\ \operatorname{in}\ \mathcal{I}\llbracket D[V/x]\rrbracket(D[V/x],\perp,\varrho,\varnothing)[\llbracket V\rrbracket_{\varrho}/x] \qquad\text{def. of substitution} \\
&=\operatorname{component}\ \lambda().\operatorname{let}\ y=\operatorname{ref}(\operatorname{false})\ \operatorname{in}\ \mathcal{I}\llbracket D[V/x]\rrbracket(D[V/x],\perp,\varrho,\varnothing) \qquad\text{by (2)} \\
&=\llbracket\operatorname{component}\{D[V/x]\}\rrbracket_{\varrho} \qquad\text{def. of translation} \\
&=\llbracket(\operatorname{component}\{D\})[V/x]\rrbracket_{\varrho} \qquad\text{def. of substitution}
\end{aligned} [ [ component { D } ] ] ϱ [ [ [ V ] ] ϱ / x ] = ( component λ ( ) . let y = ref ( false ) in I [ [ D ] ] ( D , ⊥ , ϱ , ∅ )) [ [ [ V ] ] ϱ / x ] def. of translation = component λ ( ) . let y = ref ( false ) in I [ [ D [ V / x ] ] ] ( D [ V / x ] , ⊥ , ϱ , ∅ ) [ [ [ V ] ] ϱ / x ] def. of substitution = component λ ( ) . let y = ref ( false ) in I [ [ D [ V / x ] ] ] ( D [ V / x ] , ⊥ , ϱ , ∅ ) by (2) = [ [ component { D [ V / x ]} ] ] ϱ def. of translation = [ [ ( component { D }) [ V / x ] ] ] ϱ def. of substitution
Case W = compInst p ( ⌈ D ⌉ , W 1 ) W=\operatorname{compInst}_{p}(\lceil D\rceil,W_1) W = compInst p (⌈ D ⌉ , W 1 ) :
By premise ( i ) (i) ( i ) , we have (1) that S ⟦ D ⟧ ( ⊥ , ϱ , ∅ ) \mathcal{S}\llbracket D\rrbracket(\perp,\varrho,\varnothing) S [ [ D ] ] ( ⊥ , ϱ , ∅ ) is well-defined and (2) that ⟦ W 1 ⟧ ϱ \llbracket W_1\rrbracket_{\varrho} [ [ W 1 ] ] ϱ is well-defined.
By mutual inductive hypothesis (Lemma B.12 ) on (1) and premise ( i i ) (ii) ( ii ) , we get (3) that S ⟦ D [ V / x ] ⟧ ( ⊥ , ϱ , ∅ ) = S ⟦ D ⟧ ( ⊥ , ϱ , ∅ ) [ ⟦ V ⟧ ϱ / x ] \mathcal{S}\llbracket D[V/x]\rrbracket(\perp,\varrho,\varnothing)=\mathcal{S}\llbracket D\rrbracket(\perp,\varrho,\varnothing)[\llbracket V\rrbracket_{\varrho}/x] S [ [ D [ V / x ] ] ] ( ⊥ , ϱ , ∅ ) = S [ [ D ] ] ( ⊥ , ϱ , ∅ ) [ [ [ V ] ] ϱ / x ] .
By inductive hypothesis on (2) and premise ( i i ) (ii) ( ii ) , we get (4) that ⟦ W 1 [ V / x ] ⟧ ϱ = ⟦ W 1 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket W_1[V/x]\rrbracket_{\varrho}=\llbracket W_1\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] [ [ W 1 [ V / x ] ] ] ϱ = [ [ W 1 ] ] ϱ [ [ [ V ] ] ϱ / x ] .
⟦ compInst p ( ⌈ D ⌉ , W 1 ) ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] = compInst ( λ ( ) . S ⟦ D ⟧ ( ⊥ , ϱ , ∅ ) , ϱ ( p ) , ⟦ W 1 ⟧ ϱ ) [ ⟦ V ⟧ ϱ / x ] def. of translation = compInst ( λ ( ) . S ⟦ D ⟧ ( ⊥ , ϱ , ∅ ) [ ⟦ V ⟧ ϱ / x ] , ϱ ( p ) , ⟦ W 1 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] ) def. of substitution = compInst ( λ ( ) . S ⟦ D [ V / x ] ⟧ ( ⊥ , ϱ , ∅ ) , ϱ ( p ) , ⟦ W 1 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] ) by (3) = compInst ( λ ( ) . S ⟦ D [ V / x ] ⟧ ( ⊥ , ϱ , ∅ ) , ϱ ( p ) , ⟦ W 1 [ V / x ] ⟧ ϱ ) by (4) = ⟦ compInst p ( ⌈ D [ V / x ] ⌉ , W 1 [ V / x ] ) ⟧ ϱ def. of translation = ⟦ ( compInst p ( ⌈ D ⌉ , W 1 ) ) [ V / x ] ⟧ ϱ def. of substitution \llbracket\operatorname{compInst}_{p}(\lceil D\rceil,W_{1})\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]
\\
= \operatorname{compInst}(\lambda().S\llbracket D\rrbracket(\bot,\varrho,\emptyset),\varrho(p),\llbracket W_{1}\rrbracket_{\varrho})[\llbracket V\rrbracket_{\varrho}/x] \quad\text{def. of translation}
\\
= \operatorname{compInst}(\lambda().S\llbracket D\rrbracket(\bot,\varrho,\emptyset)[\llbracket V\rrbracket_{\varrho}/x],\varrho(p),\llbracket W_{1}\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]) \quad\text{def. of substitution}
\\
= \operatorname{compInst}(\lambda().S\llbracket D[V/x]\rrbracket(\bot,\varrho,\emptyset),\varrho(p),\llbracket W_{1}\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]) \quad\text{by (3)}
\\
= \operatorname{compInst}(\lambda().S\llbracket D[V/x]\rrbracket(\bot,\varrho,\emptyset),\varrho(p),\llbracket W_{1}[V/x]\rrbracket_{\varrho}) \quad\text{by (4)}
\\
= \llbracket\operatorname{compInst}_{p}(\lceil D[V/x]\rceil,W_{1}[V/x])\rrbracket_{\varrho} \quad\text{def. of translation}
\\
= \llbracket(\operatorname{compInst}_{p}(\lceil D\rceil,W_{1}))[V/x]\rrbracket_{\varrho} \quad\text{def. of substitution} [ [ compInst p (⌈ D ⌉ , W 1 ) ] ] ϱ [ [ [ V ] ] ϱ / x ] = compInst ( λ ( ) . S [ [ D ] ] ( ⊥ , ϱ , ∅ ) , ϱ ( p ) , [ [ W 1 ] ] ϱ ) [ [ [ V ] ] ϱ / x ] def. of translation = compInst ( λ ( ) . S [ [ D ] ] ( ⊥ , ϱ , ∅ ) [ [ [ V ] ] ϱ / x ] , ϱ ( p ) , [ [ W 1 ] ] ϱ [ [ [ V ] ] ϱ / x ]) def. of substitution = compInst ( λ ( ) . S [ [ D [ V / x ] ] ] ( ⊥ , ϱ , ∅ ) , ϱ ( p ) , [ [ W 1 ] ] ϱ [ [ [ V ] ] ϱ / x ]) by (3) = compInst ( λ ( ) . S [ [ D [ V / x ] ] ] ( ⊥ , ϱ , ∅ ) , ϱ ( p ) , [ [ W 1 [ V / x ] ] ] ϱ ) by (4) = [ [ compInst p (⌈ D [ V / x ]⌉ , W 1 [ V / x ]) ] ] ϱ def. of translation = [ [ ( compInst p (⌈ D ⌉ , W 1 )) [ V / x ] ] ] ϱ def. of substitution
Lemma B.11 (Substitution, computations). If
⟦ M ⟧ ϱ \llbracket M\rrbracket_{\varrho} [ [ M ] ] ϱ is well-defined and
⟦ V ⟧ ϱ \llbracket V\rrbracket_{\varrho} [ [ V ] ] ϱ is well-defined,
then ⟦ M [ V / x ] ⟧ ϱ = ⟦ M ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket M[V/x]\rrbracket_{\varrho}=\llbracket M\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] [ [ M [ V / x ] ] ] ϱ = [ [ M ] ] ϱ [ [ [ V ] ] ϱ / x ] .
Proof. By mutual induction on the structure of M M M with Lemmas B.10 , B.12 , and B.13 .
Case M = val W M=\operatorname{val} W M = val W :
By premise (i), (1) ⟦ W ⟧ ϱ \llbracket W\rrbracket_{\varrho} [ [ W ] ] ϱ is well-defined.
By mutual inductive hypothesis (Lemma B.10 ) on (1) and premise (ii), we get (2) that ⟦ W [ V / x ] ⟧ ϱ = ⟦ W ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket W[V/x]\rrbracket_{\varrho}=\llbracket W\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] [ [ W [ V / x ] ] ] ϱ = [ [ W ] ] ϱ [ [ [ V ] ] ϱ / x ] .
We show the conclusion as follows:
⟦ val W ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] = ( val ⟦ W ⟧ ϱ ) [ ⟦ V ⟧ ϱ / x ] def. of translation = val ⟦ W ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] def. of substitution = ( val ⟦ W [ V / x ] ⟧ ϱ ) by (2) = ⟦ val W [ V / x ] ⟧ ϱ def. of translation = ⟦ ( val W ) [ V / x ] ⟧ ϱ def. of substitution \llbracket\operatorname{val} W\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]
\\
= (\operatorname{val}\llbracket W\rrbracket_{\varrho})[\llbracket V\rrbracket_{\varrho}/x] \quad\text{def. of translation}
\\
= \operatorname{val}\llbracket W\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] \quad\text{def. of substitution}
\\
= (\operatorname{val}\llbracket W[V/x]\rrbracket_{\varrho}) \quad\text{by (2)}
\\
= \llbracket\operatorname{val} W[V/x]\rrbracket_{\varrho} \quad\text{def. of translation}
\\
= \llbracket(\operatorname{val} W)[V/x]\rrbracket_{\varrho} \quad\text{def. of substitution} [ [ val W ] ] ϱ [ [ [ V ] ] ϱ / x ] = ( val [ [ W ] ] ϱ ) [ [ [ V ] ] ϱ / x ] def. of translation = val [ [ W ] ] ϱ [ [ [ V ] ] ϱ / x ] def. of substitution = ( val [ [ W [ V / x ] ] ] ϱ ) by (2) = [ [ val W [ V / x ] ] ] ϱ def. of translation = [ [ ( val W ) [ V / x ] ] ] ϱ def. of substitution
Cases M = fst W M=\operatorname{fst}W M = fst W , M = snd W M=\operatorname{snd}W M = snd W , M = init W M=\operatorname{init}W M = init W , M = click i d W M=\operatorname{click}_{id}W M = click i d W , M = runClick W M=\operatorname{runClick}W M = runClick W , and M = update W M=\operatorname{update}W M = update W can all be shown analogously to the above case.
Case M = let y = M 1 in M 2 M=\operatorname{let}\ y=M_{1}\ \operatorname{in}\ M_{2} M = let y = M 1 in M 2 :
By premise (i), we have (1) that ⟦ M 1 ⟧ ϱ \llbracket M_{1}\rrbracket_{\varrho} [ [ M 1 ] ] ϱ is well-defined and (2) that ⟦ M 2 ⟧ ϱ \llbracket M_{2}\rrbracket_{\varrho} [ [ M 2 ] ] ϱ is well-defined.
By inductive hypothesis on each of (1) and (2) alongside premise (ii), we get (3) that ⟦ M 1 [ V / x ] ⟧ ϱ = ⟦ M 1 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket M_{1}[V/x]\rrbracket_{\varrho}=\llbracket M_{1}\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] [ [ M 1 [ V / x ] ] ] ϱ = [ [ M 1 ] ] ϱ [ [ [ V ] ] ϱ / x ] and (4) that ⟦ M 2 [ V / x ] ⟧ ϱ = ⟦ M 2 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket M_{2}[V/x]\rrbracket_{\varrho}=\llbracket M_{2}\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] [ [ M 2 [ V / x ] ] ] ϱ = [ [ M 2 ] ] ϱ [ [ [ V ] ] ϱ / x ] , respectively.
By convention, x ≠ y x\ne y x = y , so we show the conclusion as follows:
⟦ let y = M 1 in M 2 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] = ( let y = ⟦ M 1 ⟧ ϱ in ⟦ M 2 ⟧ ϱ ) [ ⟦ V ⟧ ϱ / x ] def. of translation = let y = ⟦ M 1 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] in ⟦ M 2 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] def. of substitution = let y = ⟦ M 1 [ V / x ] ⟧ ϱ in ⟦ M 2 [ V / x ] ⟧ ϱ by (3) and (4) = ⟦ let y = M 1 [ V / x ] in M 2 [ V / x ] ⟧ ϱ def. of translation = ⟦ ( let y = M 1 in M 2 ) [ V / x ] ⟧ ϱ def. of substitution \llbracket\operatorname{let}\ y=M_{1}\ \operatorname{in}\ M_{2}\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]
\\
= (\operatorname{let}\ y=\llbracket M_{1}\rrbracket_{\varrho}\ \operatorname{in}\ \llbracket M_{2}\rrbracket_{\varrho})[\llbracket V\rrbracket_{\varrho}/x] \quad\text{def. of translation}
\\
= \operatorname{let}\ y=\llbracket M_{1}\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]\ \operatorname{in}\ \llbracket M_{2}\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] \quad\text{def. of substitution}
\\
= \operatorname{let}\ y=\llbracket M_{1}[V/x]\rrbracket_{\varrho}\ \operatorname{in}\ \llbracket M_{2}[V/x]\rrbracket_{\varrho} \quad\text{by (3) and (4)}
\\
= \llbracket\operatorname{let}\ y=M_{1}[V/x]\ \operatorname{in}\ M_{2}[V/x]\rrbracket_{\varrho} \quad\text{def. of translation}
\\
= \llbracket(\operatorname{let}\ y=M_{1}\ \operatorname{in}\ M_{2})[V/x]\rrbracket_{\varrho} \quad\text{def. of substitution} [ [ let y = M 1 in M 2 ] ] ϱ [ [ [ V ] ] ϱ / x ] = ( let y = [ [ M 1 ] ] ϱ in [ [ M 2 ] ] ϱ ) [ [ [ V ] ] ϱ / x ] def. of translation = let y = [ [ M 1 ] ] ϱ [ [ [ V ] ] ϱ / x ] in [ [ M 2 ] ] ϱ [ [ [ V ] ] ϱ / x ] def. of substitution = let y = [ [ M 1 [ V / x ] ] ] ϱ in [ [ M 2 [ V / x ] ] ] ϱ by (3) and (4) = [ [ let y = M 1 [ V / x ] in M 2 [ V / x ] ] ] ϱ def. of translation = [ [ ( let y = M 1 in M 2 ) [ V / x ] ] ] ϱ def. of substitution
Case M = V 1 V 2 M = V_1 V_2 M = V 1 V 2 :
By premise ( i ) (i) ( i ) , (1) ⟦ V 1 ⟧ ϱ \llbracket V_1\rrbracket_{\varrho} [ [ V 1 ] ] ϱ is well-defined and (2) ⟦ V 2 ⟧ ϱ \llbracket V_2\rrbracket_{\varrho} [ [ V 2 ] ] ϱ is well-defined.
By mutual inductive hypothesis (Lemma B.10) on each of (1) and (2) alongside premise ( i i ) (ii) ( ii ) , we get (3) that ⟦ V 1 [ V / x ] ⟧ ϱ = ⟦ V 1 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket V_1[V/x]\rrbracket_{\varrho} = \llbracket V_1\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] [ [ V 1 [ V / x ] ] ] ϱ = [ [ V 1 ] ] ϱ [ [ [ V ] ] ϱ / x ] and (4) that ⟦ V 2 [ V / x ] ⟧ ϱ = ⟦ V 2 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket V_2[V/x]\rrbracket_{\varrho} = \llbracket V_2\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] [ [ V 2 [ V / x ] ] ] ϱ = [ [ V 2 ] ] ϱ [ [ [ V ] ] ϱ / x ] , respectively.
We show the conclusion as follows:
⟦ V 1 V 2 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] = ( ⟦ V 1 ⟧ ϱ ⟦ V 2 ⟧ ϱ ) [ ⟦ V ⟧ ϱ / x ] def. of translation = ⟦ V 1 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] ⟦ V 2 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] def. of substitution = ⟦ V 1 [ V / x ] ⟧ ϱ ⟦ V 2 [ V / x ] ⟧ ϱ by (3) and (4) = ⟦ V 1 [ V / x ] V 2 [ V / x ] ⟧ ϱ def. of translation = ⟦ ( V 1 V 2 ) [ V / x ] ⟧ ϱ def. of substitution \begin{aligned}
\llbracket V_1 V_2\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]
&= (\llbracket V_1\rrbracket_{\varrho}\llbracket V_2\rrbracket_{\varrho})[\llbracket V\rrbracket_{\varrho}/x] && \text{def. of translation}\\
&= \llbracket V_1\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]\llbracket V_2\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] && \text{def. of substitution}\\
&= \llbracket V_1[V/x]\rrbracket_{\varrho}\llbracket V_2[V/x]\rrbracket_{\varrho} && \text{by (3) and (4)}\\
&= \llbracket V_1[V/x]\ V_2[V/x]\rrbracket_{\varrho} && \text{def. of translation}\\
&= \llbracket(V_1 V_2)[V/x]\rrbracket_{\varrho} && \text{def. of substitution}
\end{aligned} [ [ V 1 V 2 ] ] ϱ [ [ [ V ] ] ϱ / x ] = ( [ [ V 1 ] ] ϱ [ [ V 2 ] ] ϱ ) [ [ [ V ] ] ϱ / x ] = [ [ V 1 ] ] ϱ [ [ [ V ] ] ϱ / x ] [ [ V 2 ] ] ϱ [ [ [ V ] ] ϱ / x ] = [ [ V 1 [ V / x ] ] ] ϱ [ [ V 2 [ V / x ] ] ] ϱ = [ [ V 1 [ V / x ] V 2 [ V / x ] ] ] ϱ = [ [ ( V 1 V 2 ) [ V / x ] ] ] ϱ def. of translation def. of substitution by (3) and (4) def. of translation def. of substitution
Case M = fold V 1 V 2 V 3 M = \operatorname{fold} V_1 V_2 V_3 M = fold V 1 V 2 V 3 can be shown analogously to the above case.
Case M = if W then M 1 else M 2 M = \operatorname{if}\ W\ \operatorname{then}\ M_1\ \operatorname{else}\ M_2 M = if W then M 1 else M 2 :
By premise ( i ) (i) ( i ) , we have (1) that ⟦ W ⟧ ϱ \llbracket W\rrbracket_{\varrho} [ [ W ] ] ϱ is well-defined, (2) that ⟦ M 1 ⟧ ϱ \llbracket M_1\rrbracket_{\varrho} [ [ M 1 ] ] ϱ is well-defined, and (3) that ⟦ M 2 ⟧ ϱ \llbracket M_2\rrbracket_{\varrho} [ [ M 2 ] ] ϱ is well-defined.
By mutual inductive hypothesis (Lemma B.10) on (1) and premise ( i i ) (ii) ( ii ) , we get (4) that ⟦ W [ V / x ] ⟧ ϱ = ⟦ W ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket W[V/x]\rrbracket_{\varrho} = \llbracket W\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] [ [ W [ V / x ] ] ] ϱ = [ [ W ] ] ϱ [ [ [ V ] ] ϱ / x ] .
By inductive hypothesis on each of (2) and (3) alongside premise ( i i ) (ii) ( ii ) , we get (5) that ⟦ M 1 [ V / x ] ⟧ ϱ = ⟦ M 1 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket M_1[V/x]\rrbracket_{\varrho} = \llbracket M_1\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] [ [ M 1 [ V / x ] ] ] ϱ = [ [ M 1 ] ] ϱ [ [ [ V ] ] ϱ / x ] and (6) that ⟦ M 2 [ V / x ] ⟧ ϱ = ⟦ M 2 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket M_2[V/x]\rrbracket_{\varrho} = \llbracket M_2\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] [ [ M 2 [ V / x ] ] ] ϱ = [ [ M 2 ] ] ϱ [ [ [ V ] ] ϱ / x ] , respectively.
We show the conclusion as follows:
⟦ if W then M 1 else M 2 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] = ( if ⟦ W ⟧ ϱ then ⟦ M 1 ⟧ ϱ else ⟦ M 2 ⟧ ϱ ) [ ⟦ V ⟧ ϱ / x ] def. of translation = if ⟦ W ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] then ⟦ M 1 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] else ⟦ M 2 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] def. of substitution = if ⟦ W [ V / x ] ⟧ ϱ then ⟦ M 1 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] else ⟦ M 2 ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] by (4) = if ⟦ W [ V / x ] ⟧ ϱ then ⟦ M 1 [ V / x ] ⟧ ϱ else ⟦ M 2 [ V / x ] ⟧ ϱ by (5) and (6) = ⟦ if W [ V / x ] then M 1 [ V / x ] else M 2 [ V / x ] ⟧ ϱ def. of translation = ⟦ ( if W then M 1 else M 2 ) [ V / x ] ⟧ ϱ def. of substitution \begin{aligned}
\llbracket\operatorname{if}\ W\ \operatorname{then}\ M_1\ \operatorname{else}\ M_2\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]
&= (\operatorname{if}\ \llbracket W\rrbracket_{\varrho}\ \operatorname{then}\ \llbracket M_1\rrbracket_{\varrho}\ \operatorname{else}\ \llbracket M_2\rrbracket_{\varrho})[\llbracket V\rrbracket_{\varrho}/x] && \text{def. of translation}\\
&= \operatorname{if}\ \llbracket W\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]\ \operatorname{then}\ \llbracket M_1\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]\ \operatorname{else}\ \llbracket M_2\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] && \text{def. of substitution}\\
&= \operatorname{if}\ \llbracket W[V/x]\rrbracket_{\varrho}\ \operatorname{then}\ \llbracket M_1\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]\ \operatorname{else}\ \llbracket M_2\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] && \text{by (4)}\\
&= \operatorname{if}\ \llbracket W[V/x]\rrbracket_{\varrho}\ \operatorname{then}\ \llbracket M_1[V/x]\rrbracket_{\varrho}\ \operatorname{else}\ \llbracket M_2[V/x]\rrbracket_{\varrho} && \text{by (5) and (6)}\\
&= \llbracket\operatorname{if}\ W[V/x]\ \operatorname{then}\ M_1[V/x]\ \operatorname{else}\ M_2[V/x]\rrbracket_{\varrho} && \text{def. of translation}\\
&= \llbracket(\operatorname{if}\ W\ \operatorname{then}\ M_1\ \operatorname{else}\ M_2)[V/x]\rrbracket_{\varrho} && \text{def. of substitution}
\end{aligned} [ [ if W then M 1 else M 2 ] ] ϱ [ [ [ V ] ] ϱ / x ] = ( if [ [ W ] ] ϱ then [ [ M 1 ] ] ϱ else [ [ M 2 ] ] ϱ ) [ [ [ V ] ] ϱ / x ] = if [ [ W ] ] ϱ [ [ [ V ] ] ϱ / x ] then [ [ M 1 ] ] ϱ [ [ [ V ] ] ϱ / x ] else [ [ M 2 ] ] ϱ [ [ [ V ] ] ϱ / x ] = if [ [ W [ V / x ] ] ] ϱ then [ [ M 1 ] ] ϱ [ [ [ V ] ] ϱ / x ] else [ [ M 2 ] ] ϱ [ [ [ V ] ] ϱ / x ] = if [ [ W [ V / x ] ] ] ϱ then [ [ M 1 [ V / x ] ] ] ϱ else [ [ M 2 [ V / x ] ] ] ϱ = [ [ if W [ V / x ] then M 1 [ V / x ] else M 2 [ V / x ] ] ] ϱ = [ [ ( if W then M 1 else M 2 ) [ V / x ] ] ] ϱ def. of translation def. of substitution by (4) by (5) and (6) def. of translation def. of substitution
Case TC-EvalI:
By premise ( i ) (i) ( i ) , we have (1) that I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) \mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\emptyset) I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) is well-defined.
By mutual inductive hypothesis (Lemma B.13) on (1) and premise ( i i ) (ii) ( ii ) , we get (2) that I ⟦ D [ V / x ] ⟧ ( D 0 [ V / x ] , p , ϱ , ∅ ) = I ⟦ D ⟧ ( D 0 , ⊥ , ϱ , ∅ ) [ ⟦ V ⟧ ϱ / x ] \mathcal{I}\llbracket D[V/x]\rrbracket(D_0[V/x],p,\varrho,\emptyset) = \mathcal{I}\llbracket D\rrbracket(D_0,\bot,\varrho,\emptyset)[\llbracket V\rrbracket_{\varrho}/x] I [ [ D [ V / x ] ] ] ( D 0 [ V / x ] , p , ϱ , ∅ ) = I [ [ D ] ] ( D 0 , ⊥ , ϱ , ∅ ) [ [ [ V ] ] ϱ / x ] .
⟦ ⌈ D 0 ⌉ ↓ p I n i t D ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] = ( let r r , f , x ′ = I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) in compInst ( r r , f , init x ′ ) ) [ ⟦ V ⟧ ϱ / x ] def. of translation = ( let r r , f , x ′ = I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) [ ⟦ V ⟧ ϱ / x ] in compInst ( r r , f , init x ′ ) ) def. of substitution = ( let r r , f , x ′ = I ⟦ D [ V / x ] ⟧ ( D 0 [ V / x ] , p , ϱ , ∅ ) in compInst ( r r , f , init x ′ ) ) by (2) = ⟦ ⌈ D 0 [ V / x ] ⌉ ↓ p I n i t D [ V / x ] ⟧ ϱ def. of translation = ⟦ ( ⌈ D 0 ⌉ ↓ p I n i t D ) [ V / x ] ⟧ ϱ def. of substitution \begin{aligned}
\llbracket\lceil D_0\rceil\mathord{\downarrow}^{\mathrm{Init}}_{p} D\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]
= (\operatorname{let}\ rr,f,x'=\mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\varnothing)\ \operatorname{in}\ \operatorname{compInst}(rr,f,\operatorname{init}\ x'))[\llbracket V\rrbracket_{\varrho}/x]
\quad\text{def. of translation} \\
&= (\operatorname{let}\ rr,f,x'=\mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\varnothing)[\llbracket V\rrbracket_{\varrho}/x]\ \operatorname{in}\ \operatorname{compInst}(rr,f,\operatorname{init}\ x'))\quad\text{def. of substitution} \\
&= (\operatorname{let}\ rr,f,x'=\mathcal{I}\llbracket D[V/x]\rrbracket(D_0[V/x],p,\varrho,\varnothing)\ \operatorname{in}\ \operatorname{compInst}(rr,f,\operatorname{init}\ x'))\quad\text{by (2)} \\
&= \llbracket\lceil D_0[V/x]\rceil\mathord{\downarrow}^{\mathrm{Init}}_{p}D[V/x]\rrbracket_{\varrho}\quad\text{def. of translation} \\
&= \llbracket(\lceil D_0\rceil\mathord{\downarrow}^{\mathrm{Init}}_{p}D)[V/x]\rrbracket_{\varrho}\quad\text{def. of substitution}
\end{aligned} [ [ ⌈ D 0 ⌉ ↓ p Init D ] ] ϱ [ [ [ V ] ] ϱ / x ] = ( let r r , f , x ′ = I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) in compInst ( r r , f , init x ′ )) [ [ [ V ] ] ϱ / x ] def. of translation = ( let r r , f , x ′ = I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) [ [ [ V ] ] ϱ / x ] in compInst ( r r , f , init x ′ )) def. of substitution = ( let r r , f , x ′ = I [ [ D [ V / x ] ] ] ( D 0 [ V / x ] , p , ϱ , ∅ ) in compInst ( r r , f , init x ′ )) by (2) = [ [ ⌈ D 0 [ V / x ]⌉ ↓ p Init D [ V / x ] ] ] ϱ def. of translation = [ [ (⌈ D 0 ⌉ ↓ p Init D ) [ V / x ] ] ] ϱ def. of substitution
Case TC-EvalS:
By premise (i i i ), we have (1) that S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) \mathcal{S}\llbracket D_0\rrbracket(p,\varrho,\varnothing) S [ [ D 0 ] ] ( p , ϱ , ∅ ) is well-defined and (2) that S ⟦ D ⟧ ( p , ϱ , ∅ ) \mathcal{S}\llbracket D\rrbracket(p,\varrho,\varnothing) S [ [ D ] ] ( p , ϱ , ∅ ) is well-defined.
By mutual inductive hypothesis on each of (1) and (2) alongside premise (i i ii ii ), we get (3) that S ⟦ D 0 [ V / x ] ⟧ ( p , ϱ , ∅ ) = S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) [ ⟦ V ⟧ ϱ / x ] \mathcal{S}\llbracket D_0[V/x]\rrbracket(p,\varrho,\varnothing)=\mathcal{S}\llbracket D_0\rrbracket(p,\varrho,\varnothing)[\llbracket V\rrbracket_{\varrho}/x] S [ [ D 0 [ V / x ] ] ] ( p , ϱ , ∅ ) = S [ [ D 0 ] ] ( p , ϱ , ∅ ) [ [ [ V ] ] ϱ / x ] and (4) that S ⟦ D [ V / x ] ⟧ ( p , ϱ , ∅ ) = S ⟦ D ⟧ ( p , ϱ , ∅ ) [ ⟦ V ⟧ ϱ / x ] \mathcal{S}\llbracket D[V/x]\rrbracket(p,\varrho,\varnothing)=\mathcal{S}\llbracket D\rrbracket(p,\varrho,\varnothing)[\llbracket V\rrbracket_{\varrho}/x] S [ [ D [ V / x ] ] ] ( p , ϱ , ∅ ) = S [ [ D ] ] ( p , ϱ , ∅ ) [ [ [ V ] ] ϱ / x ] , respectively.
We show the conclusion as follows:
⟦ ⌈ D 0 ⌉ ↓ p S u c c D ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] = compInst ( λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , init S ⟦ D ⟧ ( p , ϱ , ∅ ) ) [ ⟦ V ⟧ ϱ / x ] def. of translation = compInst ( λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) [ ⟦ V ⟧ ϱ / x ] , ϱ ( p ) , init S ⟦ D ⟧ ( p , ϱ , ∅ ) [ ⟦ V ⟧ ϱ / x ] ) def. of substitution = compInst ( λ ( ) . S ⟦ D 0 [ V / x ] ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , init S ⟦ D [ V / x ] ⟧ ( p , ϱ , ∅ ) ) by (3) and (4) = ⟦ ⌈ D 0 [ V / x ] ⌉ ↓ p S u c c D [ V / x ] ⟧ ϱ def. of translation = ⟦ ( ⌈ D 0 ⌉ ↓ p S u c c D ) [ V / x ] ⟧ ϱ def. of substitution \begin{aligned}
\llbracket\lceil D_0\rceil\mathord{\downarrow}^{\mathrm{Succ}}_{p}D\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]
= \operatorname{compInst}(\lambda().\mathcal{S}\llbracket D_0\rrbracket(p,\varrho,\varnothing),\varrho(p),\operatorname{init}\ \mathcal{S}\llbracket D\rrbracket(p,\varrho,\varnothing))[\llbracket V\rrbracket_{\varrho}/x]
\quad\text{def. of translation} \\
&= \operatorname{compInst}(\lambda().\mathcal{S}\llbracket D_0\rrbracket(p,\varrho,\varnothing)[\llbracket V\rrbracket_{\varrho}/x],\varrho(p),\operatorname{init}\ \mathcal{S}\llbracket D\rrbracket(p,\varrho,\varnothing)[\llbracket V\rrbracket_{\varrho}/x])
\quad\text{def. of substitution} \\
&= \operatorname{compInst}(\lambda().\mathcal{S}\llbracket D_0[V/x]\rrbracket(p,\varrho,\varnothing),\varrho(p),\operatorname{init}\ \mathcal{S}\llbracket D[V/x]\rrbracket(p,\varrho,\varnothing))
\quad\text{by (3) and (4)} \\
&= \llbracket\lceil D_0[V/x]\rceil\mathord{\downarrow}^{\mathrm{Succ}}_{p}D[V/x]\rrbracket_{\varrho}\quad\text{def. of translation} \\
&= \llbracket(\lceil D_0\rceil\mathord{\downarrow}^{\mathrm{Succ}}_{p}D)[V/x]\rrbracket_{\varrho}\quad\text{def. of substitution}
\end{aligned} [ [ ⌈ D 0 ⌉ ↓ p Succ D ] ] ϱ [ [ [ V ] ] ϱ / x ] = compInst ( λ ( ) . S [ [ D 0 ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , init S [ [ D ] ] ( p , ϱ , ∅ )) [ [ [ V ] ] ϱ / x ] def. of translation = compInst ( λ ( ) . S [ [ D 0 ] ] ( p , ϱ , ∅ ) [ [ [ V ] ] ϱ / x ] , ϱ ( p ) , init S [ [ D ] ] ( p , ϱ , ∅ ) [ [ [ V ] ] ϱ / x ]) def. of substitution = compInst ( λ ( ) . S [ [ D 0 [ V / x ] ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , init S [ [ D [ V / x ] ] ] ( p , ϱ , ∅ )) by (3) and (4) = [ [ ⌈ D 0 [ V / x ]⌉ ↓ p Succ D [ V / x ] ] ] ϱ def. of translation = [ [ (⌈ D 0 ⌉ ↓ p Succ D ) [ V / x ] ] ] ϱ def. of substitution
Lemma B.12 (Substitution, bodies, successor). If
(i) S ⟦ D ⟧ ( p , ϱ , δ ) \mathcal{S}\llbracket D\rrbracket(p,\varrho,\delta) S [ [ D ] ] ( p , ϱ , δ ) is well-defined,
(ii) ⟦ V ⟧ ϱ \llbracket V\rrbracket_{\varrho} [ [ V ] ] ϱ is well-defined, and
(iii) x ∉ img ( δ ) x\notin\operatorname{img}(\delta) x ∈ / img ( δ ) ,
then S ⟦ D [ V / x ] ⟧ ( p , ϱ , δ ) = S ⟦ D ⟧ ( p , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] \mathcal{S}\llbracket D[V/x]\rrbracket(p,\varrho,\delta)=\mathcal{S}\llbracket D\rrbracket(p,\varrho,\delta)[\llbracket V\rrbracket_{\varrho}/x] S [ [ D [ V / x ] ] ] ( p , ϱ , δ ) = S [ [ D ] ] ( p , ϱ , δ ) [ [ [ V ] ] ϱ / x ] .
Proof. By mutual induction on the structure of D D D with Lemmas B.10 , B.11 , and B.13 .
Case D = val W D=\operatorname{val}\ W D = val W :
By premise (i i i ), (1) ⟦ W ⟧ ϱ \llbracket W\rrbracket_{\varrho} [ [ W ] ] ϱ is well-defined.
By mutual inductive hypothesis (Lemma B.10 ) on (1) and premise (i i ii ii ), we get (2) that ⟦ W [ V / x ] ⟧ ϱ = ⟦ W ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket W[V/x]\rrbracket_{\varrho}=\llbracket W\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] [ [ W [ V / x ] ] ] ϱ = [ [ W ] ] ϱ [ [ [ V ] ] ϱ / x ] .
S ⟦ val W ⟧ ( ρ , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] = ( val ⟦ W ⟧ ϱ ) [ ⟦ V ⟧ ϱ / x ] def. of translation = val ⟦ W ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] def. of substitution = val ⟦ W [ V / x ] ⟧ ϱ by (2) = S ⟦ val W [ V / x ] ⟧ ( ρ , ϱ , δ ) def. of translation = S ⟦ ( val W ) [ V / x ] ⟧ ( ρ , ϱ , δ ) def. of substitution \begin{aligned}
S\llbracket\operatorname{val} W\rrbracket(\rho,\varrho,\delta)[\llbracket V\rrbracket\varrho/x] \\
= (\operatorname{val}\llbracket W\rrbracket\varrho)[\llbracket V\rrbracket\varrho/x] && \text{def. of translation}\\
= \operatorname{val}\llbracket W\rrbracket\varrho[\llbracket V\rrbracket\varrho/x] && \text{def. of substitution}\\
= \operatorname{val}\llbracket W[V/x]\rrbracket\varrho&& \text{by (2)}\\
= S\llbracket\operatorname{val} W[V/x]\rrbracket(\rho,\varrho,\delta) && \text{def. of translation}\\
= S\llbracket(\operatorname{val} W)[V/x]\rrbracket(\rho,\varrho,\delta) && \text{def. of substitution}
\end{aligned} S [ [ val W ] ] ( ρ , ϱ , δ ) [ [ [ V ] ] ϱ / x ] = ( val [ [ W ] ] ϱ ) [ [ [ V ] ] ϱ / x ] = val [ [ W ] ] ϱ [ [ [ V ] ] ϱ / x ] = val [ [ W [ V / x ] ] ] ϱ = S [ [ val W [ V / x ] ] ] ( ρ , ϱ , δ ) = S [ [ ( val W ) [ V / x ] ] ] ( ρ , ϱ , δ ) def. of translation def. of substitution by (2) def. of translation def. of substitution
Case D = let y = M in D ′ D = \text{let } y = M \text{ in } D' D = let y = M in D ′ :
By premise ( i ) (i) ( i ) , we have (1) that ⟦ M ⟧ ϱ \llbracket M\rrbracket\varrho [ [ M ] ] ϱ is well-defined and (2) that S ⟦ D ′ ⟧ ( ρ , ϱ , δ ) S\llbracket D'\rrbracket(\rho,\varrho,\delta) S [ [ D ′ ] ] ( ρ , ϱ , δ ) is well-defined.
By mutual inductive hypothesis (Lemma B.11) on (1) and premise ( i i ) (ii) ( ii ) , we get (3) that ⟦ M [ V / x ] ⟧ ϱ = ⟦ M ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket M[V/x]\rrbracket\varrho= \llbracket M\rrbracket\varrho[\llbracket V\rrbracket\varrho/x] [ [ M [ V / x ] ] ] ϱ = [ [ M ] ] ϱ [ [ [ V ] ] ϱ / x ] .
By inductive hypothesis on (2) and premises ( i i ) (ii) ( ii ) and ( i i i ) (iii) ( iii ) , we get (4) that S ⟦ D ′ [ V / x ] ⟧ ( ρ , ϱ , δ ) = S ⟦ D ′ ⟧ ( ρ , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] S\llbracket D'[V/x]\rrbracket(\rho,\varrho,\delta) = S\llbracket D'\rrbracket(\rho,\varrho,\delta)[\llbracket V\rrbracket\varrho/x] S [ [ D ′ [ V / x ] ] ] ( ρ , ϱ , δ ) = S [ [ D ′ ] ] ( ρ , ϱ , δ ) [ [ [ V ] ] ϱ / x ] .
By convention, y ≠ x y \ne x y = x , so we show the conclusion as follows:
S ⟦ let y = M in D ′ ⟧ ( ρ , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] = ( let y = ⟦ M ⟧ ϱ in S ⟦ D ′ ⟧ ( ρ , ϱ , δ ) ) [ ⟦ V ⟧ ϱ / x ] def. of translation = let y = ⟦ M ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] in S ⟦ D ′ ⟧ ( ρ , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] def. of substitution = let y = ⟦ M [ V / x ] ⟧ ϱ in S ⟦ D ′ ⟧ ( ρ , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] by (3) = let y = ⟦ M [ V / x ] ⟧ ϱ in S ⟦ D ′ [ V / x ] ⟧ ( ρ , ϱ , δ ) by (4) = S ⟦ let y = M [ V / x ] in D ′ [ V / x ] ⟧ ( ρ , ϱ , δ ) def. of translation = S ⟦ ( let y = M in D ′ ) [ V / x ] ⟧ ( ρ , ϱ , δ ) def. of substitution \begin{aligned}
S\llbracket\text{let } y = M \text{ in } D'\rrbracket(\rho,\varrho,\delta)[\llbracket V\rrbracket\varrho/x] \\
= (\text{let } y = \llbracket M\rrbracket\varrho\text{ in } S\llbracket D'\rrbracket(\rho,\varrho,\delta))[\llbracket V\rrbracket\varrho/x] && \text{def. of translation}\\
= \text{let } y = \llbracket M\rrbracket\varrho[\llbracket V\rrbracket\varrho/x] \text{ in } S\llbracket D'\rrbracket(\rho,\varrho,\delta)[\llbracket V\rrbracket\varrho/x] && \text{def. of substitution}\\
= \text{let } y = \llbracket M[V/x]\rrbracket\varrho\text{ in } S\llbracket D'\rrbracket(\rho,\varrho,\delta)[\llbracket V\rrbracket\varrho/x] && \text{by (3)}\\
= \text{let } y = \llbracket M[V/x]\rrbracket\varrho\text{ in } S\llbracket D'[V/x]\rrbracket(\rho,\varrho,\delta) && \text{by (4)}\\
= S\llbracket\text{let } y = M[V/x] \text{ in } D'[V/x]\rrbracket(\rho,\varrho,\delta) && \text{def. of translation}\\
= S\llbracket(\text{let } y = M \text{ in } D')[V/x]\rrbracket(\rho,\varrho,\delta) && \text{def. of substitution}
\end{aligned} S [ [ let y = M in D ′ ] ] ( ρ , ϱ , δ ) [ [ [ V ] ] ϱ / x ] = ( let y = [ [ M ] ] ϱ in S [ [ D ′ ] ] ( ρ , ϱ , δ )) [ [ [ V ] ] ϱ / x ] = let y = [ [ M ] ] ϱ [ [ [ V ] ] ϱ / x ] in S [ [ D ′ ] ] ( ρ , ϱ , δ ) [ [ [ V ] ] ϱ / x ] = let y = [ [ M [ V / x ] ] ] ϱ in S [ [ D ′ ] ] ( ρ , ϱ , δ ) [ [ [ V ] ] ϱ / x ] = let y = [ [ M [ V / x ] ] ] ϱ in S [ [ D ′ [ V / x ] ] ] ( ρ , ϱ , δ ) = S [ [ let y = M [ V / x ] in D ′ [ V / x ] ] ] ( ρ , ϱ , δ ) = S [ [ ( let y = M in D ′ ) [ V / x ] ] ] ( ρ , ϱ , δ ) def. of translation def. of substitution by (3) by (4) def. of translation def. of substitution
Case D = let y , y s e t = u s e S t a t e ℓ W in D ′ D = \text{let } y,y_{\mathrm{set}} = \mathrm{useState}^{\ell}\ W \text{ in } D' D = let y , y set = useState ℓ W in D ′ :
By premise ( i ) (i) ( i ) , we have (1) that S ⟦ D ′ ⟧ ( ρ , ϱ , δ ) S\llbracket D'\rrbracket(\rho,\varrho,\delta) S [ [ D ′ ] ] ( ρ , ϱ , δ ) is well-defined.
By inductive hypothesis on (1) and premises ( i i ) (ii) ( ii ) and ( i i i ) (iii) ( iii ) , we get (2) that S ⟦ D ′ [ V / x ] ⟧ ( ρ , ϱ , δ ) = S ⟦ D ′ ⟧ ( ρ , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] S\llbracket D'[V/x]\rrbracket(\rho,\varrho,\delta) = S\llbracket D'\rrbracket(\rho,\varrho,\delta)[\llbracket V\rrbracket\varrho/x] S [ [ D ′ [ V / x ] ] ] ( ρ , ϱ , δ ) = S [ [ D ′ ] ] ( ρ , ϱ , δ ) [ [ [ V ] ] ϱ / x ] .
Note that by premise ( i i i ) (iii) ( iii ) we must have (3) δ ( ρ , ℓ , ϱ ) [ V / x ] = δ ( ρ , ℓ , ϱ ) \delta(\rho,\ell,\varrho)[V/x] = \delta(\rho,\ell,\varrho) δ ( ρ , ℓ , ϱ ) [ V / x ] = δ ( ρ , ℓ , ϱ ) , since if δ ( ρ , ℓ , ϱ ) = x ′ \delta(\rho,\ell,\varrho) = x' δ ( ρ , ℓ , ϱ ) = x ′ , premise ( i i i ) (iii) ( iii ) guarantees x ′ ≠ x x' \ne x x ′ = x . Analogously, (4) δ ( ρ , ϱ ) [ V / x ] = δ ( ρ , ϱ ) \delta(\rho,\varrho)[V/x] = \delta(\rho,\varrho) δ ( ρ , ϱ ) [ V / x ] = δ ( ρ , ϱ ) .
By convention, x ∉ { y , y s e t } x \notin\{y,y_{\mathrm{set}}\} x ∈ / { y , y set } , so we show the conclusion as follows:
S ⟦ let y , y s e t = useState ℓ W in D ′ ⟧ ( p , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] = ( let y = ! δ ( p , ℓ , ϱ ) in let y s e t = λ z . ( δ ( p , ℓ , ϱ ) : = z ; δ ( p , ϱ ) : = true ) in S ⟦ D ′ ⟧ ( p , ϱ , δ ) ) [ ⟦ V ⟧ ϱ / x ] def. of translation = let y = ! δ ( p , ℓ , ϱ ) [ ⟦ V ⟧ ϱ / x ] in let y s e t = λ z . ( δ ( p , ℓ , ϱ ) [ ⟦ V ⟧ ϱ / x ] : = z ; δ ( p , ϱ ) [ ⟦ V ⟧ ϱ / x ] : = true ) in S ⟦ D ′ ⟧ ( p , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] def. of substitution = let y = ! δ ( p , ℓ , ϱ ) in let y s e t = λ z . ( δ ( p , ℓ , ϱ ) : = z ; δ ( p , ϱ ) : = true ) in S ⟦ D ′ ⟧ ( p , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] by (3) and (4) = let y = ! δ ( p , ℓ , ϱ ) in let y s e t = λ z . ( δ ( p , ℓ , ϱ ) : = z ; δ ( p , ϱ ) : = true ) in S ⟦ D ′ [ V / x ] ⟧ ( p , ϱ , δ ) by (2) = S ⟦ let y , y s e t = useState ℓ W [ V / x ] in D ′ [ V / x ] ⟧ ( p , ϱ , δ ) def. of translation = S ⟦ ( let y , y s e t = useState ℓ W in D ′ ) [ V / x ] ⟧ ( p , ϱ , δ ) def. of substitution \begin{aligned}
\mathcal{S}\llbracket\text{let } y,y_{\mathrm{set}}=\operatorname{useState}^{\ell}\ W\text{ in }D' \rrbracket(p,\varrho,\delta)[\llbracket V\rrbracket_{\varrho}/x]
&= (\text{let } y = !\ \delta(p,\ell,\varrho)\text{ in}\\
&\qquad\text{let } y_{\mathrm{set}}=\lambda z.(\delta(p,\ell,\varrho):=z;\ \delta(p,\varrho):=\text{true})\text{ in}\ \mathcal{S}\llbracket D'\rrbracket(p,\varrho,\delta))[\llbracket V\rrbracket_{\varrho}/x] && \text{def. of translation}\\
&= \text{let } y = !\ \delta(p,\ell,\varrho)[\llbracket V\rrbracket_{\varrho}/x]\text{ in}\\
&\qquad\text{let } y_{\mathrm{set}}=\lambda z.(\delta(p,\ell,\varrho)[\llbracket V\rrbracket_{\varrho}/x]:=z;\ \delta(p,\varrho)[\llbracket V\rrbracket_{\varrho}/x]:=\text{true})\text{ in}\ \mathcal{S}\llbracket D'\rrbracket(p,\varrho,\delta)[\llbracket V\rrbracket_{\varrho}/x] && \text{def. of substitution}\\
&= \text{let } y = !\ \delta(p,\ell,\varrho)\text{ in}\\
&\qquad\text{let } y_{\mathrm{set}}=\lambda z.(\delta(p,\ell,\varrho):=z;\ \delta(p,\varrho):=\text{true})\text{ in}\ \mathcal{S}\llbracket D'\rrbracket(p,\varrho,\delta)[\llbracket V\rrbracket_{\varrho}/x] && \text{by (3) and (4)}\\
&= \text{let } y = !\ \delta(p,\ell,\varrho)\text{ in}\\
&\qquad\text{let } y_{\mathrm{set}}=\lambda z.(\delta(p,\ell,\varrho):=z;\ \delta(p,\varrho):=\text{true})\text{ in}\\
&\qquad\mathcal{S}\llbracket D'[V/x]\rrbracket(p,\varrho,\delta) && \text{by (2)}\\
&= \mathcal{S}\llbracket\text{let } y,y_{\mathrm{set}}=\operatorname{useState}^{\ell}\ W[V/x]\text{ in }D'[V/x]\rrbracket(p,\varrho,\delta) && \text{def. of translation}\\
&= \mathcal{S}\llbracket(\text{let } y,y_{\mathrm{set}}=\operatorname{useState}^{\ell}\ W\text{ in }D')[V/x]\rrbracket(p,\varrho,\delta) && \text{def. of substitution}
\end{aligned} S [ [ let y , y set = useState ℓ W in D ′ ] ] ( p , ϱ , δ ) [ [ [ V ] ] ϱ / x ] = ( let y = ! δ ( p , ℓ , ϱ ) in let y set = λ z . ( δ ( p , ℓ , ϱ ) := z ; δ ( p , ϱ ) := true ) in S [ [ D ′ ] ] ( p , ϱ , δ )) [ [ [ V ] ] ϱ / x ] = let y = ! δ ( p , ℓ , ϱ ) [ [ [ V ] ] ϱ / x ] in let y set = λ z . ( δ ( p , ℓ , ϱ ) [ [ [ V ] ] ϱ / x ] := z ; δ ( p , ϱ ) [ [ [ V ] ] ϱ / x ] := true ) in S [ [ D ′ ] ] ( p , ϱ , δ ) [ [ [ V ] ] ϱ / x ] = let y = ! δ ( p , ℓ , ϱ ) in let y set = λ z . ( δ ( p , ℓ , ϱ ) := z ; δ ( p , ϱ ) := true ) in S [ [ D ′ ] ] ( p , ϱ , δ ) [ [ [ V ] ] ϱ / x ] = let y = ! δ ( p , ℓ , ϱ ) in let y set = λ z . ( δ ( p , ℓ , ϱ ) := z ; δ ( p , ϱ ) := true ) in S [ [ D ′ [ V / x ] ] ] ( p , ϱ , δ ) = S [ [ let y , y set = useState ℓ W [ V / x ] in D ′ [ V / x ] ] ] ( p , ϱ , δ ) = S [ [ ( let y , y set = useState ℓ W in D ′ ) [ V / x ] ] ] ( p , ϱ , δ ) def. of translation def. of substitution by (3) and (4) by (2) def. of translation def. of substitution
Lemma B.13 (Substitution, bodies, initial). If
(i) I ⟦ D ⟧ ( D 0 , p , ϱ , δ ) \mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\delta) I [ [ D ] ] ( D 0 , p , ϱ , δ ) is well-defined,
(ii) ⟦ V ⟧ ϱ \llbracket V\rrbracket_{\varrho} [ [ V ] ] ϱ is well-defined, and
(iii) x ∉ img ( δ ) x\notin\operatorname{img}(\delta) x ∈ / img ( δ ) ,
then I ⟦ D [ V / x ] ⟧ ( D 0 [ V / x ] , p , ϱ , δ ) = I ⟦ D ⟧ ( D 0 , p , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] \mathcal{I}\llbracket D[V/x]\rrbracket(D_0[V/x],p,\varrho,\delta)=\mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\delta)[\llbracket V\rrbracket_{\varrho}/x] I [ [ D [ V / x ] ] ] ( D 0 [ V / x ] , p , ϱ , δ ) = I [ [ D ] ] ( D 0 , p , ϱ , δ ) [ [ [ V ] ] ϱ / x ] .
Proof. By mutual induction on the structure of D D D with Lemmas B.10 , B.11 , and B.12
Case D = val W D=\operatorname{val}\ W D = val W :
By premise (i), we have (1) that ⟦ W ⟧ ϱ \llbracket W\rrbracket_{\varrho} [ [ W ] ] ϱ is well-defined and (2) that S ⟦ D 0 ⟧ ( p , ϱ , δ ) \mathcal{S}\llbracket D_0\rrbracket(p,\varrho,\delta) S [ [ D 0 ] ] ( p , ϱ , δ ) is well-defined.
By mutual inductive hypothesis (Lemma B.10 ) on (1) and premise (ii), we get (3) that ⟦ W [ V / x ] ⟧ ϱ = ⟦ W ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket W[V/x]\rrbracket_{\varrho}=\llbracket W\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x] [ [ W [ V / x ] ] ] ϱ = [ [ W ] ] ϱ [ [ [ V ] ] ϱ / x ] .
By mutual inductive hypothesis (Lemma B.12 ) on (2) and premises (ii) and (iii), we get (4) that S ⟦ D 0 [ V / x ] ⟧ ( p , ϱ , δ ) = S ⟦ D 0 ⟧ ( p , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] \mathcal{S}\llbracket D_0[V/x]\rrbracket(p,\varrho,\delta)=\mathcal{S}\llbracket D_0\rrbracket(p,\varrho,\delta)[\llbracket V\rrbracket_{\varrho}/x] S [ [ D 0 [ V / x ] ] ] ( p , ϱ , δ ) = S [ [ D 0 ] ] ( p , ϱ , δ ) [ [ [ V ] ] ϱ / x ] .
Note that by premise (iii), we must have (5) δ ( p , ϱ ) [ V / x ] = δ ( p , ϱ ) \delta(p,\varrho)[V/x]=\delta(p,\varrho) δ ( p , ϱ ) [ V / x ] = δ ( p , ϱ ) , since if δ ( p , ϱ ) = x ′ \delta(p,\varrho)=x' δ ( p , ϱ ) = x ′ , premise (iii) guarantees x ′ ≠ x x'\ne x x ′ = x .
We show the conclusion as follows:
I ⟦ val W ⟧ ( D 0 , p , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] = val ( λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , δ ) , δ ( p , ϱ ) , ⟦ W ⟧ ϱ ) [ ⟦ V ⟧ ϱ / x ] def. of translation = val ( λ ( ) . S ⟦ D 0 ⟧ ( p , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] , δ ( p , ϱ ) [ ⟦ V ⟧ ϱ / x ] , ⟦ W ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] ) def. of substitution = val ( λ ( ) . S ⟦ D 0 [ V / x ] ⟧ ( p , ϱ , δ ) , δ ( p , ϱ ) , ⟦ W [ V / x ] ⟧ ϱ ) by (5), (6), and (7) = I ⟦ val W [ V / x ] ⟧ ( D 0 [ V / x ] , p , ϱ , δ ) def. of translation = I ⟦ ( val W ) [ V / x ] ⟧ ( D 0 [ V / x ] , p , ϱ , δ ) def. of substitution \begin{aligned}
\mathcal{I}\llbracket\operatorname{val}\ W\rrbracket(D_0,p,\varrho,\delta)[\llbracket V\rrbracket_{\varrho}/x]
&= \operatorname{val}(\lambda().\mathcal{S}\llbracket D_0\rrbracket(p,\varrho,\delta),\delta(p,\varrho),\llbracket W\rrbracket_{\varrho})[\llbracket V\rrbracket_{\varrho}/x] && \text{def. of translation}\\
&= \operatorname{val}(\lambda().\mathcal{S}\llbracket D_0\rrbracket(p,\varrho,\delta)[\llbracket V\rrbracket_{\varrho}/x],\delta(p,\varrho)[\llbracket V\rrbracket_{\varrho}/x],\llbracket W\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]) && \text{def. of substitution}\\
&= \operatorname{val}(\lambda().\mathcal{S}\llbracket D_0[V/x]\rrbracket(p,\varrho,\delta),\delta(p,\varrho),\llbracket W[V/x]\rrbracket_{\varrho}) && \text{by (5), (6), and (7)}\\
&= \mathcal{I}\llbracket\operatorname{val}\ W[V/x]\rrbracket(D_0[V/x],p,\varrho,\delta) && \text{def. of translation}\\
&= \mathcal{I}\llbracket(\operatorname{val}\ W)[V/x]\rrbracket(D_0[V/x],p,\varrho,\delta) && \text{def. of substitution}
\end{aligned} I [ [ val W ] ] ( D 0 , p , ϱ , δ ) [ [ [ V ] ] ϱ / x ] = val ( λ ( ) . S [ [ D 0 ] ] ( p , ϱ , δ ) , δ ( p , ϱ ) , [ [ W ] ] ϱ ) [ [ [ V ] ] ϱ / x ] = val ( λ ( ) . S [ [ D 0 ] ] ( p , ϱ , δ ) [ [ [ V ] ] ϱ / x ] , δ ( p , ϱ ) [ [ [ V ] ] ϱ / x ] , [ [ W ] ] ϱ [ [ [ V ] ] ϱ / x ]) = val ( λ ( ) . S [ [ D 0 [ V / x ] ] ] ( p , ϱ , δ ) , δ ( p , ϱ ) , [ [ W [ V / x ] ] ] ϱ ) = I [ [ val W [ V / x ] ] ] ( D 0 [ V / x ] , p , ϱ , δ ) = I [ [ ( val W ) [ V / x ] ] ] ( D 0 [ V / x ] , p , ϱ , δ ) def. of translation def. of substitution by (5), (6), and (7) def. of translation def. of substitution
Case D = let y = M in D ′ D = \text{let } y = M \text{ in } D' D = let y = M in D ′ can be shown analogously to the same case in Lemma B.12 (Succ-phase substitution).
Case D = let y , y s e t = useState ℓ V in D ′ D = \text{let } y, y_{\mathrm{set}} = \text{useState}^{\ell}\ V \text{ in } D' D = let y , y set = useState ℓ V in D ′ :
By premise (i), we have (1) that ⟦ V ⟧ ϱ \llbracket V \rrbracket_{\varrho} [ [ V ] ] ϱ is well-defined and (2) that I ⟦ D ⟧ ( D 0 , p , ϱ , δ , ℓ ↦ y ℓ ) \mathcal{I}\llbracket D \rrbracket(D_0,p,\varrho,\delta,\ell\mapsto y_{\ell}) I [ [ D ] ] ( D 0 , p , ϱ , δ , ℓ ↦ y ℓ ) is well-defined.
By mutual inductive hypothesis (Lemma B.10 ) on (1) and premise (ii), we have (3) that ⟦ W [ V / x ] ⟧ ϱ = ⟦ W ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] \llbracket W[V/x] \rrbracket_{\varrho} = \llbracket W \rrbracket_{\varrho}[\llbracket V \rrbracket_{\varrho}/x] [ [ W [ V / x ] ] ] ϱ = [ [ W ] ] ϱ [ [ [ V ] ] ϱ / x ] .
Note that whatever y ℓ y_{\ell} y ℓ we generate in our translation will be fresh, and so premise (iii) gives us (4) that x ∉ img ( δ , ℓ ↦ y ℓ ) x \notin\operatorname{img}(\delta,\ell\mapsto y_{\ell}) x ∈ / img ( δ , ℓ ↦ y ℓ ) .
By inductive hypothesis on (2), (4), and premise (ii), we get (5) that I ⟦ D [ V / x ] ⟧ ( D 0 [ V / x ] , p , ϱ , δ ) = I ⟦ D ⟧ ( D 0 , p , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] \mathcal{I}\llbracket D[V/x] \rrbracket(D_0[V/x],p,\varrho,\delta) = \mathcal{I}\llbracket D \rrbracket(D_0,p,\varrho,\delta)[\llbracket V \rrbracket_{\varrho}/x] I [ [ D [ V / x ] ] ] ( D 0 [ V / x ] , p , ϱ , δ ) = I [ [ D ] ] ( D 0 , p , ϱ , δ ) [ [ [ V ] ] ϱ / x ] .
Note that by premise (iii) we must have (6) δ ( p , ϱ ) [ V / x ] = δ ( p , ϱ ) \delta(p,\varrho)[V/x] = \delta(p,\varrho) δ ( p , ϱ ) [ V / x ] = δ ( p , ϱ ) , since if δ ( p , ϱ ) = x ′ \delta(p,\varrho) = x' δ ( p , ϱ ) = x ′ , premise (iii) guarantees x ′ ≠ x x' \ne x x ′ = x .
By convention, x ∉ { y , y s e t } x \notin\{y,y_{\mathrm{set}}\} x ∈ / { y , y set } , and also x ≠ y ℓ x \ne y_{\ell} x = y ℓ since y ℓ y_{\ell} y ℓ is translation-fresh. We show the conclusion as follows:
I ⟦ let y , y s e t = useState ℓ W in D ′ ⟧ ( D 0 , p , ϱ , δ ) [ ⟦ V ⟧ ϱ / x ] = ( let y ℓ = ref ( ⟦ W ⟧ ϱ ) in let y = ! y ℓ in let y s e t = λ z . ( y ℓ : = z ; δ ( p , ϱ ) : = true ) in I ⟦ D ′ ⟧ ( D 0 , p , ϱ , δ , ℓ ↦ y ℓ ) ) [ ⟦ V ⟧ ϱ / x ] \begin{aligned}
\mathcal{I}\llbracket\text{let } y,y_{\mathrm{set}} = \text{useState}^{\ell}\ W \text{ in } D' \rrbracket(D_0,p,\varrho,\delta)[\llbracket V \rrbracket_{\varrho}/x]
&= (\text{let } y_{\ell} = \operatorname{ref}(\llbracket W \rrbracket_{\varrho}) \text{ in} \\
&\quad\text{let } y = {!}y_{\ell} \text{ in} \\
&\quad\text{let } y_{\mathrm{set}} = \lambda z.(y_{\ell} := z\,;\,\delta(p,\varrho) := \text{true}) \text{ in} \\
&\quad\mathcal{I}\llbracket D' \rrbracket(D_0,p,\varrho,\delta,\ell\mapsto y_{\ell}))[\llbracket V \rrbracket_{\varrho}/x]
\end{aligned} I [ [ let y , y set = useState ℓ W in D ′ ] ] ( D 0 , p , ϱ , δ ) [ [ [ V ] ] ϱ / x ] = ( let y ℓ = ref ( [ [ W ] ] ϱ ) in let y = ! y ℓ in let y set = λ z . ( y ℓ := z ; δ ( p , ϱ ) := true ) in I [ [ D ′ ] ] ( D 0 , p , ϱ , δ , ℓ ↦ y ℓ )) [ [ [ V ] ] ϱ / x ]
= let y ℓ = ref ( ⟦ W ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] ) in let y = ! y ℓ in let y s e t = λ z . ( y ℓ : = z ; δ ( p , ϱ ) [ ⟦ V ⟧ ϱ / x ] : = true ) in I ⟦ D ′ ⟧ ( D 0 , p , ϱ , δ , ℓ ↦ y ℓ ) [ ⟦ V ⟧ ϱ / x ] \begin{aligned}
&= \text{let } y_{\ell} = \operatorname{ref}(\llbracket W \rrbracket_{\varrho}[\llbracket V \rrbracket_{\varrho}/x]) \text{ in} \\
&\quad\text{let } y = {!}y_{\ell} \text{ in} \\
&\quad\text{let } y_{\mathrm{set}} = \lambda z.(y_{\ell} := z\,;\,\delta(p,\varrho)[\llbracket V \rrbracket_{\varrho}/x] := \text{true}) \text{ in} \\
&\quad\mathcal{I}\llbracket D' \rrbracket(D_0,p,\varrho,\delta,\ell\mapsto y_{\ell})[\llbracket V \rrbracket_{\varrho}/x]
\end{aligned} = let y ℓ = ref ( [ [ W ] ] ϱ [ [ [ V ] ] ϱ / x ]) in let y = ! y ℓ in let y set = λ z . ( y ℓ := z ; δ ( p , ϱ ) [ [ [ V ] ] ϱ / x ] := true ) in I [ [ D ′ ] ] ( D 0 , p , ϱ , δ , ℓ ↦ y ℓ ) [ [ [ V ] ] ϱ / x ]
= let y ℓ = ref ( ⟦ W [ V / x ] ⟧ ϱ ) in let y = ! y ℓ in let y s e t = λ z . ( y ℓ : = z ; δ ( p , ϱ ) : = true ) in I ⟦ D ′ [ V / x ] ⟧ ( D 0 [ V / x ] , p , ϱ , δ , ℓ ↦ y ℓ ) \begin{aligned}
&= \text{let } y_{\ell} = \operatorname{ref}(\llbracket W[V/x] \rrbracket_{\varrho}) \text{ in} \\
&\quad\text{let } y = {!}y_{\ell} \text{ in} \\
&\quad\text{let } y_{\mathrm{set}} = \lambda z.(y_{\ell} := z\,;\,\delta(p,\varrho) := \text{true}) \text{ in} \\
&\quad\mathcal{I}\llbracket D'[V/x] \rrbracket(D_0[V/x],p,\varrho,\delta,\ell\mapsto y_{\ell})
\end{aligned} = let y ℓ = ref ( [ [ W [ V / x ] ] ] ϱ ) in let y = ! y ℓ in let y set = λ z . ( y ℓ := z ; δ ( p , ϱ ) := true ) in I [ [ D ′ [ V / x ] ] ] ( D 0 [ V / x ] , p , ϱ , δ , ℓ ↦ y ℓ )
= I ⟦ let y , y s e t = useState ℓ W [ V / x ] in D ′ [ V / x ] ⟧ ( D 0 [ V / x ] , p , ϱ , δ ) = I ⟦ ( let y , y s e t = useState ℓ W in D ′ ) [ V / x ] ⟧ ( D 0 [ V / x ] , p , ϱ , δ ) \begin{aligned}
&= \mathcal{I}\llbracket\text{let } y,y_{\mathrm{set}} = \text{useState}^{\ell}\ W[V/x] \text{ in } D'[V/x] \rrbracket(D_0[V/x],p,\varrho,\delta) \\
&= \mathcal{I}\llbracket(\text{let } y,y_{\mathrm{set}} = \text{useState}^{\ell}\ W \text{ in } D')[V/x] \rrbracket(D_0[V/x],p,\varrho,\delta)
\end{aligned} = I [ [ let y , y set = useState ℓ W [ V / x ] in D ′ [ V / x ] ] ] ( D 0 [ V / x ] , p , ϱ , δ ) = I [ [ ( let y , y set = useState ℓ W in D ′ ) [ V / x ] ] ] ( D 0 [ V / x ] , p , ϱ , δ )
ϱ \varrho ϱ -Extension
The following set of “ϱ \varrho ϱ -extension lemmas” state that a well-defined translation under ϱ \varrho ϱ is equivalent to that translation under extensions of ϱ \varrho ϱ . They are fairly easy to prove, but nonetheless important.
Lemma B.14 (ϱ \varrho ϱ -extension, values). If
⟦ V ⟧ ϱ \llbracket V \rrbracket_{\varrho} [ [ V ] ] ϱ is well-defined and
ϱ ⊆ ϱ ′ \varrho\subseteq\varrho' ϱ ⊆ ϱ ′ ,
then ⟦ V ⟧ ϱ = ⟦ V ⟧ ϱ ′ \llbracket V \rrbracket_{\varrho} = \llbracket V \rrbracket_{\varrho'} [ [ V ] ] ϱ = [ [ V ] ] ϱ ′ .
Proof. This can be most formally shown by mutual induction over the structure of V V V , but we here provide a direct argument instead. By premise (i) and definition of well-definedness, we have that all instances of ρ ( i d ) \rho(id) ρ ( i d ) , ρ ( p ) \rho(p) ρ ( p ) , and ρ ( p , ℓ ) \rho(p,\ell) ρ ( p , ℓ ) which occur in the translation result are well-defined. Without loss of generality, take ρ ( p ) \rho(p) ρ ( p ) as an example, and suppose ρ ( p ) \rho(p) ρ ( p ) occurs in the translation result. Then by premise (i), ρ ( p ) \rho(p) ρ ( p ) is well-defined. Now by premise (ii), since ρ ( p ) \rho(p) ρ ( p ) is well-defined and ρ ⊆ ρ ′ \rho\subseteq\rho' ρ ⊆ ρ ′ , we must have ρ ′ ( p ) = ρ ( p ) \rho'(p) = \rho(p) ρ ′ ( p ) = ρ ( p ) . By analogy, ρ ′ ( p , ℓ ) = ρ ( p , ℓ ) \rho'(p,\ell) = \rho(p,\ell) ρ ′ ( p , ℓ ) = ρ ( p , ℓ ) and ρ ′ ( i d ) = ρ ( i d ) \rho'(id) = \rho(id) ρ ′ ( i d ) = ρ ( i d ) for any relevant instances of ρ ( p , ℓ ) \rho(p,\ell) ρ ( p , ℓ ) and ρ ( i d ) \rho(id) ρ ( i d ) .
Choice of ρ \rho ρ only affects the translation result by occurrences of ρ ( i d ) \rho(id) ρ ( i d ) , ρ ( p ) \rho(p) ρ ( p ) , and ρ ( p , ℓ ) \rho(p,\ell) ρ ( p , ℓ ) , and we have shown that these are equivalent to ρ ′ ( i d ) \rho'(id) ρ ′ ( i d ) , ρ ′ ( p ) \rho'(p) ρ ′ ( p ) , and ρ ′ ( p , ℓ ) \rho'(p,\ell) ρ ′ ( p , ℓ ) respectively. Therefore, ⟦ V ⟧ ρ = ⟦ V ⟧ ρ ′ \llbracket V \rrbracket_{\rho} = \llbracket V \rrbracket_{\rho'} [ [ V ] ] ρ = [ [ V ] ] ρ ′ and we are done. □
The above argument applies to all other ρ \rho ρ -extension lemmas, whose proofs we therefore elide.
Lemma B.15 (ρ \rho ρ -extension, computations). If
(i) ⟦ M ⟧ ρ \llbracket M \rrbracket_{\rho} [ [ M ] ] ρ is well-defined and
(ii) ρ ⊆ ρ ′ \rho\subseteq\rho' ρ ⊆ ρ ′ ,
then ⟦ M ⟧ ρ = ⟦ M ⟧ ρ ′ \llbracket M \rrbracket_{\rho} = \llbracket M \rrbracket_{\rho'} [ [ M ] ] ρ = [ [ M ] ] ρ ′ .
Lemma B.16 (ρ \rho ρ -extension, bodies, successor). If
(i) S ⟦ D ⟧ ( p , ρ , δ ) S\llbracket D \rrbracket(p,\rho,\delta) S [ [ D ] ] ( p , ρ , δ ) is well-defined and
(ii) ρ ⊆ ρ ′ \rho\subseteq\rho' ρ ⊆ ρ ′ ,
then S ⟦ D ⟧ ( p , ρ , δ ) = S ⟦ D ⟧ ( p , ρ ′ , δ ) S\llbracket D \rrbracket(p,\rho,\delta) = S\llbracket D \rrbracket(p,\rho',\delta) S [ [ D ] ] ( p , ρ , δ ) = S [ [ D ] ] ( p , ρ ′ , δ ) .
Lemma B.17 (ρ \rho ρ -extension, bodies, initial). If
(i) I ⟦ D ⟧ ( D 0 , p , ρ , δ ) I\llbracket D \rrbracket(D_0,p,\rho,\delta) I [ [ D ] ] ( D 0 , p , ρ , δ ) is well-defined and
(ii) ρ ⊆ ρ ′ \rho\subseteq\rho' ρ ⊆ ρ ′ ,
then I ⟦ D ⟧ ( D 0 , p , ρ , δ ) = I ⟦ D ⟧ ( D 0 , p , ρ ′ , δ ) I\llbracket D \rrbracket(D_0,p,\rho,\delta) = I\llbracket D \rrbracket(D_0,p,\rho',\delta) I [ [ D ] ] ( D 0 , p , ρ , δ ) = I [ [ D ] ] ( D 0 , p , ρ ′ , δ ) .
Lemma B.18 (ρ \rho ρ -extension, heaps). If
(i) ⟦ H ⟧ ρ \llbracket H \rrbracket_{\rho} [ [ H ] ] ρ is well-defined and
(ii) ρ ⊆ ρ ′ \rho\subseteq\rho' ρ ⊆ ρ ′ ,
then ⟦ H ⟧ ρ = ⟦ H ⟧ ρ ′ \llbracket H \rrbracket_{\rho} = \llbracket H \rrbracket_{\rho'} [ [ H ] ] ρ = [ [ H ] ] ρ ′ .
Specialization
The “specialization” lemmas allow us to move from static bodies (parameterized by the nonexistent pointer ⊥ \bot ⊥ ) to dynamic bodies (parameterized by some concrete pointer p p p ).
Lemma B.19 (Specialization, successor). If S ⟦ D ⟧ ( ⊥ , ρ , δ ) S\llbracket D \rrbracket(\bot,\rho,\delta) S [ [ D ] ] ( ⊥ , ρ , δ ) is well-defined, then for any p p p , we have S ⟦ D ⟧ ( ⊥ , ρ , δ ) = S ⟦ D ⟧ ( p , ρ , δ ) S\llbracket D \rrbracket(\bot,\rho,\delta) = S\llbracket D \rrbracket(p,\rho,\delta) S [ [ D ] ] ( ⊥ , ρ , δ ) = S [ [ D ] ] ( p , ρ , δ ) .
Proof. This can be most formally shown by induction over the structure of D D D , but we here provide a direct argument instead.
By premise (i), any instances of δ ( ⊥ , ℓ , ρ ) \delta(\bot,\ell,\rho) δ ( ⊥ , ℓ , ρ ) or δ ( ⊥ , ρ ) \delta(\bot,\rho) δ ( ⊥ , ρ ) which appear in the translation are well-defined.
Consider first an arbitrary instance of δ ( ⊥ , ℓ , ρ ) \delta(\bot,\ell,\rho) δ ( ⊥ , ℓ , ρ ) : by definition, either ℓ ↦ x ℓ ∈ δ \ell\mapsto x_\ell\in\delta ℓ ↦ x ℓ ∈ δ and δ ( ⊥ , ℓ , ρ ) = x ℓ \delta(\bot,\ell,\rho) = x_\ell δ ( ⊥ , ℓ , ρ ) = x ℓ , or ℓ ∉ dom ( δ ) \ell\notin\operatorname{dom}(\delta) ℓ ∈ / dom ( δ ) and δ ( ⊥ , ℓ , ρ ) = ρ ( ⊥ , ℓ ) \delta(\bot,\ell,\rho) = \rho(\bot,\ell) δ ( ⊥ , ℓ , ρ ) = ρ ( ⊥ , ℓ ) . However, ρ ( ⊥ , ℓ ) = ⊥ \rho(\bot,\ell) = \bot ρ ( ⊥ , ℓ ) = ⊥ by definition of ρ \rho ρ , and so we therefore must have ℓ ↦ x ℓ ∈ δ \ell\mapsto x_\ell\in\delta ℓ ↦ x ℓ ∈ δ . Now, by definition, δ ( p , ℓ , ρ ) = x ℓ \delta(p,\ell,\rho) = x_\ell δ ( p , ℓ , ρ ) = x ℓ for any p p p . Thus, we get that δ ( ⊥ , ℓ , ρ ) = δ ( p , ℓ , ρ ) \delta(\bot,\ell,\rho) = \delta(p,\ell,\rho) δ ( ⊥ , ℓ , ρ ) = δ ( p , ℓ , ρ ) for any p p p . By analogy, we also have δ ( ⊥ , ρ ) = δ ( p , ρ ) \delta(\bot,\rho) = \delta(p,\rho) δ ( ⊥ , ρ ) = δ ( p , ρ ) for any p p p .
Choice of δ \delta δ only affects the translation result by occurrences of δ ( p , ℓ , ρ ) \delta(p,\ell,\rho) δ ( p , ℓ , ρ ) and δ ( p , ρ ) \delta(p,\rho) δ ( p , ρ ) , and we have shown that these are equivalent for any p p p given the premise. Therefore, S ⟦ D ⟧ ( ⊥ , ρ , δ ) = S ⟦ D ⟧ ( p , ρ , δ ) S\llbracket D \rrbracket(\bot,\rho,\delta) = S\llbracket D \rrbracket(p,\rho,\delta) S [ [ D ] ] ( ⊥ , ρ , δ ) = S [ [ D ] ] ( p , ρ , δ ) for any p p p and we are done. □
Lemma B.20 (Specialization, initial). If I ⟦ D ⟧ ( D 0 , ⊥ , ϱ , δ ) \mathcal{I}\llbracket D\rrbracket(D_0,\perp,\varrho,\delta) I [ [ D ] ] ( D 0 , ⊥ , ϱ , δ ) is well-defined, then for any p p p , we have I ⟦ D ⟧ ( D 0 , ⊥ , ϱ , δ ) = I ⟦ D ⟧ ( D 0 , p , ϱ , δ ) \mathcal{I}\llbracket D\rrbracket(D_0,\perp,\varrho,\delta)=\mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\delta) I [ [ D ] ] ( D 0 , ⊥ , ϱ , δ ) = I [ [ D ] ] ( D 0 , p , ϱ , δ ) .
Proof. Follows from an analogous argument to that presented for Lemma B.20 (successor-phase specialization). □
δ \delta δ -Elimination
Our final set of lemmas concerns substitution with respect to δ \delta δ , which we neglected before in our substitution lemmas. Since the δ \delta δ function always has two possible results, one of which is a variable, we can show that substituting the other result for that variable lets us simply remove the corresponding entry from δ \delta δ .
Lemma B.21 (Flag elimination, successor). If S ⟦ D ⟧ ( p , ϱ , δ , f l a g ↦ x ) \mathcal{S}\llbracket D\rrbracket(p,\varrho,\delta,\mathit{flag}\mapsto x) S [ [ D ] ] ( p , ϱ , δ , flag ↦ x ) is well-defined, then we have that S ⟦ D ⟧ ( p , ϱ , δ , f l a g ↦ x ) [ ϱ ( p ) / x ] = S ⟦ D ⟧ ( p , ϱ , δ ) [ ϱ ( p ) / x ] \mathcal{S}\llbracket D\rrbracket(p,\varrho,\delta,\mathit{flag}\mapsto x)[\varrho(p)/x]=\mathcal{S}\llbracket D\rrbracket(p,\varrho,\delta)[\varrho(p)/x] S [ [ D ] ] ( p , ϱ , δ , flag ↦ x ) [ ϱ ( p ) / x ] = S [ [ D ] ] ( p , ϱ , δ ) [ ϱ ( p ) / x ] .
Proof. Once again, this can be most formally shown by induction over the structure of D D D , but we here provide a direct argument instead.
Let δ ′ = δ , f l a g ↦ x \delta'=\delta,\mathit{flag}\mapsto x δ ′ = δ , flag ↦ x , and consider an arbitrary instance of δ ′ ( p , ϱ ) \delta'(p,\varrho) δ ′ ( p , ϱ ) in the translation result. By our premise, δ ′ ( p , ϱ ) \delta'(p,\varrho) δ ′ ( p , ϱ ) is well-defined, and then by definition, δ ′ ( p , ϱ ) = x \delta'(p,\varrho)=x δ ′ ( p , ϱ ) = x . Therefore, δ ′ ( p , ϱ ) [ ϱ ( p ) / x ] = ϱ ( p ) \delta'(p,\varrho)[\varrho(p)/x]=\varrho(p) δ ′ ( p , ϱ ) [ ϱ ( p ) / x ] = ϱ ( p ) . Now, by well-formedness of δ ′ \delta' δ ′ , we must have f l a g ∉ dom ( δ ) \mathit{flag}\notin\operatorname{dom}(\delta) flag ∈ / dom ( δ ) , i.e. δ ( p , ϱ ) = ϱ ( p ) \delta(p,\varrho)=\varrho(p) δ ( p , ϱ ) = ϱ ( p ) . Thus, δ ′ ( p , ϱ ) [ ϱ ( p ) / x ] = δ ( p , ϱ ) \delta'(p,\varrho)[\varrho(p)/x]=\delta(p,\varrho) δ ′ ( p , ϱ ) [ ϱ ( p ) / x ] = δ ( p , ϱ ) .
Choice of δ \delta δ versus δ ′ \delta' δ ′ only affects the translation result by occurrences of δ ( p , ϱ ) \delta(p,\varrho) δ ( p , ϱ ) , and we have shown that δ ′ ( p , ϱ ) [ ϱ ( p ) / x ] \delta'(p,\varrho)[\varrho(p)/x] δ ′ ( p , ϱ ) [ ϱ ( p ) / x ] is equivalent to δ ( p , ϱ ) \delta(p,\varrho) δ ( p , ϱ ) . Therefore, we conclude that S ⟦ D ⟧ ( p , ϱ , δ ′ ) [ ϱ ( p ) / x ] = S ⟦ D ⟧ ( p , ϱ , δ ) [ ϱ ( p ) / x ] \mathcal{S}\llbracket D\rrbracket(p,\varrho,\delta')[\varrho(p)/x]=\mathcal{S}\llbracket D\rrbracket(p,\varrho,\delta)[\varrho(p)/x] S [ [ D ] ] ( p , ϱ , δ ′ ) [ ϱ ( p ) / x ] = S [ [ D ] ] ( p , ϱ , δ ) [ ϱ ( p ) / x ] and we are done. □
The above argument applies to all other δ \delta δ -elimination lemmas, whose proofs we therefore elide.
Lemma B.22 (Flag elimination, initial). If I ⟦ D ⟧ ( D 0 , p , ϱ , δ , f l a g ↦ x ) \mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\delta,\mathit{flag}\mapsto x) I [ [ D ] ] ( D 0 , p , ϱ , δ , flag ↦ x ) is well-defined, then we have that I ⟦ D ⟧ ( D 0 , p , ϱ , δ , f l a g ↦ x ) [ ϱ ( p ) / x ] = I ⟦ D ⟧ ( D 0 , p , ϱ , δ ) [ ϱ ( p ) / x ] \mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\delta,\mathit{flag}\mapsto x)[\varrho(p)/x]=\mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\delta)[\varrho(p)/x] I [ [ D ] ] ( D 0 , p , ϱ , δ , flag ↦ x ) [ ϱ ( p ) / x ] = I [ [ D ] ] ( D 0 , p , ϱ , δ ) [ ϱ ( p ) / x ] .
Lemma B.23 (Label elimination, successor). If S ⟦ D ⟧ ( p , ϱ , δ , ℓ ↦ x ) \mathcal{S}\llbracket D\rrbracket(p,\varrho,\delta,\ell\mapsto x) S [ [ D ] ] ( p , ϱ , δ , ℓ ↦ x ) is well-defined, then we have that S ⟦ D ⟧ ( p , ϱ , δ , ℓ ↦ x ) [ ϱ ( p , ℓ ) / x ] = S ⟦ D ⟧ ( p , ϱ , δ ) [ ϱ ( p , ℓ ) / x ] \mathcal{S}\llbracket D\rrbracket(p,\varrho,\delta,\ell\mapsto x)[\varrho(p,\ell)/x]=\mathcal{S}\llbracket D\rrbracket(p,\varrho,\delta)[\varrho(p,\ell)/x] S [ [ D ] ] ( p , ϱ , δ , ℓ ↦ x ) [ ϱ ( p , ℓ ) / x ] = S [ [ D ] ] ( p , ϱ , δ ) [ ϱ ( p , ℓ ) / x ] .
Lemma B.24 (Label elimination, initial). If I ⟦ D ⟧ ( D 0 , p , ϱ , δ , ℓ ↦ x ) \mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\delta,\ell\mapsto x) I [ [ D ] ] ( D 0 , p , ϱ , δ , ℓ ↦ x ) is well-defined, then we have that I ⟦ D ⟧ ( D 0 , p , ϱ , δ , ℓ ↦ x ) [ ϱ ( p , ℓ ) / x ] = I ⟦ D ⟧ ( D 0 , p , ϱ , δ ) [ ϱ ( p , ℓ ) / x ] \mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\delta,\ell\mapsto x)[\varrho(p,\ell)/x]=\mathcal{I}\llbracket D\rrbracket(D_0,p,\varrho,\delta)[\varrho(p,\ell)/x] I [ [ D ] ] ( D 0 , p , ϱ , δ , ℓ ↦ x ) [ ϱ ( p , ℓ ) / x ] = I [ [ D ] ] ( D 0 , p , ϱ , δ ) [ ϱ ( p , ℓ ) / x ] .
Simulation
We state one final lemma about the target language:
Lemma B.25 (Let-transitivity). If σ ; M ⇝ + M ′ ; σ ′ \sigma;M\mathrel{\rightsquigarrow^{+}}M';\sigma' σ ; M ⇝ + M ′ ; σ ′ , then σ ; let x = M in N ⇝ + let x = M ′ in N ; σ ′ \sigma;\operatorname{let}\ x=M\ \operatorname{in}\ N\mathrel{\rightsquigarrow^{+}}\operatorname{let}\ x=M'\ \operatorname{in}\ N;\sigma' σ ; let x = M in N ⇝ + let x = M ′ in N ; σ ′ .
Proof. By induction on the length of the reduction sequence. For each intermediate step in the premise, we derive a corresponding step via EC-Let. □
As mentioned in § 8.4 , the proofs of simulation mirror those of λ h o o k r e a c t \lambda_{\mathrm{hook}}^{\mathrm{react}} λ hook react type preservation. The novel bits are typeset in blue.
Theorem B.26 (Simulation, pure computations). If
(i) Γ ; Π ; Φ H ; Φ M ⊢ H ; M : A ! P u r e \Gamma;\Pi;\Phi_H;\Phi_M\vdash\mathcal{H};M:A! \ \mathrm{Pure} Γ ; Π ; Φ H ; Φ M ⊢ H ; M : A ! Pure ,
(ii) Π ; ids ( M ) ∪ ids ( H ) ⊆ ϱ \Pi;\operatorname{ids}(M)\cup\operatorname{ids}(\mathcal{H})\subseteq\varrho Π ; ids ( M ) ∪ ids ( H ) ⊆ ϱ , and
(iii) H ; M ⇝ N ; H ′ \mathcal{H};M\mathrel{\rightsquigarrow}N;\mathcal{H}' H ; M ⇝ N ; H ′ ,
then
(i) Γ ; Π ; Φ M ⊢ N : A ! P u r e \Gamma;\Pi;\Phi_M\vdash N:A! \ \mathrm{Pure} Γ ; Π ; Φ M ⊢ N : A ! Pure ,
(ii) H ′ = H \mathcal{H}'=\mathcal{H} H ′ = H ,
(iii) Π \Pi Π ; ids ( N ) ∪ ids ( H ) ⊨ ϱ \operatorname{ids}(N) \cup\operatorname{ids}(\mathcal{H}) \models\varrho ids ( N ) ∪ ids ( H ) ⊨ ϱ , and
(iv) ⟦ H ⟧ ϱ ; ⟦ M ⟧ ϱ ⇝ + ⟦ N ⟧ ϱ ; ⟦ H ⟧ ϱ \llbracket\mathcal{H} \rrbracket_{\varrho};\llbracket M \rrbracket_{\varrho} \mathrel{\rightsquigarrow^{+}}\llbracket N \rrbracket_{\varrho};\llbracket\mathcal{H} \rrbracket_{\varrho} [ [ H ] ] ϱ ; [ [ M ] ] ϱ ⇝ + [ [ N ] ] ϱ ; [ [ H ] ] ϱ .
Proof. By definition of premise (i), we have subpremises
(i-a) Γ ; Π ; Φ M ⊢ M : A ! P u r e \Gamma;\Pi;\Phi_M \vdash M : A\ !\ \mathrm{Pure} Γ ; Π ; Φ M ⊢ M : A ! Pure and
(i-b) Γ ; Π ; Φ H ⊨ H \Gamma;\Pi;\Phi_{\mathcal{H}} \models\mathcal{H} Γ ; Π ; Φ H ⊨ H .
We begin with a few general observations:
By premise (ii), we have (ii-a) that Π ; ids ( M ) ⊨ ϱ \Pi;\operatorname{ids}(M) \models\varrho Π ; ids ( M ) ⊨ ϱ and (ii-b) that Π ; ids ( H ) ⊨ ϱ \Pi;\operatorname{ids}(\mathcal{H}) \models\varrho Π ; ids ( H ) ⊨ ϱ .
To show conclusion (iv) in any case, it is necessary to show (iv-a) that ⟦ H ⟧ ϱ \llbracket\mathcal{H} \rrbracket_{\varrho} [ [ H ] ] ϱ is well-defined and (iv-b) that ⟦ M ⟧ ϱ \llbracket M \rrbracket_{\varrho} [ [ M ] ] ϱ is well-defined:
We proceed by induction on the derivation of the computation step judgment (iii).
Case EC-Let: We have
H ; M ⇝ M ′ ; H ′ ( 1 ) H ; let x = M in N ⇝ let x = M ′ in N ; H ′ E C - L e t \frac{
\frac{\mathcal{H};M \rightsquigarrow M';\mathcal{H}'}{(1)}
}{
\mathcal{H};\operatorname{let} x=M\operatorname{in}N \rightsquigarrow\operatorname{let} x=M'\operatorname{in}N;\mathcal{H}'
}
\quad\mathrm{EC\text{-}Let} H ; let x = M in N ⇝ let x = M ′ in N ; H ′ ( 1 ) H ; M ⇝ M ′ ; H ′ EC - Let
Γ ; Π ; Φ 1 ⊢ M : A ! P u r e Γ , x : A ; Π ; Φ 2 ⊢ N : B ! P u r e Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in N : B ! P u r e T C - L e t \frac{
\Gamma;\Pi;\Phi_1 \vdash M:A\ !\ \mathrm{Pure}
\qquad
\Gamma,x:A;\Pi;\Phi_2 \vdash N:B\ !\ \mathrm{Pure}
}{
\Gamma;\Pi;\Phi_1 \bowtie\Phi_2 \vdash\operatorname{let} x=M\operatorname{in}N:B\ !\ \mathrm{Pure}
}
\quad\mathrm{TC\text{-}Let} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in N : B ! Pure Γ ; Π ; Φ 1 ⊢ M : A ! Pure Γ , x : A ; Π ; Φ 2 ⊢ N : B ! Pure TC - Let
By premise (ii) and definition, we have (5) that Π ; ids ( M ) ∪ ids ( H ) ⊨ ϱ \Pi;\operatorname{ids}(M) \cup\operatorname{ids}(\mathcal{H}) \models\varrho Π ; ids ( M ) ∪ ids ( H ) ⊨ ϱ and (6) that Π ; ids ( N ) ∪ ids ( H ) ⊨ ϱ \Pi;\operatorname{ids}(N) \cup\operatorname{ids}(\mathcal{H}) \models\varrho Π ; ids ( N ) ∪ ids ( H ) ⊨ ϱ .
By inductive hypothesis on (1), (2), and premise (i-b), we get (7) Γ ; Π ; Φ 1 ⊢ M ′ : A ! P u r e \Gamma;\Pi;\Phi_1 \vdash M':A\ !\ \mathrm{Pure} Γ ; Π ; Φ 1 ⊢ M ′ : A ! Pure , (8) H ′ = H \mathcal{H}'=\mathcal{H} H ′ = H , satisfying conclusion (ii), (9) Π ; ids ( M ′ ) ∪ ids ( H ′ ) ⊨ ϱ \Pi;\operatorname{ids}(M') \cup\operatorname{ids}(\mathcal{H}') \models\varrho Π ; ids ( M ′ ) ∪ ids ( H ′ ) ⊨ ϱ , and (10) ⟦ H ⟧ ϱ ; ⟦ M ⟧ ϱ ⇝ + ⟦ M ′ ⟧ ϱ ; ⟦ H ⟧ ϱ \llbracket\mathcal{H} \rrbracket_{\varrho};\llbracket M \rrbracket_{\varrho} \mathrel{\rightsquigarrow^{+}}\llbracket M' \rrbracket_{\varrho};\llbracket\mathcal{H} \rrbracket_{\varrho} [ [ H ] ] ϱ ; [ [ M ] ] ϱ ⇝ + [ [ M ′ ] ] ϱ ; [ [ H ] ] ϱ .
By (5) and (8), we get Π ; ids ( M ′ ) ∪ ids ( N ) ∪ ids ( H ) ⊨ ϱ \Pi;\operatorname{ids}(M') \cup\operatorname{ids}(N) \cup\operatorname{ids}(\mathcal{H}) \models\varrho Π ; ids ( M ′ ) ∪ ids ( N ) ∪ ids ( H ) ⊨ ϱ , satisfying conclusion (iii).
We derive conclusion (i) as follows:
Γ ; Π ; Φ 1 ⊢ M ′ : A ! P u r e Γ , x : A ; Π ; Φ 2 ⊢ N : B ! P u r e Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M ′ in N : B ! P u r e T C - L e t \frac{
\Gamma;\Pi;\Phi_1 \vdash M':A\ !\ \mathrm{Pure}
\qquad
\Gamma,x:A;\Pi;\Phi_2 \vdash N:B\ !\ \mathrm{Pure}
}{
\Gamma;\Pi;\Phi_1 \bowtie\Phi_2 \vdash\operatorname{let} x=M'\operatorname{in}N:B\ !\ \mathrm{Pure}
}
\quad\mathrm{TC\text{-}Let} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M ′ in N : B ! Pure Γ ; Π ; Φ 1 ⊢ M ′ : A ! Pure Γ , x : A ; Π ; Φ 2 ⊢ N : B ! Pure TC - Let
⟦ H ⟧ ϱ ; ⟦ let x = M in N ⟧ ϱ = (def. of translation) let x = ⟦ M ⟧ ϱ in ⟦ N ⟧ ϱ ; ⟦ H ⟧ ϱ = (xref‘Lemma B.25‘, let-transitivity on (10)) let x = ⟦ M ′ ⟧ ϱ in ⟦ N ⟧ ϱ ; ⟦ H ⟧ ϱ = (def. of translation) ⟦ let x = M ′ in N ⟧ ϱ ; ⟦ H ⟧ ϱ \begin{aligned}
\llbracket\mathcal{H} \rrbracket_{\varrho};\llbracket\operatorname{let} x=M\operatorname{in}N \rrbracket_{\varrho}
&\qquad\\
&\overset{\text{(def. of translation)}}{=}
\operatorname{let} x=\llbracket M \rrbracket_{\varrho}\operatorname{in}\llbracket N \rrbracket_{\varrho};\llbracket\mathcal{H} \rrbracket_{\varrho}\\
&\overset{\text{({xref}`Lemma B.25`, let-transitivity on (10))}}{=}
\operatorname{let} x=\llbracket M' \rrbracket_{\varrho}\operatorname{in}\llbracket N \rrbracket_{\varrho};\llbracket\mathcal{H} \rrbracket_{\varrho}\\
&\overset{\text{(def. of translation)}}{=}
\llbracket\operatorname{let} x=M'\operatorname{in}N \rrbracket_{\varrho};\llbracket\mathcal{H} \rrbracket_{\varrho}
\end{aligned} [ [ H ] ] ϱ ; [ [ let x = M in N ] ] ϱ = (def. of translation) let x = [ [ M ] ] ϱ in [ [ N ] ] ϱ ; [ [ H ] ] ϱ = ( xref ‘Lemma B.25‘, let-transitivity on (10)) let x = [ [ M ′ ] ] ϱ in [ [ N ] ] ϱ ; [ [ H ] ] ϱ = (def. of translation) [ [ let x = M ′ in N ] ] ϱ ; [ [ H ] ] ϱ
Case EC-Val: We have H \mathcal{H} H ; let x = val V x = \operatorname{val} V x = val V in M ⇝ M [ V / x ] M \rightsquigarrow M[V/x] M ⇝ M [ V / x ] ; H \mathcal{H} H (from which conclusion ( i i ) (ii) ( ii ) is immediate) and
Γ ; Π ; Φ 1 ⊢ V : A Γ ; Π ; Φ 1 ⊢ val V : A ! P u r e E C - V a l Γ , x : A ; Π ; Φ 2 ⊢ M : B ! P u r e Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = val V in M : B ! P u r e E C - L e t \begin{aligned}
&\frac{\Gamma; \Pi; \Phi_1 \vdash V : A}{\Gamma; \Pi; \Phi_1 \vdash\operatorname{val} V : A\ !\ \mathrm{Pure}}\ \mathrm{EC\text{-}Val}
\qquad
\frac{\Gamma, x : A ; \Pi; \Phi_2 \vdash M : B\ !\ \mathrm{Pure}}{\Gamma; \Pi; \Phi_1 \mathbin{\bowtie} \Phi_2 \vdash\operatorname{let}\ x = \operatorname{val} V\ \operatorname{in}\ M : B\ !\ \mathrm{Pure}}\ \mathrm{EC\text{-}Let}
\end{aligned} Γ ; Π ; Φ 1 ⊢ val V : A ! Pure Γ ; Π ; Φ 1 ⊢ V : A EC - Val Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = val V in M : B ! Pure Γ , x : A ; Π ; Φ 2 ⊢ M : B ! Pure EC - Let
Conclusion ( i ) (i) ( i ) is given by Lemma A.19 (type substitution) on (1) and (2).
Conclusion ( i i i ) (iii) ( iii ) is given by premise ( i i ) (ii) ( ii ) and the fact that ids ( M [ V / x ] ) ⊆ ids ( M ) ∪ ids ( V ) \operatorname{ids}(M[V/x]) \subseteq\operatorname{ids}(M) \cup\operatorname{ids}(V) ids ( M [ V / x ]) ⊆ ids ( M ) ∪ ids ( V ) .
We show conclusion ( i v ) (iv) ( i v ) as follows:
⟦ H ⟧ ϱ ; ⟦ let x = val V in M ⟧ ϱ = (def. of translation) = let x = val ⟦ V ⟧ ϱ in ⟦ M ⟧ ϱ ; ⟦ H ⟧ ϱ = (EC-App) ⇝ ⟦ M ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] ; ⟦ H ⟧ ϱ = (xref‘Lemma B.11‘, substitution) = ⟦ M [ V / x ] ⟧ ϱ ; ⟦ H ⟧ ϱ \begin{aligned}
\llbracket\mathcal{H}\rrbracket_{\varrho}\ ;\ \llbracket\operatorname{let}\ x = \operatorname{val}\ V\ \operatorname{in}\ M\rrbracket_{\varrho}\\
\mathrel{\phantom{=}} \text{(def. of translation)} = \operatorname{let}\ x = \operatorname{val}\ \llbracket V\rrbracket_{\varrho}\ \operatorname{in}\ \llbracket M\rrbracket_{\varrho}\ ;\ \llbracket\mathcal{H}\rrbracket_{\varrho}\\
\mathrel{\phantom{=}} \text{(EC-App)} \rightsquigarrow\llbracket M\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]\ ;\ \llbracket\mathcal{H}\rrbracket_{\varrho}\\
\mathrel{\phantom{=}} \text{({xref}`Lemma B.11`, substitution)} = \llbracket M[V/x]\rrbracket_{\varrho}\ ;\ \llbracket\mathcal{H}\rrbracket_{\varrho}
\end{aligned} [ [ H ] ] ϱ ; [ [ let x = val V in M ] ] ϱ = (def. of translation) = let x = val [ [ V ] ] ϱ in [ [ M ] ] ϱ ; [ [ H ] ] ϱ = (EC-App) ⇝ [ [ M ] ] ϱ [ [ [ V ] ] ϱ / x ] ; [ [ H ] ] ϱ = ( xref ‘Lemma B.11‘, substitution) = [ [ M [ V / x ] ] ] ϱ ; [ [ H ] ] ϱ
Case EC-App: We have H \mathcal{H} H ; ( λ x . M ) V ⇝ M [ V / x ] (\lambda x.M)\ V \rightsquigarrow M[V/x] ( λ x . M ) V ⇝ M [ V / x ] ; H \mathcal{H} H (from which conclusion ( i i ) (ii) ( ii ) is immediate) and
Γ , x : A ; Π ; Φ 1 ⊢ M : B ! P u r e Succ ( Φ 1 ) Γ ; Π ; Φ 1 ⊢ λ x . M : A → P u r e B T V - L a m ( 1 ) Γ ; Π ; Φ 2 ⊢ V : A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( λ x . M ) V : B ! P u r e T C - A p p ( 2 ) \begin{aligned}
&\frac{\Gamma, x : A ; \Pi; \Phi_1 \vdash M : B\ !\ \mathrm{Pure}\quad\operatorname{Succ}(\Phi_1)}{\Gamma; \Pi; \Phi_1 \vdash\lambda x.M : A \mathrel{\xrightarrow{\mathrm{Pure}}} B}\ \mathrm{TV\text{-}Lam}\ (1)
\qquad
\frac{\Gamma; \Pi; \Phi_2 \vdash V : A}{\Gamma; \Pi; \Phi_1 \mathbin{\bowtie} \Phi_2 \vdash(\lambda x.M)\ V : B\ !\ \mathrm{Pure}}\ \mathrm{TC\text{-}App}\ (2)
\end{aligned} Γ ; Π ; Φ 1 ⊢ λ x . M : A Pure B Γ , x : A ; Π ; Φ 1 ⊢ M : B ! Pure Succ ( Φ 1 ) TV - Lam ( 1 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( λ x . M ) V : B ! Pure Γ ; Π ; Φ 2 ⊢ V : A TC - App ( 2 )
Conclusion ( i ) (i) ( i ) is given by Lemma A.19 (type substitution) on (1) and (2), noting Φ ⋈ ∅ = Φ \Phi\mathbin{\bowtie} \varnothing= \Phi Φ ⋈ ∅ = Φ .
Conclusion ( i i i ) (iii) ( iii ) is given by premise ( i i ) (ii) ( ii ) and the fact that ids ( M [ V / x ] ) ⊆ ids ( M ) ∪ ids ( V ) \operatorname{ids}(M[V/x]) \subseteq\operatorname{ids}(M) \cup\operatorname{ids}(V) ids ( M [ V / x ]) ⊆ ids ( M ) ∪ ids ( V ) .
We show conclusion ( i v ) (iv) ( i v ) as follows:
⟦ H ⟧ ϱ ; ⟦ ( λ x . M ) V ⟧ ϱ = (def. of translation) = ( λ x . ⟦ M ⟧ ϱ ) ⟦ V ⟧ ϱ ; ⟦ H ⟧ ϱ = (EC-App) ⇝ ⟦ M ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] ; ⟦ H ⟧ ϱ = (xref‘Lemma B.11‘, substitution) = ⟦ M [ V / x ] ⟧ ϱ ; ⟦ H ⟧ ϱ \begin{aligned}
\llbracket\mathcal{H}\rrbracket_{\varrho}\ ;\ \llbracket(\lambda x.M)\ V\rrbracket_{\varrho}\\
\mathrel{\phantom{=}} \text{(def. of translation)} = (\lambda x.\llbracket M\rrbracket_{\varrho})\ \llbracket V\rrbracket_{\varrho}\ ;\ \llbracket\mathcal{H}\rrbracket_{\varrho}\\
\mathrel{\phantom{=}} \text{(EC-App)} \rightsquigarrow\llbracket M\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]\ ;\ \llbracket\mathcal{H}\rrbracket_{\varrho}\\
\mathrel{\phantom{=}} \text{({xref}`Lemma B.11`, substitution)} = \llbracket M[V/x]\rrbracket_{\varrho}\ ;\ \llbracket\mathcal{H}\rrbracket_{\varrho}
\end{aligned} [ [ H ] ] ϱ ; [ [ ( λ x . M ) V ] ] ϱ = (def. of translation) = ( λ x . [ [ M ] ] ϱ ) [ [ V ] ] ϱ ; [ [ H ] ] ϱ = (EC-App) ⇝ [ [ M ] ] ϱ [ [ [ V ] ] ϱ / x ] ; [ [ H ] ] ϱ = ( xref ‘Lemma B.11‘, substitution) = [ [ M [ V / x ] ] ] ϱ ; [ [ H ] ] ϱ
Case EC-IfT: We have H \mathcal{H} H ; if true then M M M else N ⇝ M N \rightsquigarrow M N ⇝ M ; H \mathcal{H} H (from which conclusion ( i i ) (ii) ( ii ) is immediate) and
Γ ; Π ; Φ 1 ⊢ t r u e : B o o l Γ ; Π ; Φ 1 ⊢ t r u e : B o o l T V - T r u e Γ ; Π ; Φ 2 ⊢ M : A ! P u r e Γ ; Π ; Φ 2 ⊢ N : A ! P u r e Γ ; Π ; Φ ⊢ i f t r u e t h e n M e l s e N : A ! P u r e T C - I f \frac{\Gamma; \Pi; \Phi_1 \vdash\mathrm{true} : \mathrm{Bool}}{\Gamma; \Pi; \Phi_1 \vdash\mathrm{true} : \mathrm{Bool}}\ \mathrm{TV\text{-}True}
\qquad
\frac{\Gamma; \Pi; \Phi_2 \vdash M : A\ !\ \mathrm{Pure}\qquad\Gamma; \Pi; \Phi_2 \vdash N : A\ !\ \mathrm{Pure}}{\Gamma; \Pi; \Phi\vdash\mathrm{if\ true\ then}\ M\ \mathrm{else}\ N : A\ !\ \mathrm{Pure}}\ \mathrm{TC\text{-}If} Γ ; Π ; Φ 1 ⊢ true : Bool Γ ; Π ; Φ 1 ⊢ true : Bool TV - True Γ ; Π ; Φ ⊢ if true then M else N : A ! Pure Γ ; Π ; Φ 2 ⊢ M : A ! Pure Γ ; Π ; Φ 2 ⊢ N : A ! Pure TC - If
Conclusion ( i ) (i) ( i ) is given by Lemma A.10 (Φ \Phi Φ -weakening) on (2) using (1).
By premise ( i i ) (ii) ( ii ) , we have Π ; ids ( M ) ∪ ids ( H ) ⊨ ϱ \Pi; \operatorname{ids}(M) \cup\operatorname{ids}(\mathcal{H}) \models\varrho Π ; ids ( M ) ∪ ids ( H ) ⊨ ϱ , which satisfies conclusion ( i i i ) (iii) ( iii ) .
⟦ H ⟧ ϱ ; ⟦ if true then M else N ⟧ ϱ \llbracket\mathcal{H} \rrbracket_{\varrho};\llbracket\text{if true then }M\text{ else }N\rrbracket_{\varrho} [ [ H ] ] ϱ ; [ [ if true then M else N ] ] ϱ
(def. of translation) = if true then ⟦ M ⟧ ϱ else ⟦ N ⟧ ϱ ; ⟦ H ⟧ ϱ \text{(def. of translation)} = \text{if true then }\llbracket M\rrbracket_{\varrho}\text{ else }\llbracket N\rrbracket_{\varrho};\llbracket\mathcal{H}\rrbracket_{\varrho} (def. of translation) = if true then [ [ M ] ] ϱ else [ [ N ] ] ϱ ; [ [ H ] ] ϱ
(EC-IfT) ⇝ ⟦ M ⟧ ϱ ; ⟦ H ⟧ ϱ \text{(EC-IfT)} \quad\leadsto\quad\llbracket M\rrbracket_{\varrho};\llbracket\mathcal{H}\rrbracket_{\varrho} (EC-IfT) ⇝ [ [ M ] ] ϱ ; [ [ H ] ] ϱ
Case EC-IfF: Analogous to the above case.
Case EC-Fst: We have H ; fst ( V , W ) ⇝ val V ; H \mathcal{H};\operatorname{fst}(V,W)\leadsto\operatorname{val}V;\mathcal{H} H ; fst ( V , W ) ⇝ val V ; H (from which conclusion ( i i ) (ii) ( ii ) is immediate) and
Γ ; Π ; Φ 1 ⊢ V : A Γ ; Π ; Φ 2 ⊢ W : B Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B TV-Pair Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ fst ( V , W ) : A ! Pure TC-Fst \frac{\frac{\Gamma;\Pi;\Phi_1\vdash V:A\qquad\Gamma;\Pi;\Phi_2\vdash W:B}{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash(V,W):A\times B}\ \text{TV-Pair}}{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash\operatorname{fst}(V,W):A\mathbin{!}\operatorname{Pure}}\ \text{TC-Fst} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ fst ( V , W ) : A ! Pure Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B Γ ; Π ; Φ 1 ⊢ V : A Γ ; Π ; Φ 2 ⊢ W : B TV-Pair TC-Fst
By Lemma A.4 (unrestriction) on (2), we get (3) that Succ ( Φ 2 ) \operatorname{Succ}(\Phi_2) Succ ( Φ 2 ) .
By Lemma A.9 (Φ \Phi Φ -weakening) on (1) and (3), we get (4) that Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : A \Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash V:A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : A .
We derive conclusion ( i ) (i) ( i ) as follows:
∅ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : A ( 4 ) ∅ ; Π ; Φ 1 ⋈ Φ 2 ⊢ val V : A ! Pure TC-Val \frac{\frac{}{\,\varnothing;\Pi;\Phi_1\bowtie\Phi_2\vdash V:A\,}\ (4)}{\varnothing;\Pi;\Phi_1\bowtie\Phi_2\vdash\operatorname{val}V:A\mathbin{!}\operatorname{Pure}}\ \text{TC-Val} ∅ ; Π ; Φ 1 ⋈ Φ 2 ⊢ val V : A ! Pure ∅ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : A ( 4 ) TC-Val
By premise ( i i ) (ii) ( ii ) , we have Π ; ids ( V ) ∪ ids ( H ) ⊨ ϱ \Pi;\operatorname{ids}(V)\cup\operatorname{ids}(\mathcal{H})\models\varrho Π ; ids ( V ) ∪ ids ( H ) ⊨ ϱ , which satisfies conclusion ( i i i ) (iii) ( iii ) .
We show conclusion ( i v ) (iv) ( i v ) as follows:
⟦ H ⟧ ϱ ; ⟦ fst ( V , W ) ⟧ ϱ \llbracket\mathcal{H}\rrbracket_{\varrho};\llbracket\operatorname{fst}(V,W)\rrbracket_{\varrho} [ [ H ] ] ϱ ; [ [ fst ( V , W ) ] ] ϱ
(def. of translation) = fst ( ⟦ V ⟧ ϱ , ⟦ W ⟧ ϱ ) ; ⟦ H ⟧ ϱ \text{(def. of translation)} = \operatorname{fst}(\llbracket V\rrbracket_{\varrho},\llbracket W\rrbracket_{\varrho});\llbracket\mathcal{H}\rrbracket_{\varrho} (def. of translation) = fst ( [ [ V ] ] ϱ , [ [ W ] ] ϱ ) ; [ [ H ] ] ϱ
(EC-Fst) ⇝ val ⟦ V ⟧ ϱ ; ⟦ H ⟧ ϱ \text{(EC-Fst)} \quad\leadsto\quad\operatorname{val}\llbracket V\rrbracket_{\varrho};\llbracket\mathcal{H}\rrbracket_{\varrho} (EC-Fst) ⇝ val [ [ V ] ] ϱ ; [ [ H ] ] ϱ
(def. of translation) = ⟦ val V ⟧ ϱ ; ⟦ H ⟧ ϱ \text{(def. of translation)} = \llbracket\operatorname{val}V\rrbracket_{\varrho};\llbracket\mathcal{H}\rrbracket_{\varrho} (def. of translation) = [ [ val V ] ] ϱ ; [ [ H ] ] ϱ
Case EC-Snd: Analogous to the above case.
Case EC-FdN: We have H ; fold V 1 V 2 [ ] ⇝ val V 2 ; H \mathcal{H};\operatorname{fold}V_1\ V_2\ [\,]\leadsto\operatorname{val}V_2;\mathcal{H} H ; fold V 1 V 2 [ ] ⇝ val V 2 ; H (from which conclusion ( i i ) (ii) ( ii ) is immediate) and
\frac{\frac{\Gamma;\Pi;\Phi_1\vdash V_1:A\ \xrightarrow{\mathbin{!}\operatorname{Pure}}\ B\ \xrightarrow{\mathbin{!}\operatorname{Pure}}\ B\qquad\Gamma;\Pi;\Phi_2\vdash V_2:B\qquad\Gamma;\Pi;\Phi_3\vdash[\,]:\operatorname{List}A}{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\bowtie\Phi_3\vdash\operatorname{fold}V_1\ V_2\ [\,]:B\mathbin{!}\operatorname{Pure}}\ \text{TC-Fold}}
By Lemma A.4 (unrestriction) on (1) and (3), we get (4) that Succ ( Φ 1 ) \operatorname{Succ}(\Phi_1) Succ ( Φ 1 ) and (5) that Succ ( Φ 3 ) \operatorname{Succ}(\Phi_3) Succ ( Φ 3 ) , respectively.
By Lemma A.9 (Φ \Phi Φ -weakening) on (2) using (4) and (5), we get (6) that Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ V 2 : B \Gamma;\Pi;\Phi_1\bowtie\Phi_2\bowtie\Phi_3\vdash V_2:B Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ V 2 : B .
We derive conclusion ( i ) (i) ( i ) as follows:
\frac{\frac{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\bowtie\Phi_3\vdash V_2:B}{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\bowtie\Phi_3\vdash\operatorname{val}V_2:B\mathbin{!}\operatorname{Pure}}\ \text{TC-Val}}
By premise (ii), we have Π \Pi Π ; ids ( V 2 ) ∪ ids ( H ) ⊨ ϱ \operatorname{ids}(V_2) \cup\operatorname{ids}(\mathcal{H}) \models\varrho ids ( V 2 ) ∪ ids ( H ) ⊨ ϱ , which satisfies conclusion (iii).
We show conclusion (iv) as follows:
⟦ H ⟧ ϱ ; ⟦ fold V 1 V 2 [ ] ⟧ ϱ (def. of translation) = fold ⟦ V 1 ⟧ ϱ ⟦ V 2 ⟧ ϱ [ ] ; ⟦ H ⟧ ϱ (EC-FdN) ⇝ val ⟦ V 2 ⟧ ϱ ; ⟦ H ⟧ ϱ (def. of translation) = ⟦ val V 2 ⟧ ϱ ; ⟦ H ⟧ ϱ \begin{aligned}
\llbracket\mathcal{H} \rrbracket_{\varrho} \mathbin{;} \llbracket\operatorname{fold}\ V_1\ V_2\ [] \rrbracket_{\varrho}\\
\text{(def. of translation)} \quad= \operatorname{fold}\ \llbracket V_1 \rrbracket_{\varrho}\ \llbracket V_2 \rrbracket_{\varrho}\ [] \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho}\\
\text{(EC-FdN)} \quad\rightsquigarrow\operatorname{val}\ \llbracket V_2 \rrbracket_{\varrho} \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho}\\
\text{(def. of translation)} \quad= \llbracket\operatorname{val}\ V_2 \rrbracket_{\varrho} \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho}
\end{aligned} [ [ H ] ] ϱ ; [ [ fold V 1 V 2 [ ] ] ] ϱ (def. of translation) = fold [ [ V 1 ] ] ϱ [ [ V 2 ] ] ϱ [ ] ; [ [ H ] ] ϱ (EC-FdN) ⇝ val [ [ V 2 ] ] ϱ ; [ [ H ] ] ϱ (def. of translation) = [ [ val V 2 ] ] ϱ ; [ [ H ] ] ϱ
Case EC-FdC: We have H ; fold V 1 V 2 ( V h : : V t ) ⇝ V 1 V h ( fold V 1 V 2 V t ) ; H \mathcal{H} \mathbin{;} \operatorname{fold}\ V_1\ V_2\ (V_h :: V_t) \rightsquigarrow V_1\ V_h\ (\operatorname{fold}\ V_1\ V_2\ V_t) \mathbin{;} \mathcal{H} H ; fold V 1 V 2 ( V h :: V t ) ⇝ V 1 V h ( fold V 1 V 2 V t ) ; H , whose right-hand term desugars to let x = V 1 V h in let y = fold V 1 V 2 V t in x y \operatorname{let}\ x = V_1\ V_h\ \operatorname{in}\ \operatorname{let}\ y = \operatorname{fold}\ V_1\ V_2\ V_t\ \operatorname{in}\ x\ y let x = V 1 V h in let y = fold V 1 V 2 V t in x y . Conclusion (ii) is immediate, and we also have:
Γ ; Π ; Φ 3 ⊢ V h : A Γ ; Π ; Φ 3 ⋈ Φ 4 ⊢ V h : : V t : List A Γ ; Π ; Φ 4 ⊢ V t : List A Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⋈ Φ 4 ⊢ fold V 1 V 2 ( V h : : V t ) : B ! Pure TC-FOLD \frac{
\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_3 \vdash V_h : A}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_3 \mathbin{\bowtie} \Phi_4 \vdash V_h :: V_t : \operatorname{List}\ A}
\qquad
\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_4 \vdash V_t : \operatorname{List}\ A}{}
}{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \mathbin{\bowtie} \Phi_2 \mathbin{\bowtie} \Phi_3 \mathbin{\bowtie} \Phi_4 \vdash\operatorname{fold}\ V_1\ V_2\ (V_h :: V_t) : B\ {!}\ \operatorname{Pure}
}
\quad\text{TC-FOLD} Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⋈ Φ 4 ⊢ fold V 1 V 2 ( V h :: V t ) : B ! Pure Γ ; Π ; Φ 3 ⋈ Φ 4 ⊢ V h :: V t : List A Γ ; Π ; Φ 3 ⊢ V h : A Γ ; Π ; Φ 4 ⊢ V t : List A TC-FOLD
where (1) and (2) are identical to the previous case.
By Lemma A.4 (unrestriction) on (1)–(4), we get that Succ ( Φ i ) \operatorname{Succ}(\Phi_i) Succ ( Φ i ) for i ∈ { 1 , 2 , 3 , 4 } i \in\{1, 2, 3, 4\} i ∈ { 1 , 2 , 3 , 4 } . It follows (5) that Succ ( Φ ) \operatorname{Succ}(\Phi) Succ ( Φ ) , where Φ = ⋈ i = 1 4 Φ i \Phi= \mathbin{\bowtie}_{i=1}^{4} \Phi_i Φ = ⋈ i = 1 4 Φ i .
We derive conclusion (i) by way of intermediate derivations (6)–(8) as follows, using Φ \Phi Φ intuitionistically by (5) and weakening (1)–(4) appropriately:
Γ 6 ; Π ; Φ ⊢ x : B Γ 6 ; Π ; Φ ⊢ y : B Γ 6 ; Π ; Φ ⊢ x y : B ! Pure TC-App \frac{
\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi\vdash x : B
\qquad
\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi\vdash y : B
}{
\Gamma_6 \mathbin{;} \Pi\mathbin{;} \Phi\vdash x\ y : B\ {!}\ \operatorname{Pure}
}
\quad\text{TC-App} Γ 6 ; Π ; Φ ⊢ x y : B ! Pure Γ 6 ; Π ; Φ ⊢ x : B Γ 6 ; Π ; Φ ⊢ y : B TC-App
Γ 7 ; Π ; Φ ⊢ V 1 : A → Pure B → Pure B Γ 7 ; Π ; Φ ⊢ V 2 : B Γ 7 ; Π ; Φ ⊢ V t : List A Γ 7 ; Π ; Φ ⊢ fold V 1 V 2 V t : B ! Pure TC-FOLD \frac{
\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi\vdash V_1 : A \xrightarrow{\operatorname{Pure}} B \xrightarrow{\operatorname{Pure}} B
\qquad
\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi\vdash V_2 : B
\qquad
\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi\vdash V_t : \operatorname{List}\ A
}{
\Gamma_7 \mathbin{;} \Pi\mathbin{;} \Phi\vdash\operatorname{fold}\ V_1\ V_2\ V_t : B\ {!}\ \operatorname{Pure}
}
\quad\text{TC-FOLD} Γ 7 ; Π ; Φ ⊢ fold V 1 V 2 V t : B ! Pure Γ 7 ; Π ; Φ ⊢ V 1 : A Pure B Pure B Γ 7 ; Π ; Φ ⊢ V 2 : B Γ 7 ; Π ; Φ ⊢ V t : List A TC-FOLD
[ ( 7 ) , Γ 7 = Γ 8 ] [ ( 6 ) , Γ 6 = Γ 8 , y : B ] Γ 8 ; Π ; Φ ⊢ let y = fold V 1 V 2 V t in ⋯ : B ! Pure TC-Let \frac{
\left[(7),\ \Gamma_7 = \Gamma_8\right]
\qquad
\left[(6),\ \Gamma_6 = \Gamma_8,\ y : B\right]
}{
\Gamma_8 \mathbin{;} \Pi\mathbin{;} \Phi\vdash\operatorname{let}\ y = \operatorname{fold}\ V_1\ V_2\ V_t\ \operatorname{in}\ \cdots: B\ {!}\ \operatorname{Pure}
}
\quad\text{TC-Let} Γ 8 ; Π ; Φ ⊢ let y = fold V 1 V 2 V t in ⋯ : B ! Pure [ ( 7 ) , Γ 7 = Γ 8 ] [ ( 6 ) , Γ 6 = Γ 8 , y : B ] TC-Let
Γ ; Π ; Φ ⊢ V 1 : A → Pure B → Pure E Γ ; Π ; Φ ⊢ V h : A Γ ; Π ; Φ ⊢ V 1 V h : B → Pure B ! Pure TC-App \frac{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash V_1 : A \xrightarrow{\operatorname{Pure}} B \xrightarrow{\operatorname{Pure}} E
\qquad
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash V_h : A
}{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash V_1\ V_h : B \xrightarrow{\operatorname{Pure}} B\ {!}\ \operatorname{Pure}
}
\quad\text{TC-App} Γ ; Π ; Φ ⊢ V 1 V h : B Pure B ! Pure Γ ; Π ; Φ ⊢ V 1 : A Pure B Pure E Γ ; Π ; Φ ⊢ V h : A TC-App
[ ( 8 ) , Γ 8 = Γ , x : B → Pure B ] Γ ; Π ; Φ ⊢ let x = V 1 V h in ⋯ : B ! Pure TC-Let \frac{
\left[(8),\ \Gamma_8 = \Gamma,\ x : B \xrightarrow{\operatorname{Pure}} B\right]
}{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi\vdash\operatorname{let}\ x = V_1\ V_h\ \operatorname{in}\ \cdots: B\ {!}\ \operatorname{Pure}
}
\quad\text{TC-Let} Γ ; Π ; Φ ⊢ let x = V 1 V h in ⋯ : B ! Pure [ ( 8 ) , Γ 8 = Γ , x : B Pure B ] TC-Let
By premise (ii), we have Π \Pi Π ; ids ( V 1 ) ∪ ids ( V 2 ) ∪ ids ( V h ) ∪ ids ( V t ) ∪ ids ( H ) ⊨ ϱ \operatorname{ids}(V_1) \cup\operatorname{ids}(V_2) \cup\operatorname{ids}(V_h) \cup\operatorname{ids}(V_t) \cup\operatorname{ids}(\mathcal{H}) \models\varrho ids ( V 1 ) ∪ ids ( V 2 ) ∪ ids ( V h ) ∪ ids ( V t ) ∪ ids ( H ) ⊨ ϱ , which satisfies conclusion (iii).
⟦ H ⟧ ϱ ; ⟦ fold V 1 V 2 ( V h : : V t ) ⟧ ϱ \llbracket H\rrbracket_{\varrho}\ ;\ \llbracket\operatorname{fold}\ V_1\ V_2\ (V_h :: V_t)\rrbracket_{\varrho} [ [ H ] ] ϱ ; [ [ fold V 1 V 2 ( V h :: V t ) ] ] ϱ
(def. of translation) = = = fold ⟦ V 1 ⟧ ϱ ⟦ V 2 ⟧ ϱ ( ⟦ V h ⟧ ϱ : : ⟦ V t ⟧ ϱ ) ; ⟦ H ⟧ ϱ \operatorname{fold}\ \llbracket V_1\rrbracket_{\varrho}\ \llbracket V_2\rrbracket_{\varrho}\ (\llbracket V_h\rrbracket_{\varrho} :: \llbracket V_t\rrbracket_{\varrho})\ ;\ \llbracket H\rrbracket_{\varrho} fold [ [ V 1 ] ] ϱ [ [ V 2 ] ] ϱ ( [ [ V h ] ] ϱ :: [ [ V t ] ] ϱ ) ; [ [ H ] ] ϱ
(EC-FdC) ⇝ \leadsto ⇝ ⟦ V 1 ⟧ ϱ ⟦ V h ⟧ ϱ ( fold ⟦ V 1 ⟧ ϱ ⟦ V 2 ⟧ ϱ ⟦ V t ⟧ ϱ ) ; ⟦ H ⟧ ϱ \llbracket V_1\rrbracket_{\varrho}\ \llbracket V_h\rrbracket_{\varrho}\ (\operatorname{fold}\ \llbracket V_1\rrbracket_{\varrho}\ \llbracket V_2\rrbracket_{\varrho}\ \llbracket V_t\rrbracket_{\varrho})\ ;\ \llbracket H\rrbracket_{\varrho} [ [ V 1 ] ] ϱ [ [ V h ] ] ϱ ( fold [ [ V 1 ] ] ϱ [ [ V 2 ] ] ϱ [ [ V t ] ] ϱ ) ; [ [ H ] ] ϱ
(def. of translation) = = = ⟦ V 1 V h ( fold V 1 V 2 V t ) ⟧ ϱ ; ⟦ H ⟧ ϱ \llbracket V_1\ V_h\ (\operatorname{fold}\ V_1\ V_2\ V_t)\rrbracket_{\varrho}\ ;\ \llbracket H\rrbracket_{\varrho} [ [ V 1 V h ( fold V 1 V 2 V t ) ] ] ϱ ; [ [ H ] ] ϱ
All other cases are untypeable with the Pure effect, and so the theorem holds vacuously. □
Theorem B.27 (Simulation, bodies, successor). If
(i) Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L , \Gamma\ ;\ \Pi\ ;\ \Phi_H\ ;\ \Phi_D \vdash H\ ;\ D : L, Γ ; Π ; Φ H ; Φ D ⊢ H ; D : L ,
(ii) L ⊆ Π [ p ] , L \subseteq\Pi[p], L ⊆ Π [ p ] ,
(iii) Π ; ids ( D ) ∪ ids ( H ) ⊨ ϱ , \Pi\ ;\ \operatorname{ids}(D) \cup\operatorname{ids}(H) \models\varrho, Π ; ids ( D ) ∪ ids ( H ) ⊨ ϱ , and
(iv) H ; D ⇝ S u c c p H ′ , H\ ;\ D \mathrel{\overset{\mathrm{Succ}}{\leadsto}_p} H', H ; D ⇝ Succ p H ′ ,
then for some Φ D ′ \Phi'_D Φ D ′ , we have:
(i) Γ ; Π ; Φ D ′ ⊢ D ′ : L ′ , \Gamma\ ;\ \Pi\ ;\ \Phi'_D \vdash D' : L', Γ ; Π ; Φ D ′ ⊢ D ′ : L ′ ,
(ii) Φ H ⋈ Φ D ′ = Φ H ⋈ Φ D , \Phi_H \bowtie\Phi'_D = \Phi_H \bowtie\Phi_D, Φ H ⋈ Φ D ′ = Φ H ⋈ Φ D ,
(iii) H ′ = H , H' = H, H ′ = H ,
(iv) L ′ ⊆ L , L' \subseteq L, L ′ ⊆ L ,
(v) Π ; ids ( D ′ ) ∪ ids ( H ) ⊨ ϱ , \Pi\ ;\ \operatorname{ids}(D') \cup\operatorname{ids}(H) \models\varrho, Π ; ids ( D ′ ) ∪ ids ( H ) ⊨ ϱ , and
(vi) ⟦ H ⟧ ϱ ; S ⟦ D ⟧ ( p , ϱ , ∅ ) ⇝ + S ⟦ D ′ ⟧ ( p , ϱ , ∅ ) ; ⟦ H ⟧ ϱ \llbracket H\rrbracket_{\varrho}\ ;\ S\llbracket D\rrbracket(p,\varrho,\emptyset) \mathrel{\overset{+}{\leadsto}} S\llbracket D'\rrbracket(p,\varrho,\emptyset)\ ;\ \llbracket H\rrbracket_{\varrho} [ [ H ] ] ϱ ; S [ [ D ] ] ( p , ϱ , ∅ ) ⇝ + S [ [ D ′ ] ] ( p , ϱ , ∅ ) ; [ [ H ] ] ϱ .
Proof. By definition of premise (i), we have subpremises
(i-a) Γ ; Π ; Φ M ⊢ M : A ! P u r e \Gamma\ ;\ \Pi\ ;\ \Phi_M \vdash M : A\ !\ \mathrm{Pure} Γ ; Π ; Φ M ⊢ M : A ! Pure and
(i-b) Γ ; Π ; Φ H ⊨ H \Gamma\ ;\ \Pi\ ;\ \Phi_H \models H Γ ; Π ; Φ H ⊨ H .
We begin with a few general observations:
By premise (iii), we have (iii-a) that Π ; ids ( D ) ⊨ ϱ \Pi\ ;\ \operatorname{ids}(D) \models\varrho Π ; ids ( D ) ⊨ ϱ and (iii-b) that Π ; ids ( H ) ⊨ ϱ \Pi\ ;\ \operatorname{ids}(H) \models\varrho Π ; ids ( H ) ⊨ ϱ .
To show conclusion (vi) in any case, it is necessary to show (vi-a) that ⟦ H ⟧ ϱ \llbracket H\rrbracket_{\varrho} [ [ H ] ] ϱ is well-defined and (vi-b) that S ⟦ D ⟧ ( p , ϱ , ∅ ) S\llbracket D\rrbracket(p,\varrho,\emptyset) S [ [ D ] ] ( p , ϱ , ∅ ) is well-defined:
(vi-a) is given by Lemma B.9 (heap preservation) on premises (iii-b) and (i-b).
(vi-b) is given by Lemma B.5 (successor body preservation) on premises (i-a), (ii) (which gives us that ∅ ; Π ⊨ p ∅ : L \emptyset\ ;\ \Pi\models_p \emptyset: L ∅ ; Π ⊨ p ∅ : L ), and (iii-a).
We proceed by induction on the derivation of the body step judgment (iv).
Case EB-Let: We have
H ; M ⇝ N ; H ′ H ; let x = M in D ⇝ I n i t p let x = N in D ; H ′ \frac{H\ ;\ M \mathrel{\leadsto} N\ ;\ H'}{H\ ;\ \operatorname{let}\ x=M\ \operatorname{in}\ D \mathrel{\overset{\mathrm{Init}}{\leadsto}_p} \operatorname{let}\ x=N\ \operatorname{in}\ D\ ;\ H'} H ; let x = M in D ⇝ Init p let x = N in D ; H ′ H ; M ⇝ N ; H ′ EB-Let
Γ ; Π ; Φ 1 ⊢ M : A ! P u r e Γ , x : A ; Π ; Φ 2 ⊢ D : L Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in D : L \frac{\Gamma\ ;\ \Pi\ ;\ \Phi_1 \vdash M : A\ !\ \mathrm{Pure}
\qquad
\Gamma,x:A\ ;\ \Pi\ ;\ \Phi_2 \vdash D : L}
{\Gamma\ ;\ \Pi\ ;\ \Phi_1 \bowtie\Phi_2 \vdash\operatorname{let}\ x=M\ \operatorname{in}\ D : L} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in D : L Γ ; Π ; Φ 1 ⊢ M : A ! Pure Γ , x : A ; Π ; Φ 2 ⊢ D : L TB-Let
By Theorem B.26 (pure simulation) on (1), (2), (4), and premise (i-b), we get
Γ ; Π ; Φ 1 ⊢ N : A ! P u r e , \Gamma; \Pi; \Phi_{1} \vdash N : A ! \mathrm{Pure}, Γ ; Π ; Φ 1 ⊢ N : A ! Pure ,
H ′ = H , satisfying conclusion (iii), \mathcal{H}' = \mathcal{H}, \text{ satisfying conclusion (iii),} H ′ = H , satisfying conclusion (iii),
Π ; ids ( N ) ∪ ids ( H ) ⊨ ϱ , and \Pi; \operatorname{ids}(N) \cup\operatorname{ids}(\mathcal{H}) \models\varrho, \text{ and} Π ; ids ( N ) ∪ ids ( H ) ⊨ ϱ , and
⟦ H ⟧ ϱ ; ⟦ M ⟧ ϱ ⇝ + ⟦ N ⟧ ϱ ; ⟦ H ⟧ ϱ . \llbracket\mathcal{H} \rrbracket_{\varrho} ; \llbracket M \rrbracket_{\varrho} \rightsquigarrow^{+} \llbracket N \rrbracket_{\varrho} ; \llbracket\mathcal{H} \rrbracket_{\varrho}. [ [ H ] ] ϱ ; [ [ M ] ] ϱ ⇝ + [ [ N ] ] ϱ ; [ [ H ] ] ϱ .
We choose Φ D ′ = Φ D \Phi'_{D} = \Phi_{D} Φ D ′ = Φ D , trivializing conclusion (ii). Conclusion (iv) is obvious since L ′ = L \mathcal{L}' = \mathcal{L} L ′ = L .
By (5) and (8), we get Π ; ids ( N ) ∪ ids ( D ) ∪ ids ( H ) ⊨ ϱ \Pi; \operatorname{ids}(N) \cup\operatorname{ids}(D) \cup\operatorname{ids}(\mathcal{H}) \models\varrho Π ; ids ( N ) ∪ ids ( D ) ∪ ids ( H ) ⊨ ϱ , satisfying conclusion (v).
We derive conclusion (i) as follows:
\frac{\Gamma; \Pi; \Phi_{1} \vdash N : A ! \mathrm{Pure} \qquad\Gamma, x : A ; \Pi; \Phi_{2} \vdash D : \mathcal{L}}{\Gamma; \Pi; \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{let}\ x = N\ \operatorname{in}\ D : \mathcal{L}}
\quad\mathrm{TB\mathchar`-Let}
⟦ H ⟧ ϱ ; S ⟦ let x = M in D ⟧ ( p , ϱ , ∅ ) = let x = ⟦ M ⟧ ϱ in S ⟦ D ⟧ ( p , ϱ , ∅ ) ; ⟦ H ⟧ ϱ (def. of translation) ⇝ + let x = ⟦ N ⟧ ϱ in S ⟦ D ⟧ ( p , ϱ , ∅ ) ; ⟦ H ⟧ ϱ (xref‘Lemma B.25‘, let-transitivity on (9)) = S ⟦ let x = N in D ⟧ ( p , ϱ , ∅ ) ; ⟦ H ⟧ ϱ (def. of translation) \begin{aligned}
\llbracket\mathcal{H} \rrbracket_{\varrho} \ ;\ S\llbracket\operatorname{let}\ x = M\ \operatorname{in}\ D \rrbracket(p,\varrho,\emptyset)
&= \operatorname{let}\ x = \llbracket M \rrbracket_{\varrho}\ \operatorname{in}\ S\llbracket D \rrbracket(p,\varrho,\emptyset)\ ;\ \llbracket\mathcal{H} \rrbracket_{\varrho} && \text{(def. of translation)}\\
&\rightsquigarrow^{+} \operatorname{let}\ x = \llbracket N \rrbracket_{\varrho}\ \operatorname{in}\ S\llbracket D \rrbracket(p,\varrho,\emptyset)\ ;\ \llbracket\mathcal{H} \rrbracket_{\varrho} && \text{({xref}`Lemma B.25`, let-transitivity on (9))}\\
&= S\llbracket\operatorname{let}\ x = N\ \operatorname{in}\ D \rrbracket(p,\varrho,\emptyset)\ ;\ \llbracket\mathcal{H} \rrbracket_{\varrho} && \text{(def. of translation)}
\end{aligned} [ [ H ] ] ϱ ; S [ [ let x = M in D ] ] ( p , ϱ , ∅ ) = let x = [ [ M ] ] ϱ in S [ [ D ] ] ( p , ϱ , ∅ ) ; [ [ H ] ] ϱ ⇝ + let x = [ [ N ] ] ϱ in S [ [ D ] ] ( p , ϱ , ∅ ) ; [ [ H ] ] ϱ = S [ [ let x = N in D ] ] ( p , ϱ , ∅ ) ; [ [ H ] ] ϱ (def. of translation) ( xref ‘Lemma B.25‘, let-transitivity on (9)) (def. of translation)
Case EB-Val: We have H ; let x = val V in D ⇝ p S u c c D [ V / x ] ; H \mathcal{H}\ ;\ \operatorname{let}\ x = \operatorname{val}\ V\ \operatorname{in}\ D \rightsquigarrow^{\mathrm{Succ}}_{p} D[V/x]\ ;\ \mathcal{H} H ; let x = val V in D ⇝ p Succ D [ V / x ] ; H (from which conclusion (iii) is immediate) and
\frac{\Gamma; \Pi; \Phi_{1} \vdash V : A}{\Gamma; \Pi; \Phi_{1} \vdash\operatorname{val}\ V : A ! \mathrm{Pure}}
\quad\mathrm{TC\mathchar`-Val}
\frac{\Gamma, x : A ; \Pi; \Phi_{2} \vdash D : \mathcal{L}}{\Gamma; \Pi; \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{let}\ x = \operatorname{val}\ V\ \operatorname{in}\ D : \mathcal{L}}
\quad\mathrm{TB\mathchar`-Let}
Choose Φ D ′ = Φ D \Phi'_{D} = \Phi_{D} Φ D ′ = Φ D , trivializing conclusion (ii).
Conclusion (i) is given by Lemma A.20 (type substitution) on (1) and (2).
Conclusion (iv) is obvious since L ′ = L \mathcal{L}' = \mathcal{L} L ′ = L .
Conclusion (v) is given by premise (iii) and the fact that ids ( D [ V / x ] ) ⊆ ids ( D ) ∪ ids ( V ) \operatorname{ids}(D[V/x]) \subseteq\operatorname{ids}(D) \cup\operatorname{ids}(V) ids ( D [ V / x ]) ⊆ ids ( D ) ∪ ids ( V ) .
We show conclusion (vi) as follows:
⟦ H ⟧ ϱ ; S ⟦ let x = val V in D ⟧ ( p , ϱ , ∅ ) = let x = val ⟦ V ⟧ ϱ in S ⟦ D ⟧ ( p , ϱ , ∅ ) ; ⟦ H ⟧ ϱ (def. of translation) ⇝ S ⟦ D ⟧ ( p , ϱ , ∅ ) [ ⟦ V ⟧ ϱ / x ] ; ⟦ H ⟧ ϱ (EC-Val) = S ⟦ D [ V / x ] ⟧ ( p , ϱ , ∅ ) ; ⟦ H ⟧ ϱ (xref‘Lemma B.12‘, substitution) \begin{aligned}
\llbracket\mathcal{H} \rrbracket_{\varrho}\ ;\ S\llbracket\operatorname{let}\ x = \operatorname{val}\ V\ \operatorname{in}\ D \rrbracket(p,\varrho,\emptyset)
&= \operatorname{let}\ x = \operatorname{val}\ \llbracket V \rrbracket_{\varrho}\ \operatorname{in}\ S\llbracket D \rrbracket(p,\varrho,\emptyset)\ ;\ \llbracket\mathcal{H} \rrbracket_{\varrho} && \text{(def. of translation)}\\
&\rightsquigarrow S\llbracket D \rrbracket(p,\varrho,\emptyset)[\llbracket V \rrbracket_{\varrho}/x]\ ;\ \llbracket\mathcal{H} \rrbracket_{\varrho} && \text{(EC-Val)}\\
&= S\llbracket D[V/x] \rrbracket(p,\varrho,\emptyset)\ ;\ \llbracket\mathcal{H} \rrbracket_{\varrho} && \text{({xref}`Lemma B.12`, substitution)}
\end{aligned} [ [ H ] ] ϱ ; S [ [ let x = val V in D ] ] ( p , ϱ , ∅ ) = let x = val [ [ V ] ] ϱ in S [ [ D ] ] ( p , ϱ , ∅ ) ; [ [ H ] ] ϱ ⇝ S [ [ D ] ] ( p , ϱ , ∅ ) [ [ [ V ] ] ϱ / x ] ; [ [ H ] ] ϱ = S [ [ D [ V / x ] ] ] ( p , ϱ , ∅ ) ; [ [ H ] ] ϱ (def. of translation) (EC-Val) ( xref ‘Lemma B.12‘, substitution)
Case EB-StateI: Impossible, since the step rule requires that ϕ = I n i t \phi= \mathrm{Init} ϕ = Init .
Case EB-StateS: We have H ; let x , x s e t = useState ℓ V in D ⇝ p S u c c D [ W / x , set ℓ p / x s e t ] ; H \mathcal{H}\ ;\ \operatorname{let}\ x,x_{\mathrm{set}} = \operatorname{useState}^{\ell}\ V\ \operatorname{in}\ D \rightsquigarrow^{\mathrm{Succ}}_{p} D[W/x,\operatorname{set}^{p}_{\ell}/x_{\mathrm{set}}]\ ;\ \mathcal{H} H ; let x , x set = useState ℓ V in D ⇝ p Succ D [ W / x , set ℓ p / x set ] ; H (from which conclusion (iii) is immediate), where W = H [ p ] . s t [ ℓ ] W = \mathcal{H}[p].\mathrm{st}[\ell] W = H [ p ] . st [ ℓ ] , and
\frac{\Gamma; \Pi; \Phi_{1} \vdash V : A \qquad\Gamma, x : A, x_{\mathrm{set}} : A \xrightarrow{\mathrm{Mut}} 1 ; \Pi; \Phi_{2} \vdash D : \mathcal{L} \qquad\ell\notin\operatorname{dom}(\mathcal{L})}{\Gamma; \Pi; \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{let}\ x,x_{\mathrm{set}} = \operatorname{useState}^{\ell}\ V\ \operatorname{in}\ D : \mathcal{L},\ell: A}
\quad\mathrm{TB\mathchar`-State}
Case EB-StateS: We have H \mathcal{H} H ; let x , x s e t = useState ℓ V x, x_{\mathrm{set}} = \operatorname{useState}^{\ell}\ V x , x set = useState ℓ V in D ⇝ p S u c c D [ W / x , set p ℓ / x s e t ] ; H D \mathrel{\rightsquigarrow^{\mathrm{Succ}}_{p}} D[W/x,\operatorname{set}^{\ell}_{p}/x_{\mathrm{set}}];\mathcal{H} D ⇝ p Succ D [ W / x , set p ℓ / x set ] ; H (from which conclusion (iii) is immediate), where W = H [ p ] . st [ ℓ ] W=\mathcal{H}[p].\operatorname{st}[\ell] W = H [ p ] . st [ ℓ ] , and
Γ ; Π ; Φ 1 ⊢ V : A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x s e t = useState ℓ V in D : L , ℓ : A Γ , x : A , x s e t : A ⟶ M u t 1 ; Π ; Φ 2 ⊢ D : L ℓ ∉ dom ( L ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x s e t = useState ℓ V in D : L , ℓ : A \frac{\Gamma;\Pi;\Phi_1\vdash V:A}{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash\operatorname{let}\ x,x_{\mathrm{set}}=\operatorname{useState}^{\ell}\ V\ \operatorname{in}\ D:\mathcal{L},\ell:A}
\qquad
\frac{\Gamma,x:A,x_{\mathrm{set}}:A\mathrel{\stackrel{\mathrm{Mut}}{\longrightarrow}}1;\Pi;\Phi_2\vdash D:\mathcal{L}\qquad\ell\notin\operatorname{dom}(\mathcal{L})}{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash\operatorname{let}\ x,x_{\mathrm{set}}=\operatorname{useState}^{\ell}\ V\ \operatorname{in}\ D:\mathcal{L},\ell:A} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x set = useState ℓ V in D : L , ℓ : A Γ ; Π ; Φ 1 ⊢ V : A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x , x set = useState ℓ V in D : L , ℓ : A Γ , x : A , x set : A ⟶ Mut 1 ; Π ; Φ 2 ⊢ D : L ℓ ∈ / dom ( L )
By premise (ii), we know L , ℓ : A ⊆ Π [ p ] \mathcal{L},\ell:A\subseteq\Pi[p] L , ℓ : A ⊆ Π [ p ] , i.e. (3) Π [ p ] [ ℓ ] = A \Pi[p][\ell]=A Π [ p ] [ ℓ ] = A .
We derive the setter type as follows (noting Succ ( ∅ ) \operatorname{Succ}(\varnothing) Succ ( ∅ ) holds trivially):
ℓ : A ∈ Π [ p ] Succ ( ∅ ) Γ ; Π ; ∅ ⊢ set p ℓ : A ⟶ M u t 1 \frac{\ell:A\in\Pi[p]\qquad\operatorname{Succ}(\varnothing)}{\Gamma;\Pi;\varnothing\vdash\operatorname{set}^{\ell}_{p}:A\mathrel{\stackrel{\mathrm{Mut}}{\longrightarrow}}1} Γ ; Π ; ∅ ⊢ set p ℓ : A ⟶ Mut 1 ℓ : A ∈ Π [ p ] Succ ( ∅ )
By premise (i-b), we have that Γ ; Π ; Φ W ⊢ W : Π [ p ] [ ℓ ] \Gamma;\Pi;\Phi_W\vdash W:\Pi[p][\ell] Γ ; Π ; Φ W ⊢ W : Π [ p ] [ ℓ ] for some Φ 3 \Phi_3 Φ 3 with Φ H = Φ W ⋈ Φ H ′ \Phi_{\mathcal{H}}=\Phi_W\bowtie\Phi'_{\mathcal{H}} Φ H = Φ W ⋈ Φ H ′ . By (3), this is equivalent to (5) that Γ ; Π ; Φ W ⊢ W : A \Gamma;\Pi;\Phi_W\vdash W:A Γ ; Π ; Φ W ⊢ W : A .
Choose Φ D ′ = Φ D ⋈ Φ W \Phi'_D=\Phi_D\bowtie\Phi_W Φ D ′ = Φ D ⋈ Φ W . We are given that Φ D ⋈ ( Φ W ⋈ Φ H ′ ) \Phi_D\bowtie(\Phi_W\bowtie\Phi'_{\mathcal{H}}) Φ D ⋈ ( Φ W ⋈ Φ H ′ ) is defined, so Φ D ⋈ Φ W \Phi_D\bowtie\Phi_W Φ D ⋈ Φ W is also defined.
By A.4 (unrestriction) on (5), we have Succ ( Φ W ) \operatorname{Succ}(\Phi_W) Succ ( Φ W ) . It follows that ( Φ D ⋈ Φ W ) ⋈ ( Φ W ⋈ Φ H ′ ) = Φ D ⋈ ( Φ W ⋈ Φ H ′ ) (\Phi_D\bowtie\Phi_W)\bowtie(\Phi_W\bowtie\Phi'_{\mathcal{H}})=\Phi_D\bowtie(\Phi_W\bowtie\Phi'_{\mathcal{H}}) ( Φ D ⋈ Φ W ) ⋈ ( Φ W ⋈ Φ H ′ ) = Φ D ⋈ ( Φ W ⋈ Φ H ′ ) , satisfying conclusion (ii).
Lemma A.4 (unrestriction) on (1) gives that Succ ( Φ 1 ) \operatorname{Succ}(\Phi_1) Succ ( Φ 1 ) . We then apply Lemma A.11 (Φ \Phi Φ -weakening) to (2), getting (6) Γ , x : A , x s e t : A ⟶ M u t 1 ; Π ; Φ 1 ⋈ Φ 2 ⊢ D [ W / x , set p ℓ / x s e t ] : L \Gamma,x:A,x_{\mathrm{set}}:A\mathrel{\stackrel{\mathrm{Mut}}{\longrightarrow}}1;\Pi;\Phi_1\bowtie\Phi_2\vdash D[W/x,\operatorname{set}^{\ell}_{p}/x_{\mathrm{set}}]:\mathcal{L} Γ , x : A , x set : A ⟶ Mut 1 ; Π ; Φ 1 ⋈ Φ 2 ⊢ D [ W / x , set p ℓ / x set ] : L .
We apply Lemma A.20 (substitution) twice to (6), using (4) and (5), to obtain that Γ ; Π ; Φ D ′ ⊢ D [ W / x , set p ℓ / x s e t ] : L \Gamma;\Pi;\Phi'_D\vdash D[W/x,\operatorname{set}^{\ell}_{p}/x_{\mathrm{set}}]:\mathcal{L} Γ ; Π ; Φ D ′ ⊢ D [ W / x , set p ℓ / x set ] : L , satisfying conclusion (i).
Conclusion (iv) is obvious, since L ⊆ L , ℓ : A \mathcal{L}\subseteq\mathcal{L},\ell:A L ⊆ L , ℓ : A .
Conclusion (v) is shown as follows:
By premise (iii) and definition, it suffices to show that ids ( H ) ∪ ids ( D [ W / x , set p ℓ / x s e t ] ) ⊆ ids ( W ) ∪ ids ( D ) ∪ ids ( H ) \operatorname{ids}(\mathcal{H})\cup\operatorname{ids}(D[W/x,\operatorname{set}^{\ell}_{p}/x_{\mathrm{set}}])\subseteq\operatorname{ids}(W)\cup\operatorname{ids}(D)\cup\operatorname{ids}(\mathcal{H}) ids ( H ) ∪ ids ( D [ W / x , set p ℓ / x set ]) ⊆ ids ( W ) ∪ ids ( D ) ∪ ids ( H ) .
In general, ids ( D [ V / x ] ) ⊆ ids ( D ) ∪ ids ( V ) \operatorname{ids}(D[V/x])\subseteq\operatorname{ids}(D)\cup\operatorname{ids}(V) ids ( D [ V / x ]) ⊆ ids ( D ) ∪ ids ( V ) . Therefore, it suffices to show that ids ( H ) ∪ ids ( D ) ∪ ids ( W ) ∪ ids ( set p ℓ / x s e t ) ⊆ ids ( V ) ∪ ids ( D ) ∪ ids ( H ) \operatorname{ids}(\mathcal{H})\cup\operatorname{ids}(D)\cup\operatorname{ids}(W)\cup\operatorname{ids}(\operatorname{set}^{\ell}_{p}/x_{\mathrm{set}})\subseteq\operatorname{ids}(V)\cup\operatorname{ids}(D)\cup\operatorname{ids}(\mathcal{H}) ids ( H ) ∪ ids ( D ) ∪ ids ( W ) ∪ ids ( set p ℓ / x set ) ⊆ ids ( V ) ∪ ids ( D ) ∪ ids ( H ) .
By definition, ids ( set p ℓ ) = ∅ \operatorname{ids}(\operatorname{set}^{\ell}_{p})=\varnothing ids ( set p ℓ ) = ∅ and ids ( W ) ⊆ ids ( H ) \operatorname{ids}(W)\subseteq\operatorname{ids}(\mathcal{H}) ids ( W ) ⊆ ids ( H ) . We thus get that ids ( H ) ∪ ids ( D ) ⊆ ids ( V ) ∪ ids ( D ) ∪ ids ( H ) \operatorname{ids}(\mathcal{H})\cup\operatorname{ids}(D)\subseteq\operatorname{ids}(V)\cup\operatorname{ids}(D)\cup\operatorname{ids}(\mathcal{H}) ids ( H ) ∪ ids ( D ) ⊆ ids ( V ) ∪ ids ( D ) ∪ ids ( H ) , which clearly holds, and so we have shown conclusion (v).
By definition of ⟦ H ⟧ ϱ \llbracket\mathcal{H}\rrbracket_{\varrho} [ [ H ] ] ϱ , we know ( ⟦ H ⟧ ϱ ) [ ϱ ( p , ℓ ) ] = ⟦ W ⟧ ϱ (\llbracket\mathcal{H}\rrbracket_{\varrho})[\varrho(p,\ell)]=\llbracket W\rrbracket_{\varrho} ( [ [ H ] ] ϱ ) [ ϱ ( p , ℓ )] = [ [ W ] ] ϱ .
We show conclusion (vi) as follows:
⟦ H ⟧ ϱ ; S ⟦ let x , x s e t = useState ℓ V in D ⟧ ( p , ϱ , ∅ ) = let x = ! ϱ ( p , ℓ ) in let x s e t = val λ y . ( ϱ ( p , ℓ ) : = y ; ϱ ( p ) : = true ) in S ⟦ D ⟧ ( p , ϱ , ∅ ) ; ⟦ H ⟧ ϱ ⇝ + ( let x s e t = val λ y . ( ϱ ( p , ℓ ) : = y ; ϱ ( p ) : = true ) in S ⟦ D ⟧ ( p , ϱ , ∅ ) ) [ ⟦ W ⟧ ϱ / x ] ; ⟦ H ⟧ ϱ ⇝ S ⟦ D ⟧ ( p , ϱ , ∅ ) [ ⟦ W ⟧ ϱ / x , ⟦ set p ℓ ⟧ ϱ / x s e t ] ; ⟦ H ⟧ ϱ = S ⟦ D [ W / x , set p ℓ / x s e t ] ⟧ ( p , ϱ , ∅ ) ; ⟦ H ⟧ ϱ \begin{aligned}
\llbracket\mathcal{H}\rrbracket_{\varrho};\mathsf{S}\llbracket\operatorname{let}\ x,x_{\mathrm{set}}=\operatorname{useState}^{\ell}\ V\ \operatorname{in}\ D\rrbracket(p,\varrho,\varnothing)
&= \operatorname{let}\ x=!\varrho(p,\ell)\ \operatorname{in}\\
&\quad\operatorname{let}\ x_{\mathrm{set}}=\operatorname{val}\ \lambda y.(\varrho(p,\ell):=y;\varrho(p):=\operatorname{true})\ \operatorname{in}\\
&\quad\mathsf{S}\llbracket D\rrbracket(p,\varrho,\varnothing);\llbracket\mathcal{H}\rrbracket_{\varrho}\\
&\mathrel{\rightsquigarrow^{+}}(\operatorname{let}\ x_{\mathrm{set}}=\operatorname{val}\ \lambda y.(\varrho(p,\ell):=y;\varrho(p):=\operatorname{true})\ \operatorname{in}\\
&\quad\mathsf{S}\llbracket D\rrbracket(p,\varrho,\varnothing))[\llbracket W\rrbracket_{\varrho}/x];\llbracket\mathcal{H}\rrbracket_{\varrho}\\
&\mathrel{\rightsquigarrow}\mathsf{S}\llbracket D\rrbracket(p,\varrho,\varnothing)[\llbracket W\rrbracket_{\varrho}/x,\llbracket\operatorname{set}^{\ell}_{p}\rrbracket_{\varrho}/x_{\mathrm{set}}];\llbracket\mathcal{H}\rrbracket_{\varrho}\\
&=\mathsf{S}\llbracket D[W/x,\operatorname{set}^{\ell}_{p}/x_{\mathrm{set}}]\rrbracket(p,\varrho,\varnothing);\llbracket\mathcal{H}\rrbracket_{\varrho}
\end{aligned} [ [ H ] ] ϱ ; S [ [ let x , x set = useState ℓ V in D ] ] ( p , ϱ , ∅ ) = let x = ! ϱ ( p , ℓ ) in let x set = val λ y . ( ϱ ( p , ℓ ) := y ; ϱ ( p ) := true ) in S [ [ D ] ] ( p , ϱ , ∅ ) ; [ [ H ] ] ϱ ⇝ + ( let x set = val λ y . ( ϱ ( p , ℓ ) := y ; ϱ ( p ) := true ) in S [ [ D ] ] ( p , ϱ , ∅ )) [ [ [ W ] ] ϱ / x ] ; [ [ H ] ] ϱ ⇝ S [ [ D ] ] ( p , ϱ , ∅ ) [ [ [ W ] ] ϱ / x , [ [ set p ℓ ] ] ϱ / x set ] ; [ [ H ] ] ϱ = S [ [ D [ W / x , set p ℓ / x set ] ] ] ( p , ϱ , ∅ ) ; [ [ H ] ] ϱ
Theorem B.28 (Simulation, bodies, initial). If
(i) Γ ; Π ; Φ H ⋈ Φ D ⊢ H ; D : L \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_H \mathbin{\bowtie} \Phi_D \vdash\mathcal{H} \mathbin{;} D : \mathcal{L} Γ ; Π ; Φ H ⋈ Φ D ⊢ H ; D : L ,
(ii) Γ ; Π ; Φ 0 ⊢ D 0 : L ⊎ Π [ p ] \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_0 \vdash D_0 : \mathcal{L} \mathbin{\uplus} \Pi[p] Γ ; Π ; Φ 0 ⊢ D 0 : L ⊎ Π [ p ] ,
(iii) p ∉ dom ( Φ H ⋈ Φ D ⋈ Φ 0 ) p \notin\operatorname{dom}(\Phi_H \mathbin{\bowtie} \Phi_D \mathbin{\bowtie} \Phi_0) p ∈ / dom ( Φ H ⋈ Φ D ⋈ Φ 0 ) ,
(iv) Π ; ids ( D ) ∪ ids ( D 0 ) ∪ ids ( H ) ⊨ ϱ \Pi\mathbin{;} \operatorname{ids}(D) \cup\operatorname{ids}(D_0) \cup\operatorname{ids}(\mathcal{H}) \models\varrho Π ; ids ( D ) ∪ ids ( D 0 ) ∪ ids ( H ) ⊨ ϱ , and
(v) H ; D ⇝ p I n i t D ′ ; H ′ \mathcal{H} \mathbin{;} D \mathrel{\overset{\mathrm{Init}}{\underset{p}{\rightsquigarrow}}} D' \mathbin{;} \mathcal{H}' H ; D p ⇝ Init D ′ ; H ′ ,
then for some Φ H ′ \Phi_H' Φ H ′ , Π ′ \Pi' Π ′ , and ϱ ′ ⊇ ϱ \varrho' \supseteq\varrho ϱ ′ ⊇ ϱ , we have:
(i) Γ ; Π ′ ; Φ H ′ ⋈ Φ D ⊢ H ; D ′ : L ′ \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_H' \mathbin{\bowtie} \Phi_D \vdash\mathcal{H} \mathbin{;} D' : \mathcal{L}' Γ ; Π ′ ; Φ H ′ ⋈ Φ D ⊢ H ; D ′ : L ′ ,
(ii) Γ ; Π ′ ; Φ 0 ⊢ D 0 : L ′ ⊎ Π ′ [ p ] \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_0 \vdash D_0 : \mathcal{L}' \mathbin{\uplus} \Pi'[p] Γ ; Π ′ ; Φ 0 ⊢ D 0 : L ′ ⊎ Π ′ [ p ] ,
(iii) Φ H ′ ⋈ Φ D = Φ H ⋈ Φ D \Phi_H' \mathbin{\bowtie} \Phi_D = \Phi_H \mathbin{\bowtie} \Phi_D Φ H ′ ⋈ Φ D = Φ H ⋈ Φ D ,
(iv) Π ⊑ p : I n i t Π ′ \Pi\sqsubseteq_{p:\mathrm{Init}} \Pi' Π ⊑ p : Init Π ′ ,
(v) Π ′ ; ids ( D ′ ) ∪ ids ( D 0 ) ∪ ids ( H ′ ) ⊨ ϱ ′ \Pi' \mathbin{;} \operatorname{ids}(D') \cup\operatorname{ids}(D_0) \cup\operatorname{ids}(\mathcal{H}') \models\varrho' Π ′ ; ids ( D ′ ) ∪ ids ( D 0 ) ∪ ids ( H ′ ) ⊨ ϱ ′ , and
(vi) ⟦ H ⟧ ϱ ; I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) ⇝ + I ⟦ D ′ ⟧ ( D 0 , p , ϱ ′ , ∅ ) ; ⟦ H ′ ⟧ ϱ ′ \llbracket\mathcal{H} \rrbracket_{\varrho} \mathbin{;} I\llbracket D\rrbracket(D_0,p,\varrho,\emptyset) \mathrel{\rightsquigarrow^{+}} I\llbracket D'\rrbracket(D_0,p,\varrho',\emptyset) \mathbin{;} \llbracket\mathcal{H}' \rrbracket_{\varrho'} [ [ H ] ] ϱ ; I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) ⇝ + I [ [ D ′ ] ] ( D 0 , p , ϱ ′ , ∅ ) ; [ [ H ′ ] ] ϱ ′ .
Proof. By definition of premise (i), we have subpremises
(i-a) Γ ; Π ; Φ D ⊢ D : L \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_D \vdash D : \mathcal{L} Γ ; Π ; Φ D ⊢ D : L and
(i-b) Γ ; Π ; Φ H ⊨ H \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_H \models\mathcal{H} Γ ; Π ; Φ H ⊨ H .
Likewise, to show conclusion (i) it suffices to pick some Π ′ ⊒ p : I n i t Π \Pi' \sqsupseteq_{p:\mathrm{Init}} \Pi Π ′ ⊒ p : Init Π and Φ H ′ \Phi_H' Φ H ′ such that conclusion (iii) holds and:
(i-a) Γ ; Π ′ ; Φ D ⊢ D ′ : L ′ \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_D \vdash D' : \mathcal{L}' Γ ; Π ′ ; Φ D ⊢ D ′ : L ′ and
(i-b) Γ ; Π ′ ; Φ H ′ ⊨ H ′ \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_H' \models\mathcal{H}' Γ ; Π ′ ; Φ H ′ ⊨ H ′ .
We begin with a few general observations:
By premise (iv), we have (iv-a) that Π ; ids ( D ) ∪ ids ( D 0 ) ⊨ ϱ \Pi\mathbin{;} \operatorname{ids}(D) \cup\operatorname{ids}(D_0) \models\varrho Π ; ids ( D ) ∪ ids ( D 0 ) ⊨ ϱ and (iv-b) that Π ; ids ( H ) ⊨ ϱ \Pi\mathbin{;} \operatorname{ids}(\mathcal{H}) \models\varrho Π ; ids ( H ) ⊨ ϱ .
To show conclusion (vi) in any case, it is necessary to show (vi-a) that ⟦ H ⟧ ϱ \llbracket\mathcal{H} \rrbracket_{\varrho} [ [ H ] ] ϱ is well-defined and (vi-b) that I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) I\llbracket D\rrbracket(D_0,p,\varrho,\emptyset) I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) is well-defined:
(vi-a) is given by Lemma B.9 (heap preservation) on premises (i-b) and (iv-b).
(vi-b) is given by Lemma 6.3 (initial body preservation) on premises (i-a), (ii), and (iv-a), noting that ∅ ; Π ⊨ p ∅ : ( L ⊎ Π [ p ] ) ∖ L \emptyset\mathbin{;} \Pi\models_p \emptyset: (\mathcal{L} \uplus\Pi[p]) \setminus\mathcal{L} ∅ ; Π ⊨ p ∅ : ( L ⊎ Π [ p ]) ∖ L by definition.
Unless otherwise mentioned, we choose Φ H ′ = Φ H \Phi_H' = \Phi_H Φ H ′ = Φ H , Π ′ = Π \Pi' = \Pi Π ′ = Π , and ϱ ′ = ϱ \varrho' = \varrho ϱ ′ = ϱ , such that:
conclusion (i-b) is given by premise (i-b) when H ′ = H \mathcal{H}' = \mathcal{H} H ′ = H ,
conclusion (ii) is given by premise (ii) when L ′ = L \mathcal{L}' = \mathcal{L} L ′ = L , and
conclusions (iii) and (iv) are trivial.
We proceed by induction on the derivation of the body step judgment (iv).
Case EB-Let: We have
H ; M ⇝ N ; H ′ H ; l e t x = M i n D ⇝ p I n i t l e t x = N i n D ; H ′ (19) \frac{\mathcal{H} \mathbin{;} M \mathrel{\rightsquigarrow} N \mathbin{;} \mathcal{H}'}{\mathcal{H} \mathbin{;} \mathop{\mathrm{let}} x = M \mathop{\mathrm{in}} D \mathrel{\overset{\mathrm{Init}}{\underset{p}{\rightsquigarrow}}} \mathop{\mathrm{let}} x = N \mathop{\mathrm{in}} D \mathbin{;} \mathcal{H}'} \tag*{(19)} H ; let x = M in D p ⇝ Init let x = N in D ; H ′ H ; M ⇝ N ; H ′ (19)
Γ ; Π ; Φ 1 ⊢ M : A ! P u r e Γ , x : A ; Π ; Φ 2 ⊢ D : L Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ l e t x = M i n D : L (20) \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash M : A \mathbin{!} \mathrm{Pure} \qquad\Gamma,x:A \mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash D : \mathcal{L}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \mathbin{\bowtie} \Phi_2 \vdash\mathop{\mathrm{let}} x = M \mathop{\mathrm{in}} D : \mathcal{L}} \tag*{(20)} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in D : L Γ ; Π ; Φ 1 ⊢ M : A ! Pure Γ , x : A ; Π ; Φ 2 ⊢ D : L (20)
By premise (iv) and definition, we have (4) that Π ; ids ( M ) ∪ ids ( H ) ⊨ ϱ \Pi\mathbin{;} \operatorname{ids}(M) \cup\operatorname{ids}(\mathcal{H}) \models\varrho Π ; ids ( M ) ∪ ids ( H ) ⊨ ϱ and (5) that Π ; ids ( D ) ∪ ids ( H ) ⊨ ϱ \Pi\mathbin{;} \operatorname{ids}(D) \cup\operatorname{ids}(\mathcal{H}) \models\varrho Π ; ids ( D ) ∪ ids ( H ) ⊨ ϱ .
By Theorem B.26 (pure simulation) on (1), (2), (4), and premise (i-b), we get
(6) Γ \Gamma Γ ; Π \Pi Π ; Φ 1 ⊢ N : A ! P u r e \Phi_1 \vdash N : A ! \mathrm{Pure} Φ 1 ⊢ N : A ! Pure ,
(7) H ′ = H \mathcal{H}' = \mathcal{H} H ′ = H , satisfying conclusion (i-b),
(8) Π \Pi Π ; ids ( N ) ∪ ids ( H ) ⊨ ϱ \operatorname{ids}(N) \cup\operatorname{ids}(\mathcal{H}) \models\varrho ids ( N ) ∪ ids ( H ) ⊨ ϱ , and
(9) ⟦ H ⟧ ϱ \llbracket\mathcal{H} \rrbracket_{\varrho} [ [ H ] ] ϱ ; ⟦ M ⟧ ϱ ⇝ + ⟦ N ⟧ ϱ \llbracket M \rrbracket_{\varrho} \leadsto^{+} \llbracket N \rrbracket_{\varrho} [ [ M ] ] ϱ ⇝ + [ [ N ] ] ϱ ; ⟦ H ⟧ ϱ \llbracket\mathcal{H} \rrbracket_{\varrho} [ [ H ] ] ϱ .
By (5) and (8), we get Π \Pi Π ; ids ( N ) ∪ ids ( D ) ∪ ids ( H ) ⊨ ϱ \operatorname{ids}(N) \cup\operatorname{ids}(D) \cup\operatorname{ids}(\mathcal{H}) \models\varrho ids ( N ) ∪ ids ( D ) ∪ ids ( H ) ⊨ ϱ , satisfying conclusion (v).
Γ ; Π ; Φ 1 ⊢ N : A ! P u r e Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ l e t x = N i n D : L Γ , x : A ; Π ; Φ 2 ⊢ D : L \begin{aligned}
&\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash N : A ! \mathrm{Pure}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \bowtie\Phi_2 \vdash\mathrm{let}\ x = N\ \mathrm{in}\ D : \mathcal{L}}
\quad
\frac{\Gamma, x : A \mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash D : \mathcal{L}}{}
\end{aligned} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = N in D : L Γ ; Π ; Φ 1 ⊢ N : A ! Pure Γ , x : A ; Π ; Φ 2 ⊢ D : L
⟦ H ⟧ ϱ ; I ⟦ l e t x = M i n D ⟧ ( D 0 , p , ϱ , ∅ ) = l e t x = ⟦ M ⟧ ϱ i n I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) ; ⟦ H ⟧ ϱ ⇝ + l e t l e t x = ⟦ N ⟧ ϱ i n I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) ; ⟦ H ⟧ ϱ = I ⟦ l e t x = N i n D ⟧ ( D 0 , p , ϱ , ∅ ) ; ⟦ H ⟧ ϱ . \begin{aligned}
\llbracket\mathcal{H} \rrbracket_{\varrho} \mathbin{;} \mathcal{I}\llbracket\mathrm{let}\ x = M\ \mathrm{in}\ D \rrbracket(D_0,p,\varrho,\emptyset)
&= \mathrm{let}\ x = \llbracket M \rrbracket_{\varrho}\ \mathrm{in}\ \mathcal{I}\llbracket D \rrbracket(D_0,p,\varrho,\emptyset) \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho} \\
&\leadsto^{+\mathrm{let}}\ \mathrm{let}\ x = \llbracket N \rrbracket_{\varrho}\ \mathrm{in}\ \mathcal{I}\llbracket D \rrbracket(D_0,p,\varrho,\emptyset) \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho} \\
&= \mathcal{I}\llbracket\mathrm{let}\ x = N\ \mathrm{in}\ D \rrbracket(D_0,p,\varrho,\emptyset) \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho}.
\end{aligned} [ [ H ] ] ϱ ; I [ [ let x = M in D ] ] ( D 0 , p , ϱ , ∅ ) = let x = [ [ M ] ] ϱ in I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) ; [ [ H ] ] ϱ ⇝ + let let x = [ [ N ] ] ϱ in I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) ; [ [ H ] ] ϱ = I [ [ let x = N in D ] ] ( D 0 , p , ϱ , ∅ ) ; [ [ H ] ] ϱ .
Case EB-Val: We have H ; l e t x = v a l V i n D ⇝ p I n i t D [ V / x ] ; H \mathcal{H}\mathbin{;} \mathrm{let}\ x = \mathrm{val}\ V\ \mathrm{in}\ D \mathrel{\leadsto^{\mathrm{Init}}_{p}} D[V/x]\mathbin{;} \mathcal{H} H ; let x = val V in D ⇝ p Init D [ V / x ] ; H (from which conclusion (i-b) is immediate) and
Γ ; Π ; Φ 1 ⊢ V : A Γ ; Π ; Φ 1 ⊢ v a l V : A ! P u r e T C - V a l Γ , x : A ; Π ; Φ 2 ⊢ D : L Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ l e t x = v a l V i n D : L T B - L e t \begin{aligned}
&\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash V : A}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash\mathrm{val}\ V : A ! \mathrm{Pure}} \ \mathrm{TC\text{-}Val}
\qquad
\frac{\Gamma, x : A \mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash D : \mathcal{L}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \bowtie\Phi_2 \vdash\mathrm{let}\ x = \mathrm{val}\ V\ \mathrm{in}\ D : \mathcal{L}} \ \mathrm{TB\text{-}Let}
\end{aligned} Γ ; Π ; Φ 1 ⊢ val V : A ! Pure Γ ; Π ; Φ 1 ⊢ V : A TC - Val Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = val V in D : L Γ , x : A ; Π ; Φ 2 ⊢ D : L TB - Let
⟦ H ⟧ ϱ ; I ⟦ l e t x = v a l V i n D ⟧ ( D 0 , p , ϱ , ∅ ) = l e t x = v a l ⟦ V ⟧ ϱ i n I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) ; ⟦ H ⟧ ϱ ⇝ I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) [ ⟦ V ⟧ ϱ / x ] ; ⟦ H ⟧ ϱ = I ⟦ D [ V / x ] ⟧ ( D 0 [ V / x ] , p , ϱ , ∅ ) ; ⟦ H ⟧ ϱ = I ⟦ D [ V / x ] ⟧ ( D 0 , p , ϱ , ∅ ) ; ⟦ H ⟧ ϱ . \begin{aligned}
\llbracket\mathcal{H} \rrbracket_{\varrho} \mathbin{;} \mathcal{I}\llbracket\mathrm{let}\ x = \mathrm{val}\ V\ \mathrm{in}\ D \rrbracket(D_0,p,\varrho,\emptyset)
&= \mathrm{let}\ x = \mathrm{val}\ \llbracket V \rrbracket_{\varrho}\ \mathrm{in}\ \mathcal{I}\llbracket D \rrbracket(D_0,p,\varrho,\emptyset) \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho} \\
&\leadsto\mathcal{I}\llbracket D \rrbracket(D_0,p,\varrho,\emptyset)[\llbracket V \rrbracket_{\varrho}/x] \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho} \\
&= \mathcal{I}\llbracket D[V/x] \rrbracket(D_0[V/x],p,\varrho,\emptyset) \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho} \\
&= \mathcal{I}\llbracket D[V/x] \rrbracket(D_0,p,\varrho,\emptyset) \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho}.
\end{aligned} [ [ H ] ] ϱ ; I [ [ let x = val V in D ] ] ( D 0 , p , ϱ , ∅ ) = let x = val [ [ V ] ] ϱ in I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) ; [ [ H ] ] ϱ ⇝ I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) [ [ [ V ] ] ϱ / x ] ; [ [ H ] ] ϱ = I [ [ D [ V / x ] ] ] ( D 0 [ V / x ] , p , ϱ , ∅ ) ; [ [ H ] ] ϱ = I [ [ D [ V / x ] ] ] ( D 0 , p , ϱ , ∅ ) ; [ [ H ] ] ϱ .
(Case labels: EC-Val; Lemma B.13, substitution; Convention: x ∉ fv ( D 0 ) x \notin\operatorname{fv}(D_0) x ∈ / fv ( D 0 ) .)
Case EB-StateI: We have, for H ′ = H ∣ H [ p ] . s t [ ℓ ] ↦ V \mathcal{H}' = \mathcal{H} \mid\mathcal{H}[p].\mathrm{st}[\ell] \mapsto V H ′ = H ∣ H [ p ] . st [ ℓ ] ↦ V ,
H ; l e t x , x s e t = u s e S t a t e ℓ V i n D ⇝ p I n i t D [ V / x , s e t p ℓ / x s e t ] ; H ′ \mathcal{H}\mathbin{;} \mathrm{let}\ x,x_{\mathrm{set}} = \mathrm{useState}^{\ell}\ V\ \mathrm{in}\ D \mathrel{\leadsto^{\mathrm{Init}}_{p}} D[V/x,\mathrm{set}^{\ell}_{p}/x_{\mathrm{set}}]\mathbin{;} \mathcal{H}' H ; let x , x set = useState ℓ V in D ⇝ p Init D [ V / x , set p ℓ / x set ] ; H ′
Γ ; Π ; ∅ ⊢ V : A Γ , x : A , x s e t : A → M u t 1 ; Π ⊢ D : L ℓ ∉ dom ( L ) \begin{aligned}
&\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \emptyset\vdash V : A}{}
\qquad
\frac{\Gamma,x : A,x_{\mathrm{set}} : A \mathbin{\xrightarrow{\mathrm{Mut}} 1} \mathbin{;} \Pi\vdash D : \mathcal{L}}{}
\qquad
\frac{\ell\notin\operatorname{dom}(\mathcal{L})}{}
\end{aligned} Γ ; Π ; ∅ ⊢ V : A Γ , x : A , x set : A Mut 1 ; Π ⊢ D : L ℓ ∈ / dom ( L )
Γ ; Π ⊢ l e t x , x s e t = u s e S t a t e ℓ V i n D : L , ℓ : A \Gamma\mathbin{;} \Pi\vdash\mathrm{let}\ x,x_{\mathrm{set}} = \mathrm{useState}^{\ell}\ V\ \mathrm{in}\ D : \mathcal{L},\ell: A Γ ; Π ⊢ let x , x set = useState ℓ V in D : L , ℓ : A
Choose Φ H ′ = Φ H ⋈ Φ 1 \Phi'_{\mathcal{H}} = \Phi_{\mathcal{H}} \bowtie\Phi_1 Φ H ′ = Φ H ⋈ Φ 1 , Π ′ = Π ∣ Π [ p ] [ ℓ ] ↦ A \Pi' = \Pi\mid\Pi[p][\ell] \mapsto A Π ′ = Π ∣ Π [ p ] [ ℓ ] ↦ A , and ϱ ′ = ϱ , ( p , ℓ ) ↦ ℓ ′ \varrho' = \varrho,(p,\ell) \mapsto\ell' ϱ ′ = ϱ , ( p , ℓ ) ↦ ℓ ′ , where ℓ ′ \ell' ℓ ′ is the location generated fresh by the target language.
– Since ( Φ 1 ⋈ Φ 2 ) ⋈ Φ H (\Phi_1 \bowtie\Phi_2) \bowtie\Phi_H ( Φ 1 ⋈ Φ 2 ) ⋈ Φ H is given as defined, we know Φ 1 ⋈ Φ H \Phi_1 \bowtie\Phi_H Φ 1 ⋈ Φ H is defined. – To show conclusion ( i i i ) (iii) ( iii ) , we want to show ( Φ 1 ⋈ Φ 2 ) ⋈ ( Φ H ⋈ Φ 1 ) = ( Φ 1 ⋈ Φ 2 ) ⋈ Φ H (\Phi_1 \bowtie\Phi_2) \bowtie(\Phi_H \bowtie\Phi_1) = (\Phi_1 \bowtie\Phi_2) \bowtie\Phi_H ( Φ 1 ⋈ Φ 2 ) ⋈ ( Φ H ⋈ Φ 1 ) = ( Φ 1 ⋈ Φ 2 ) ⋈ Φ H . – These are equal by associativity/commutativity of ⋈ \bowtie ⋈ and by Lemma A.4 (unrestriction) on (1), meaning Φ 1 ⋈ Φ 1 = Φ 1 \Phi_1 \bowtie\Phi_1 = \Phi_1 Φ 1 ⋈ Φ 1 = Φ 1 .
We show conclusion (i-a) as follows: – By premise ( i i i ) (iii) ( iii ) , we have (5) that p : I n i t ⋈ Φ 1 p : \mathrm{Init} \bowtie\Phi_1 p : Init ⋈ Φ 1 is defined and (6) that p : I n i t ⋈ Φ 2 p : \mathrm{Init} \bowtie\Phi_2 p : Init ⋈ Φ 2 is defined. – By Lemma A.1 (Π \Pi Π -weakening) on (1), (4), and (5), we get (7) that Γ ; Π ′ ′ ; Φ 1 ⊢ V : A \Gamma; \Pi'' ; \Phi_1 \vdash V : A Γ ; Π ′′ ; Φ 1 ⊢ V : A . – By Lemma A.3 (Π \Pi Π -weakening) on (2), (4), and (6), we get (8) that Γ , x : A , x s e t : A → M u t 1 ; Π ′ ′ ; Φ 2 ⊢ D : L \Gamma, x : A, x_{\mathrm{set}} : A \xrightarrow{\mathrm{Mut}} 1 ; \Pi'' ; \Phi_2 \vdash D : L Γ , x : A , x set : A Mut 1 ; Π ′′ ; Φ 2 ⊢ D : L . – Since ℓ : A ∈ Π ′ ′ [ p ] \ell: A \in\Pi''[p] ℓ : A ∈ Π ′′ [ p ] by definition and Succ ( ∅ ) \operatorname{Succ}(\varnothing) Succ ( ∅ ) trivially, we derive the setter type as follows:
ℓ : A ∈ Π ′ ′ [ p ] Succ ( ∅ ) ( 9 ) Γ ; Π ′ ′ ; ∅ ⊢ set p ℓ : A → M u t 1 T V - S e t t e r \frac{\ell: A \in\Pi''[p] \qquad\operatorname{Succ}(\varnothing)}
{(9)\quad\Gamma; \Pi'' ; \varnothing\vdash\operatorname{set}^{\ell}_{p} : A \xrightarrow{\mathrm{Mut}} 1}
\quad\mathrm{TV\text{-}Setter} ( 9 ) Γ ; Π ′′ ; ∅ ⊢ set p ℓ : A Mut 1 ℓ : A ∈ Π ′′ [ p ] Succ ( ∅ ) TV - Setter
– We apply Lemma A.20 (substitution) twice to (8), using (7) and (9), to get that Γ ; Π ′ ′ ; Φ 1 ⋈ Φ 2 ⊢ D [ V / x , set p ℓ / x s e t ] : L \Gamma; \Pi'' ; \Phi_1 \bowtie\Phi_2 \vdash D[V/x,\operatorname{set}^{\ell}_{p}/x_{\mathrm{set}}] : L Γ ; Π ′′ ; Φ 1 ⋈ Φ 2 ⊢ D [ V / x , set p ℓ / x set ] : L , i.e. conclusion (i-a) holds.
We show conclusion (i-b) as follows: – We first want (10) that dom ( Π ′ ′ ) = dom ( H ′ ) \operatorname{dom}(\Pi'') = \operatorname{dom}(\mathcal{H}') dom ( Π ′′ ) = dom ( H ′ ) . ∗ By definition of each, it suffices to show that dom ( Π ) ∪ { p } = dom ( H ) ∪ { p } \operatorname{dom}(\Pi) \cup\{p\} = \operatorname{dom}(\mathcal{H}) \cup\{p\} dom ( Π ) ∪ { p } = dom ( H ) ∪ { p } . ∗ Premise (i-b) says that dom ( Π ) = dom ( H ) \operatorname{dom}(\Pi) = \operatorname{dom}(\mathcal{H}) dom ( Π ) = dom ( H ) , so (10) holds. – We also want (11) that dom ( Π ′ ′ [ p ] ) = dom ( H ′ [ p ] . s t ) \operatorname{dom}(\Pi''[p]) = \operatorname{dom}(\mathcal{H}'[p].\mathrm{st}) dom ( Π ′′ [ p ]) = dom ( H ′ [ p ] . st ) . ∗ By definition of each, it suffices to show dom ( Π [ p ] ) ∪ { ℓ } = dom ( H [ p ] . s t ) ∪ { ℓ } \operatorname{dom}(\Pi[p]) \cup\{\ell\} = \operatorname{dom}(\mathcal{H}[p].\mathrm{st}) \cup\{\ell\} dom ( Π [ p ]) ∪ { ℓ } = dom ( H [ p ] . st ) ∪ { ℓ } . ∗ Premise (i-b) says that dom ( Π [ p ] ) = dom ( H [ p ] . s t ) \operatorname{dom}(\Pi[p]) = \operatorname{dom}(\mathcal{H}[p].\mathrm{st}) dom ( Π [ p ]) = dom ( H [ p ] . st ) , so (11) also holds. – Finally, we want (12) that Γ ; Π ′ ′ ; Φ 1 ⊢ H ′ [ p ] . s t [ ℓ ] : Π ′ ′ [ p ] [ ℓ ] \Gamma; \Pi'' ; \Phi_1 \vdash\mathcal{H}'[p].\mathrm{st}[\ell] : \Pi''[p][\ell] Γ ; Π ′′ ; Φ 1 ⊢ H ′ [ p ] . st [ ℓ ] : Π ′′ [ p ] [ ℓ ] . This is given by (7). – By premise (i-b) and by definition, (10)–(12) are sufficient to show that Γ ; Π ′ ′ ; Φ H ⋈ Φ 1 ⊨ H ′ \Gamma; \Pi'' ; \Phi_H \bowtie\Phi_1 \models\mathcal{H}' Γ ; Π ′′ ; Φ H ⋈ Φ 1 ⊨ H ′ , i.e. conclusion (i-b) holds.
We show conclusion (ii) as follows: – By Lemma A.3 on premise (ii), using the fact that p ∉ dom ( Φ 0 ) p \notin\operatorname{dom}(\Phi_0) p ∈ / dom ( Φ 0 ) from premise (iii), we get that Γ ; Π ′ ′ ; Φ 0 ⊢ D 0 : Π [ p ] ⊎ L , ℓ : A \Gamma; \Pi'' ; \Phi_0 \vdash D_0 : \Pi[p] \uplus L, \ell: A Γ ; Π ′′ ; Φ 0 ⊢ D 0 : Π [ p ] ⊎ L , ℓ : A . – We want to show that Π ′ ′ [ p ] ⊎ L = Π [ p ] ⊎ L , ℓ : A \Pi''[p] \uplus L = \Pi[p] \uplus L, \ell: A Π ′′ [ p ] ⊎ L = Π [ p ] ⊎ L , ℓ : A . – By definition, it suffices to show that Π [ p ] , ℓ : A ⊎ L = Π [ p ] ⊎ L , ℓ : A \Pi[p], \ell: A \uplus L = \Pi[p] \uplus L, \ell: A Π [ p ] , ℓ : A ⊎ L = Π [ p ] ⊎ L , ℓ : A . – It further suffices to show Π [ p ] , ℓ : A ⊎ L \Pi[p], \ell: A \uplus L Π [ p ] , ℓ : A ⊎ L is well-defined, i.e. Π [ p ] , ℓ : A ∩ L = ∅ \Pi[p], \ell: A \cap L = \varnothing Π [ p ] , ℓ : A ∩ L = ∅ . This follows from (3) and premise (ii).
We show conclusion (v) as follows: – Given premise (iv) and definition of Π ′ ′ \Pi'' Π ′′ and ϱ ′ \varrho' ϱ ′ , we first need to show that ϱ ′ ( p , ℓ ) \varrho'(p,\ell) ϱ ′ ( p , ℓ ) is well-defined; this is given by definition of ϱ ′ \varrho' ϱ ′ . – Then, it suffices to show that ids ( D [ V / x , set p ℓ / x s e t ] ) ∪ ids ( H ′ ) ⊆ ids ( D ) ∪ ids ( V ) ∪ ids ( H ) \operatorname{ids}(D[V/x,\operatorname{set}^{\ell}_{p}/x_{\mathrm{set}}]) \cup\operatorname{ids}(\mathcal{H}') \subseteq\operatorname{ids}(D) \cup\operatorname{ids}(V) \cup\operatorname{ids}(\mathcal{H}) ids ( D [ V / x , set p ℓ / x set ]) ∪ ids ( H ′ ) ⊆ ids ( D ) ∪ ids ( V ) ∪ ids ( H ) . – By definition of H ′ \mathcal{H}' H ′ , we have ids ( H ′ ) = ids ( H ) ∪ ids ( V ) \operatorname{ids}(\mathcal{H}') = \operatorname{ids}(\mathcal{H}) \cup\operatorname{ids}(V) ids ( H ′ ) = ids ( H ) ∪ ids ( V ) , and by definition we have ids ( set p ℓ ) = ∅ \operatorname{ids}(\operatorname{set}^{\ell}_{p}) = \varnothing ids ( set p ℓ ) = ∅ . The conclusion follows from the fact that ids ( D [ V / x ] ) ⊆ ids ( D ) ∪ ids ( V ) \operatorname{ids}(D[V/x]) \subseteq\operatorname{ids}(D) \cup\operatorname{ids}(V) ids ( D [ V / x ]) ⊆ ids ( D ) ∪ ids ( V ) .
Finally, we show conclusion (vi) as follows: – By Lemmas B.18 /B.14 (ϱ \varrho ϱ -extension) and definition of translation, we have (13) that ⟦ H ⟧ ϱ , ℓ ′ ↦ ⟦ V ⟧ ϱ = ⟦ H ⟧ ϱ ′ , ℓ ′ ↦ ⟦ V ⟧ ϱ ′ \llbracket\mathcal{H} \rrbracket_{\varrho,\ell' \mapsto\llbracket V \rrbracket_{\varrho} = \llbracket\mathcal{H} \rrbracket_{\varrho',\ell' \mapsto\llbracket V \rrbracket_{\varrho'}}} [ [ H ] ] ϱ , ℓ ′ ↦ [ [ V ] ] ϱ = [ [ H ] ] ϱ ′ , ℓ ′ ↦ [ [ V ] ] ϱ ′ .
Since ρ ′ ( p , ℓ ) = ℓ ′ \rho'(p,\ell)=\ell' ρ ′ ( p , ℓ ) = ℓ ′ by definition of translation we have that ⟦ H ⟧ ρ , ℓ ′ ↦ ⟦ V ⟧ ρ ′ = ⟦ H ∣ H [ p ] . st [ ℓ ] ↦ V ⟧ ρ ′ \llbracket H\rrbracket_{\rho,\ell'\mapsto\llbracket V\rrbracket_{\rho'}=\llbracket H\mid H[p].\operatorname{st}[\ell]\mapsto V\rrbracket_{\rho'}} [ [ H ] ] ρ , ℓ ′ ↦ [ [ V ] ] ρ ′ = [ [ H ∣ H [ p ] . st [ ℓ ] ↦ V ] ] ρ ′ . Then from (13) we get (14) that ⟦ H ⟧ ρ , ℓ ′ ↦ ⟦ V ⟧ ρ = ⟦ H ′ ⟧ ρ \llbracket H\rrbracket_{\rho,\ell'\mapsto\llbracket V\rrbracket_{\rho}=\llbracket H'\rrbracket_{\rho}} [ [ H ] ] ρ , ℓ ′ ↦ [ [ V ] ] ρ = [ [ H ′ ] ] ρ .
By Lemma B.14 (ρ \rho ρ -extension) and definition of ρ ′ \rho' ρ ′ and translation, we have (15)
λ y . ( ℓ ′ : = y ; ρ ( p ) : = true ) = ⟦ set ℓ ℓ ′ ⟧ ρ ′ \lambda y.(\ell':=y;\rho(p):=\operatorname{true})=\llbracket\operatorname{set}_{\ell}^{\ell'}\rrbracket_{\rho'} λ y . ( ℓ ′ := y ; ρ ( p ) := true ) = [ [ set ℓ ℓ ′ ] ] ρ ′
By Lemma B.17 (ρ \rho ρ -extension), we have (16) I ⟦ D ⟧ ( D 0 , p , ρ , δ ) = I ⟦ D ⟧ ( D 0 , p , ρ ′ , δ ) \mathcal{I}\llbracket D\rrbracket(D_0,p,\rho,\delta)=\mathcal{I}\llbracket D\rrbracket(D_0,p,\rho',\delta) I [ [ D ] ] ( D 0 , p , ρ , δ ) = I [ [ D ] ] ( D 0 , p , ρ ′ , δ ) .
By Lemma B.24 (δ \delta δ -elimination), we get that
I ⟦ D ⟧ ( D 0 , p , ρ ′ , ℓ ↦ x ℓ ) [ ρ ′ ( p , ℓ ) / x ℓ ] = I ⟦ D ⟧ ( D 0 , p , ρ , ∅ ) [ ρ ′ ( p , ℓ ) / x ℓ ] . \mathcal{I}\llbracket D\rrbracket(D_0,p,\rho',\ell\mapsto x_\ell)[\rho'(p,\ell)/x_\ell]=\mathcal{I}\llbracket D\rrbracket(D_0,p,\rho,\varnothing)[\rho'(p,\ell)/x_\ell]. I [ [ D ] ] ( D 0 , p , ρ ′ , ℓ ↦ x ℓ ) [ ρ ′ ( p , ℓ ) / x ℓ ] = I [ [ D ] ] ( D 0 , p , ρ , ∅ ) [ ρ ′ ( p , ℓ ) / x ℓ ] .
Since x ℓ x_\ell x ℓ is translation-fresh, the above reduces to (17)
I ⟦ D ⟧ ( D 0 , p , ρ , ℓ ↦ x ℓ ) [ ρ ′ ( p , ℓ ) / x ℓ ] = I ⟦ D ⟧ ( D 0 , p , ρ ′ , ∅ ) . \mathcal{I}\llbracket D\rrbracket(D_0,p,\rho,\ell\mapsto x_\ell)[\rho'(p,\ell)/x_\ell]=\mathcal{I}\llbracket D\rrbracket(D_0,p,\rho',\varnothing). I [ [ D ] ] ( D 0 , p , ρ , ℓ ↦ x ℓ ) [ ρ ′ ( p , ℓ ) / x ℓ ] = I [ [ D ] ] ( D 0 , p , ρ ′ , ∅ ) .
I ⟦ D ⟧ ( D 0 , p , ρ ′ , ∅ ) [ ⟦ V ⟧ ρ ′ / x ] = I ⟦ D [ V / x ] ⟧ ( D 0 [ V / x ] , p , ρ ′ , ∅ ) . \mathcal{I}\llbracket D\rrbracket(D_0,p,\rho',\varnothing)[\llbracket V\rrbracket_{\rho'}/x]=\mathcal{I}\llbracket D[V/x]\rrbracket(D_0[V/x],p,\rho',\varnothing). I [ [ D ] ] ( D 0 , p , ρ ′ , ∅ ) [ [ [ V ] ] ρ ′ / x ] = I [ [ D [ V / x ] ] ] ( D 0 [ V / x ] , p , ρ ′ , ∅ ) .
By convention, x ∉ f v ( D 0 ) x\notin fv(D_0) x ∈ / f v ( D 0 ) , so D 0 [ V / x ] = D 0 D_0[V/x]=D_0 D 0 [ V / x ] = D 0 . Applying this principle twice, we get (18)
I ⟦ D ⟧ ( D 0 , p , ρ ′ , ∅ ) [ ⟦ V ⟧ ρ ′ / x , ⟦ set ℓ ℓ ′ ⟧ ρ ′ / x set ] = I ⟦ D [ V / x , set ℓ ℓ ′ / p ] ⟧ ( D 0 , p , ρ ′ , ∅ ) . \mathcal{I}\llbracket D\rrbracket(D_0,p,\rho',\varnothing)[\llbracket V\rrbracket_{\rho'}/x,\llbracket\operatorname{set}_{\ell}^{\ell'}\rrbracket_{\rho'}/x_{\operatorname{set}}]=\mathcal{I}\llbracket D[V/x,\operatorname{set}_{\ell}^{\ell'}/p]\rrbracket(D_0,p,\rho',\varnothing). I [ [ D ] ] ( D 0 , p , ρ ′ , ∅ ) [ [ [ V ] ] ρ ′ / x , [ [ set ℓ ℓ ′ ] ] ρ ′ / x set ] = I [ [ D [ V / x , set ℓ ℓ ′ / p ] ] ] ( D 0 , p , ρ ′ , ∅ ) .
\begin{aligned}
\llbracket H\rrbracket_{\rho}\ ;\ \mathcal{I}\llbracket\operatorname{let}\ x,x_{\operatorname{set}}=\operatorname{useState}^{\ell}\ V\ \operatorname{in}\ D\rrbracket(D_0,p,\rho,\varnothing)
&\quad\text{(def. of translation)}\\
&=\operatorname{let}\ x_\ell=\operatorname{ref}(\llbracket V\rrbracket_{\rho})\ \operatorname{in}\\
&\quad\operatorname{let}\ x=!x_\ell\ \operatorname{in}\\
&\quad\operatorname{let}\ x_{\operatorname{set}}=\operatorname{val}\ \lambda y.(x_\ell:=y;\rho(p):=\operatorname{true})\ \operatorname{in}\\
&\quad\mathcal{I}\llbracket D\rrbracket(D_0,p,\rho,\ell\mapsto x_\ell)\ ;\ \llbracket H\rrbracket_{\rho}\\
&\quad\text{(EC-Ref, EC-Val)}\\
&\rightsquigarrow^+\operatorname{let}\ x=! \ell'\ \operatorname{in}\\
&\quad\operatorname{let}\ x_{\operatorname{set}}=\operatorname{val}\ \lambda y.(\ell':=y;\rho(p):=\operatorname{true})\ \operatorname{in}\\
&\quad\mathcal{I}\llbracket D\rrbracket(D_0,p,\rho,\ell\mapsto x_\ell)[\ell'/x_\ell]\ ;\ \llbracket H\rrbracket_{\rho,\ell'\mapsto\llbracket V\rrbracket_{\rho}\\
&\quad\text{(EC-Get, EC-Val)}\\
&\rightsquigarrow^+\mathcal{I}\llbracket D\rrbracket(D_0,p,\rho,\ell\mapsto x_\ell)[\ell'/x_\ell,\llbracket V\rrbracket_{\rho}/x,\\
&\qquad\lambda y.(\ell':=y;\rho(p):=\operatorname{true})/x_{\operatorname{set}}]\ ;\ \llbracket H\rrbracket_{\rho,\ell'\mapsto\llbracket V\rrbracket_{\rho}\\
&\quad\text{(14), (15), and (16)}\\
&=\mathcal{I}\llbracket D\rrbracket(D_0,p,\rho',\ell\mapsto x_\ell)[\rho'(p,\ell)/x_\ell,\llbracket V\rrbracket_{\rho}/x,\llbracket\operatorname{set}_{\ell}^{\ell'}\rrbracket_{\rho'}/x_{\operatorname{set}}]\ ;\ \llbracket H'\rrbracket_{\rho}\\
&\quad\text{(17)}\\
&=\mathcal{I}\llbracket D\rrbracket(D_0,p,\rho',\varnothing)[\llbracket V\rrbracket_{\rho}/x,\llbracket\operatorname{set}_{\ell}^{\ell'}\rrbracket_{\rho'}/x_{\operatorname{set}}]\ ;\ \llbracket H'\rrbracket_{\rho}\\
&\quad\text{(18)}\\
&=\mathcal{I}\llbracket D[V/x,\operatorname{set}_{\ell}^{\ell'}/x_{\operatorname{set}}]\rrbracket(D_0,p,\rho',\varnothing)\ ;\ \llbracket H'\rrbracket_{\rho}
\end{aligned}}}
Case EB-StateS: Impossible, since the step rule requires that ϕ = Succ \phi=\operatorname{Succ} ϕ = Succ .
Theorem 6.5 (Simulation, computations). If we have
(i) Γ ; Π ; Φ H ; Φ M ⊢ H ; M : A ! Mut , (ii) Π ; ids ( M ) ∪ ids ( H ) ⊨ ρ , and (iii) H ; M ⇝ N ; H ′ , \begin{aligned}
\text{(i)}\quad&\Gamma;\Pi;\Phi_H;\Phi_M\vdash H;M:A!\operatorname{Mut},\\
\text{(ii)}\quad&\Pi;\operatorname{ids}(M)\cup\operatorname{ids}(H)\models\rho,\ \text{and}\\
\text{(iii)}\quad&H;M\rightsquigarrow N;H',
\end{aligned} (i) (ii) (iii) Γ ; Π ; Φ H ; Φ M ⊢ H ; M : A ! Mut , Π ; ids ( M ) ∪ ids ( H ) ⊨ ρ , and H ; M ⇝ N ; H ′ , then for some Φ H ′ , Φ N , Π ′ \Phi'_H,\Phi_N,\Pi' Φ H ′ , Φ N , Π ′ , and ρ ′ ⊇ ρ \rho'\supseteq\rho ρ ′ ⊇ ρ , we get:
(i) Φ M ⋈ Φ H ⊑ f r e s h Φ N ⋈ Φ H ′ , (ii) Π ⊑ Φ N ⋈ Φ H ′ Π ′ , (iii) Γ ; Π ′ ; Φ H ′ ; Φ N ⊢ N : A ! Mut , (iv) Π ′ ; ids ( N ) ∪ ids ( H ′ ) ⊨ ρ ′ , and (v) ⟦ H ⟧ ρ ; ⟦ M ⟧ ρ ⇝ + ⟦ N ⟧ ρ ′ ; ⟦ H ′ ⟧ ρ ′ . \begin{aligned}
\text{(i)}\quad&\Phi_M\mathbin{\bowtie}\Phi_H\sqsubseteq_{\mathrm{fresh}}\Phi_N\mathbin{\bowtie}\Phi'_H,\\
\text{(ii)}\quad&\Pi\sqsubseteq_{\Phi_N\bowtie\Phi'_H}\Pi',\\
\text{(iii)}\quad&\Gamma;\Pi';\Phi'_H;\Phi_N\vdash N:A!\operatorname{Mut},\\
\text{(iv)}\quad&\Pi';\operatorname{ids}(N)\cup\operatorname{ids}(H')\models\rho',\ \text{and}\\
\text{(v)}\quad&\llbracket H\rrbracket_{\rho};\llbracket M\rrbracket_{\rho}\rightsquigarrow^+\llbracket N\rrbracket_{\rho'};\llbracket H'\rrbracket_{\rho'}.
\end{aligned} (i) (ii) (iii) (iv) (v) Φ M ⋈ Φ H ⊑ fresh Φ N ⋈ Φ H ′ , Π ⊑ Φ N ⋈ Φ H ′ Π ′ , Γ ; Π ′ ; Φ H ′ ; Φ N ⊢ N : A ! Mut , Π ′ ; ids ( N ) ∪ ids ( H ′ ) ⊨ ρ ′ , and [ [ H ] ] ρ ; [ [ M ] ] ρ ⇝ + [ [ N ] ] ρ ′ ; [ [ H ′ ] ] ρ ′ .
Proof. By definition of premise (i), we have subpremises (i-a) Γ ; Π ; Φ M ⊢ M : A ! Mut \Gamma;\Pi;\Phi_M\vdash M:A!\operatorname{Mut} Γ ; Π ; Φ M ⊢ M : A ! Mut and (i-b) Γ ; Π ; Φ H ⊨ H \Gamma;\Pi;\Phi_H\models H Γ ; Π ; Φ H ⊨ H .
Likewise, to show conclusion (iii), it suffices to show for our chosen Φ N \Phi_N Φ N , Φ H ′ \Phi'_H Φ H ′ , and Π ′ \Pi' Π ′ that (iii-a) Γ ; Π ′ ; Φ N ⊢ N : A ! M u t \Gamma\mathbin{;} \Pi^{\prime} \mathbin{;} \Phi_N \vdash N : A\ !\ \mathrm{Mut} Γ ; Π ′ ; Φ N ⊢ N : A ! Mut and (iii-b) Γ ; Π ′ ; Φ H ′ ⊢ H ′ \Gamma\mathbin{;} \Pi^{\prime} \mathbin{;} \Phi^{\prime}_{H} \vdash H^{\prime} Γ ; Π ′ ; Φ H ′ ⊢ H ′ .
Unless otherwise mentioned, we choose Φ N = Φ M \Phi_N = \Phi_M Φ N = Φ M , Φ H ′ = Φ H \Phi^{\prime}_{H} = \Phi_H Φ H ′ = Φ H , and Π ′ = Π \Pi^{\prime} = \Pi Π ′ = Π , such that are trivial, and
conclusions ( i ) (i) ( i ) and ( i i ) (ii) ( ii ) are trivial,
conclusion (iii-b) is trivial by premise (i-b) when H ′ = H H^{\prime} = H H ′ = H , and
to show conclusion ( i v ) (iv) ( i v ) given premise ( i i ) (ii) ( ii ) , it suffices to show ids ( N ) ∪ ids ( H ′ ) ⊆ ids ( M ) ∪ ids ( H ) \operatorname{ids}(N) \cup\operatorname{ids}(H^{\prime}) \subseteq\operatorname{ids}(M) \cup\operatorname{ids}(H) ids ( N ) ∪ ids ( H ′ ) ⊆ ids ( M ) ∪ ids ( H ) .
We begin by establishing translation well-definedness:
By premise ( i i ) (ii) ( ii ) , we have (ii-a) that Π ; ids ( M ) ⊨ ϱ \Pi\mathbin{;} \operatorname{ids}(M) \models\varrho Π ; ids ( M ) ⊨ ϱ and (ii-b) that Π ; ids ( H ) ⊨ ϱ \Pi\mathbin{;} \operatorname{ids}(H) \models\varrho Π ; ids ( H ) ⊨ ϱ .
To show conclusion ( i v ) (iv) ( i v ) in any case, it is necessary to show (iv-a) that ⟦ H ⟧ ϱ \llbracket H \rrbracket_{\varrho} [ [ H ] ] ϱ is well-defined and (iv-b) that ⟦ M ⟧ ϱ \llbracket M \rrbracket_{\varrho} [ [ M ] ] ϱ is well-defined:
We proceed by induction on the derivation of the computation step judgment ( i i i ) (iii) ( iii ) .
Case EC-Let: We have
(1) H ; M ⇝ M ′ ; H ′ H ; l e t x = M i n N ⇝ l e t x = M ′ i n N ; H ′ \begin{gathered}
\text{(1)}\\
\frac{H\mathbin{;}M \leadsto M^{\prime}\mathbin{;}H^{\prime}}{}\\
H\mathbin{;} \mathop{\mathrm{let}}\ x=M\ \mathop{\mathrm{in}}\ N \leadsto\mathop{\mathrm{let}}\ x=M^{\prime}\ \mathop{\mathrm{in}}\ N\mathbin{;}H^{\prime}
\end{gathered} (1) H ; M ⇝ M ′ ; H ′ H ; let x = M in N ⇝ let x = M ′ in N ; H ′
(2) (3) Γ ; Π ; Φ 1 ⊢ M : A ! M u t Γ , x : A ; Π ; Φ 2 ⊢ N : B ! M u t Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ l e t x = M i n N : B ! M u t \begin{gathered}
\text{(2)}\qquad\qquad\text{(3)}\\
\frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \vdash M:A\ !\ \mathrm{Mut}}
\qquad
\frac{\Gamma,x:A\mathbin{;} \Pi\mathbin{;} \Phi_2 \vdash N:B\ !\ \mathrm{Mut}}{}\\
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_1 \mathbin{\bowtie} \Phi_2 \vdash\mathop{\mathrm{let}}\ x=M\ \mathop{\mathrm{in}}\ N:B\ !\ \mathrm{Mut}
\end{gathered} (2) (3) Γ ; Π ; Φ 1 ⊢ M : A ! Mut Γ , x : A ; Π ; Φ 2 ⊢ N : B ! Mut Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = M in N : B ! Mut
By premise ( i i i ) (iii) ( iii ) and definition, we have (4) that Π ; ids ( M ) ∪ ids ( H ) ⊨ ϱ \Pi\mathbin{;} \operatorname{ids}(M) \cup\operatorname{ids}(H) \models\varrho Π ; ids ( M ) ∪ ids ( H ) ⊨ ϱ , and (5) that Π ; ids ( N ) ∪ ids ( H ) ⊨ ϱ \Pi\mathbin{;} \operatorname{ids}(N) \cup\operatorname{ids}(H) \models\varrho Π ; ids ( N ) ∪ ids ( H ) ⊨ ϱ .
By inductive hypothesis on (1), (2), (4), and premise (i-b), we get some Φ 1 ′ \Phi_1^{\prime} Φ 1 ′ , Φ H ′ \Phi_H^{\prime} Φ H ′ , and Π ′ \Pi^{\prime} Π ′ such that: (6) Φ 1 ⋈ Φ H ⊑ f r e s h Φ 1 ′ ⋈ Φ H ′ \Phi_1 \bowtie\Phi_H \sqsubseteq_{\mathrm{fresh}} \Phi_1^{\prime} \bowtie\Phi_H^{\prime} Φ 1 ⋈ Φ H ⊑ fresh Φ 1 ′ ⋈ Φ H ′ (7) Π ⊑ Φ 1 ′ ⋈ Φ H ′ Π ′ \Pi\sqsubseteq_{\Phi_1^{\prime}\bowtie\Phi_H^{\prime}} \Pi^{\prime} Π ⊑ Φ 1 ′ ⋈ Φ H ′ Π ′ (8) Γ ; Π ′ ; Φ 1 ′ ⊢ M ′ : A ! M u t \Gamma\mathbin{;} \Pi^{\prime} \mathbin{;} \Phi_1^{\prime} \vdash M^{\prime}:A\ !\ \mathrm{Mut} Γ ; Π ′ ; Φ 1 ′ ⊢ M ′ : A ! Mut , (9) Γ ; Π ′ ; Φ H ′ ⊨ H ′ \Gamma\mathbin{;} \Pi^{\prime} \mathbin{;} \Phi_H^{\prime} \models H^{\prime} Γ ; Π ′ ; Φ H ′ ⊨ H ′ , (10) Π ′ ; ids ( M ′ ) ∪ ids ( H ′ ) ⊨ ϱ ′ \Pi^{\prime} \mathbin{;} \operatorname{ids}(M^{\prime}) \cup\operatorname{ids}(H^{\prime}) \models\varrho^{\prime} Π ′ ; ids ( M ′ ) ∪ ids ( H ′ ) ⊨ ϱ ′ , and (11) ⟦ H ⟧ ϱ ; ⟦ M ⟧ ϱ ⇝ + ⟦ M ′ ⟧ ϱ ′ ; ⟦ H ′ ⟧ ϱ ′ \llbracket H \rrbracket_{\varrho} \mathbin{;} \llbracket M \rrbracket_{\varrho} \leadsto^{+} \llbracket M^{\prime} \rrbracket_{\varrho^{\prime}} \mathbin{;} \llbracket H^{\prime} \rrbracket_{\varrho^{\prime}} [ [ H ] ] ϱ ; [ [ M ] ] ϱ ⇝ + [ [ M ′ ] ] ϱ ′ ; [ [ H ′ ] ] ϱ ′ .
Choose Φ N = Φ 1 ′ ⋈ Φ 2 \Phi_N = \Phi_1^{\prime} \bowtie\Phi_2 Φ N = Φ 1 ′ ⋈ Φ 2 and this Φ H ′ \Phi_H^{\prime} Φ H ′ as our own.
By Lemma 4.5 (fresh Φ \Phi Φ -extension) using (6) and extending by Φ 2 \Phi_2 Φ 2 , we get that Φ N ⋈ Φ H ′ \Phi_N \bowtie\Phi_H^{\prime} Φ N ⋈ Φ H ′ is defined and Φ M ⋈ Φ H ⊑ f r e s h Φ N ⋈ Φ H ′ \Phi_M \bowtie\Phi_H \sqsubseteq_{\mathrm{fresh}} \Phi_N \bowtie\Phi_H^{\prime} Φ M ⋈ Φ H ⊑ fresh Φ N ⋈ Φ H ′ , satisfying conclusion ( i ) (i) ( i ) .
Choose this Π ′ \Pi^{\prime} Π ′ as our own. By Lemma A.17 (Π \Pi Π -order preservation) using (7) and extending by Φ 2 \Phi_2 Φ 2 , we get that Π ⊑ Φ N ⋈ Φ H Π ′ \Pi\sqsubseteq_{\Phi_N\bowtie\Phi_H} \Pi^{\prime} Π ⊑ Φ N ⋈ Φ H Π ′ , satisfying conclusion ( i i ) (ii) ( ii ) .
Choose this ϱ ′ \varrho^{\prime} ϱ ′ as our own. By (10) and (5), we have Π ′ ; ids ( l e t x = M ′ i n N ) ∪ ids ( H ′ ) ⊨ ϱ ′ \Pi^{\prime} \mathbin{;} \operatorname{ids}(\mathop{\mathrm{let}}\ x=M^{\prime}\ \mathop{\mathrm{in}}\ N) \cup\operatorname{ids}(H^{\prime}) \models\varrho^{\prime} Π ′ ; ids ( let x = M ′ in N ) ∪ ids ( H ′ ) ⊨ ϱ ′ , satisfying conclusion ( i v ) (iv) ( i v ) .
(9) gives us conclusion (iii-b).
By Lemma A.2 (Π \Pi Π -weakening) on (3) using (7) and the fact that Φ N ⋈ Φ H \Phi_N \bowtie\Phi_H Φ N ⋈ Φ H is defined, we get (12) that Γ , x : A ; Π ′ ; Φ 2 ⊢ N : B ! P u r e \Gamma,x:A\mathbin{;} \Pi^{\prime}\mathbin{;} \Phi_2 \vdash N:B\ !\ \mathrm{Pure} Γ , x : A ; Π ′ ; Φ 2 ⊢ N : B ! Pure .
Γ ; Π ′ ; Φ 1 ′ ⊢ M ′ : A ! P u r e Γ , x : A ; Π ′ ; Φ 2 ⊢ N : B ! P u r e Γ ; Π ; Φ 1 ′ ⋈ Φ 2 ⊢ l e t x = M ′ i n N : B ! P u r e T C - L e t \frac{\Gamma; \Pi' ; \Phi'_1 \vdash M' : A\ !\ \mathrm{Pure} \qquad\Gamma, x : A ; \Pi' ; \Phi_2 \vdash N : B\ !\ \mathrm{Pure}}{\Gamma; \Pi; \Phi'_1 \bowtie\Phi_2 \vdash\mathrm{let}\ x = M' \ \mathrm{in}\ N : B\ !\ \mathrm{Pure}}\ \mathrm{TC\text{-}Let} Γ ; Π ; Φ 1 ′ ⋈ Φ 2 ⊢ let x = M ′ in N : B ! Pure Γ ; Π ′ ; Φ 1 ′ ⊢ M ′ : A ! Pure Γ , x : A ; Π ′ ; Φ 2 ⊢ N : B ! Pure TC - Let
⟦ H ⟧ ϱ ; ⟦ l e t x = M i n N ⟧ ϱ \llbracket H \rrbracket_{\varrho} ; \llbracket\mathrm{let}\ x = M\ \mathrm{in}\ N \rrbracket_{\varrho} [ [ H ] ] ϱ ; [ [ let x = M in N ] ] ϱ
= (def. of translation) = l e t x = ⟦ M ⟧ ϱ i n ⟦ N ⟧ ϱ ; ⟦ H ⟧ ϱ (Lemma B.25, let-transitivity on (11)) ⇝ l e t + l e t x = ⟦ M ′ ⟧ ϱ ′ i n ⟦ N ⟧ ϱ ; ⟦ H ′ ⟧ ϱ ′ (Lemma B.15, ϱ -extension) = l e t x = ⟦ M ′ ⟧ ϱ ′ i n ⟦ N ⟧ ϱ ′ ; ⟦ H ′ ⟧ ϱ ′ (def. of translation) = ⟦ l e t x = M ′ i n N ⟧ ϱ ′ ; ⟦ H ′ ⟧ ϱ ′ \begin{aligned}
&\mathrel{\phantom{=}} \text{(def. of translation)} &&= \mathrm{let}\ x = \llbracket M \rrbracket_{\varrho}\ \mathrm{in}\ \llbracket N \rrbracket_{\varrho} ; \llbracket H \rrbracket_{\varrho}\\
&\text{(Lemma B.25, let-transitivity on (11))} &&\rightsquigarrow^{+}_{\mathrm{let}}\ \mathrm{let}\ x = \llbracket M' \rrbracket_{\varrho'}\ \mathrm{in}\ \llbracket N \rrbracket_{\varrho} ; \llbracket H' \rrbracket_{\varrho'}\\
&\text{(Lemma B.15, }\varrho\text{-extension)} &&= \mathrm{let}\ x = \llbracket M' \rrbracket_{\varrho'}\ \mathrm{in}\ \llbracket N \rrbracket_{\varrho'} ; \llbracket H' \rrbracket_{\varrho'}\\
&\text{(def. of translation)} &&= \llbracket\mathrm{let}\ x = M'\ \mathrm{in}\ N \rrbracket_{\varrho'} ; \llbracket H' \rrbracket_{\varrho'}
\end{aligned} = (def. of translation) (Lemma B.25, let-transitivity on (11)) (Lemma B.15, ϱ -extension) (def. of translation) = let x = [ [ M ] ] ϱ in [ [ N ] ] ϱ ; [ [ H ] ] ϱ ⇝ let + let x = [ [ M ′ ] ] ϱ ′ in [ [ N ] ] ϱ ; [ [ H ′ ] ] ϱ ′ = let x = [ [ M ′ ] ] ϱ ′ in [ [ N ] ] ϱ ′ ; [ [ H ′ ] ] ϱ ′ = [ [ let x = M ′ in N ] ] ϱ ′ ; [ [ H ′ ] ] ϱ ′
Case EC-Val: We have H ; l e t x = v a l V i n M ⇝ M [ V / x ] ; H \mathcal{H}\ ;\ \mathrm{let}\ x = \mathrm{val}\ V\ \mathrm{in}\ M \rightsquigarrow M[V/x]\ ;\ \mathcal{H} H ; let x = val V in M ⇝ M [ V / x ] ; H and
Γ ; Π ; Φ 1 ⊢ V : A Γ ; Π ; Φ 1 ⊢ v a l V : A ! P u r e T C - V a l Γ ; Π ; Φ 1 ⊢ v a l V : A ! P u r e Γ ; Π ; Φ 1 ⊢ v a l V : A ! M u t T C - S u b Γ ; Π ; Φ 2 ⊢ M : B ! M u t Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ l e t x = v a l V i n M : B ! M u t T C - L e t \begin{aligned}
&\frac{\Gamma; \Pi; \Phi_1 \vdash V : A}{\Gamma; \Pi; \Phi_1 \vdash\mathrm{val}\ V : A\ !\ \mathrm{Pure}}\ \mathrm{TC\text{-}Val}\\
&\frac{\Gamma; \Pi; \Phi_1 \vdash\mathrm{val}\ V : A\ !\ \mathrm{Pure}}{\Gamma; \Pi; \Phi_1 \vdash\mathrm{val}\ V : A\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Sub}\\
&\frac{\Gamma; \Pi; \Phi_2 \vdash M : B\ !\ \mathrm{Mut}}{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash\mathrm{let}\ x = \mathrm{val}\ V\ \mathrm{in}\ M : B\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Let}
\end{aligned} Γ ; Π ; Φ 1 ⊢ val V : A ! Pure Γ ; Π ; Φ 1 ⊢ V : A TC - Val Γ ; Π ; Φ 1 ⊢ val V : A ! Mut Γ ; Π ; Φ 1 ⊢ val V : A ! Pure TC - Sub Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ let x = val V in M : B ! Mut Γ ; Π ; Φ 2 ⊢ M : B ! Mut TC - Let
Conclusion (iv) follows from premise (ii) and the fact that ids ( M [ V / x ] ) ⊆ ids ( M ) ∪ ids ( V ) \operatorname{ids}(M[V/x]) \subseteq\operatorname{ids}(M) \cup\operatorname{ids}(V) ids ( M [ V / x ]) ⊆ ids ( M ) ∪ ids ( V ) .
Conclusion (iii-a) follows from \xrefLemma A.19 (type substitution) on (1) and (2).
We show conclusion (v) as follows:
⟦ H ⟧ ϱ ; ⟦ l e t x = v a l V i n M ⟧ ϱ = l e t x = v a l ⟦ V ⟧ ϱ i n ⟦ M ⟧ ϱ ; ⟦ H ⟧ ϱ ⇝ ⟦ M ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] ; ⟦ H ⟧ ϱ = ⟦ M [ V / x ] ⟧ ϱ ; ⟦ H ⟧ ϱ \begin{aligned}
\llbracket H \rrbracket_{\varrho} ; \llbracket\mathrm{let}\ x = \mathrm{val}\ V\ \mathrm{in}\ M \rrbracket_{\varrho}
&= \mathrm{let}\ x = \mathrm{val}\ \llbracket V \rrbracket_{\varrho}\ \mathrm{in}\ \llbracket M \rrbracket_{\varrho} ; \llbracket H \rrbracket_{\varrho}\\
&\rightsquigarrow\llbracket M \rrbracket_{\varrho}[\llbracket V \rrbracket_{\varrho}/x] ; \llbracket H \rrbracket_{\varrho}\\
&= \llbracket M[V/x] \rrbracket_{\varrho} ; \llbracket H \rrbracket_{\varrho}
\end{aligned} [ [ H ] ] ϱ ; [ [ let x = val V in M ] ] ϱ = let x = val [ [ V ] ] ϱ in [ [ M ] ] ϱ ; [ [ H ] ] ϱ ⇝ [ [ M ] ] ϱ [ [ [ V ] ] ϱ / x ] ; [ [ H ] ] ϱ = [ [ M [ V / x ] ] ] ϱ ; [ [ H ] ] ϱ
Case EC-App: We have H ; ( λ x . M ) V ⇝ M [ V / x ] ; H \mathcal{H}\ ;\ (\lambda x.M)\ V \rightsquigarrow M[V/x]\ ;\ \mathcal{H} H ; ( λ x . M ) V ⇝ M [ V / x ] ; H and one of either of the following derivations by premise (i):
Γ , x : A ; Π ; Φ 1 ⊢ M : B ! M u t Succ ( Φ 1 ) Γ ; Π ; Φ 1 ⊢ λ x . M : A → M u t B T V - L a m ( 1 a ) Γ ; Π ; Φ 1 ⊢ λ x . M : A → M u t B Γ ; Π ; Φ 2 ⊢ V : A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( λ x . M ) V : B ! M u t T C - A p p ( 2 ) \begin{aligned}
&\frac{\Gamma, x : A ; \Pi; \Phi_1 \vdash M : B\ !\ \mathrm{Mut}\quad\operatorname{Succ}(\Phi_1)}
{\Gamma; \Pi; \Phi_1 \vdash\lambda x.M : A \xrightarrow{\mathrm{Mut}} B}\ \mathrm{TV\text{-}Lam}\ (1a)\\
&\frac{\Gamma; \Pi; \Phi_1 \vdash\lambda x.M : A \xrightarrow{\mathrm{Mut}} B\qquad\Gamma; \Pi; \Phi_2 \vdash V : A}
{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash(\lambda x.M)\ V : B\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}App}\ (2)
\end{aligned} Γ ; Π ; Φ 1 ⊢ λ x . M : A Mut B Γ , x : A ; Π ; Φ 1 ⊢ M : B ! Mut Succ ( Φ 1 ) TV - Lam ( 1 a ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( λ x . M ) V : B ! Mut Γ ; Π ; Φ 1 ⊢ λ x . M : A Mut B Γ ; Π ; Φ 2 ⊢ V : A TC - App ( 2 )
Γ , x : A ; Π ; Φ 1 ⊢ M : B ! P u r e Succ ( Φ 1 ) Γ ; Π ; Φ 1 ⊢ λ x . M : A → P u r e B T V - L a m ( 1 b ) Γ ; Π ; Φ 1 ⊢ λ x . M : A → P u r e B Γ ; Π ; Φ 2 ⊢ V : A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( λ x . M ) V : B ! P u r e T C - A p p ( 2 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( λ x . M ) V : B ! P u r e Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( λ x . M ) V : B ! M u t T C - S u b \begin{aligned}
&\frac{\Gamma, x : A ; \Pi; \Phi_1 \vdash M : B\ !\ \mathrm{Pure}\quad\operatorname{Succ}(\Phi_1)}
{\Gamma; \Pi; \Phi_1 \vdash\lambda x.M : A \xrightarrow{\mathrm{Pure}} B}\ \mathrm{TV\text{-}Lam}\ (1b)\\
&\frac{\Gamma; \Pi; \Phi_1 \vdash\lambda x.M : A \xrightarrow{\mathrm{Pure}} B\qquad\Gamma; \Pi; \Phi_2 \vdash V : A}
{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash(\lambda x.M)\ V : B\ !\ \mathrm{Pure}}\ \mathrm{TC\text{-}App}\ (2)\\
&\frac{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash(\lambda x.M)\ V : B\ !\ \mathrm{Pure}}
{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2 \vdash(\lambda x.M)\ V : B\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Sub}
\end{aligned} Γ ; Π ; Φ 1 ⊢ λ x . M : A Pure B Γ , x : A ; Π ; Φ 1 ⊢ M : B ! Pure Succ ( Φ 1 ) TV - Lam ( 1 b ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( λ x . M ) V : B ! Pure Γ ; Π ; Φ 1 ⊢ λ x . M : A Pure B Γ ; Π ; Φ 2 ⊢ V : A TC - App ( 2 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( λ x . M ) V : B ! Mut Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( λ x . M ) V : B ! Pure TC - Sub
TC-Sub on (1b) gives us (1a), so it suffices to show the conclusions given (1a).
Conclusion (iv) follows from premise (ii) and the fact that ids ( M [ V / x ] ) ⊆ ids ( M ) ∪ ids ( V ) \operatorname{ids}(M[V/x]) \subseteq\operatorname{ids}(M) \cup\operatorname{ids}(V) ids ( M [ V / x ]) ⊆ ids ( M ) ∪ ids ( V ) .
Conclusion (iii-a) follows from Lemma A.19 (type substitution) on (1a) and (2).
We show conclusion (v) as follows:
⟦ H ⟧ ϱ ; ⟦ ( λ x . M ) V ⟧ ϱ (def. of translation) = ( λ x . ⟦ M ⟧ ϱ ) ⟦ V ⟧ ϱ ; ⟦ H ⟧ ϱ (EC-App) ⇝ ⟦ M ⟧ ϱ [ ⟦ V ⟧ ϱ / x ] ; ⟦ H ⟧ ϱ (Lemma B.11, substitution) = ⟦ M [ V / x ] ⟧ ϱ ; ⟦ H ⟧ ϱ \begin{aligned}
\llbracket H\rrbracket_{\varrho} \mathbin{;} \llbracket(\lambda x.M)\ V\rrbracket_{\varrho}\\
\text{(def. of translation)}\quad=(\lambda x.\llbracket M\rrbracket_{\varrho})\ \llbracket V\rrbracket_{\varrho}\mathbin{;} \llbracket H\rrbracket_{\varrho}\\
\text{(EC-App)}\quad\leadsto\llbracket M\rrbracket_{\varrho}[\llbracket V\rrbracket_{\varrho}/x]\mathbin{;} \llbracket H\rrbracket_{\varrho}\\
\text{(Lemma B.11, substitution)}\quad=\llbracket M[V/x]\rrbracket_{\varrho}\mathbin{;} \llbracket H\rrbracket_{\varrho}
\end{aligned} [ [ H ] ] ϱ ; [ [ ( λ x . M ) V ] ] ϱ (def. of translation) = ( λ x . [ [ M ] ] ϱ ) [ [ V ] ] ϱ ; [ [ H ] ] ϱ (EC-App) ⇝ [ [ M ] ] ϱ [ [ [ V ] ] ϱ / x ] ; [ [ H ] ] ϱ (Lemma B.11, substitution) = [ [ M [ V / x ] ] ] ϱ ; [ [ H ] ] ϱ
Case EC-IfT: We have H ; if true then M else N ⇝ M ; H \mathcal{H}\mathbin{;} \text{if true then }M\text{ else }N \leadsto M\mathbin{;} \mathcal{H} H ; if true then M else N ⇝ M ; H and one of either of the following derivations by premise (i):
(1a) ⋯ Γ ; Π ; Φ 2 ⊢ M : A ! M u t Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ if true then M else N : A ! M u t T C - I f \begin{array}{c}
\text{(1a)}\\[2pt]
\cdots\qquad\dfrac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{2}\vdash M:A\ !\ \mathrm{Mut}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1}\bowtie\Phi_{2}\vdash\text{if true then }M\text{ else }N:A\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}If}
\end{array} (1a) ⋯ Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ if true then M else N : A ! Mut Γ ; Π ; Φ 2 ⊢ M : A ! Mut TC - If
(1b) ⋯ Γ ; Π ; Φ 2 ⊢ M : A ! P u r e Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ if true then M else N : A ! P u r e T C - I f Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ if true then M else N : A ! P u r e Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ if true then M else N : A ! M u t T C - S u b \begin{array}{c}
\text{(1b)}\\[2pt]
\cdots\qquad\dfrac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{2}\vdash M:A\ !\ \mathrm{Pure}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1}\bowtie\Phi_{2}\vdash\text{if true then }M\text{ else }N:A\ !\ \mathrm{Pure}}\ \mathrm{TC\text{-}If}\\[6pt]
\dfrac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1}\bowtie\Phi_{2}\vdash\text{if true then }M\text{ else }N:A\ !\ \mathrm{Pure}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1}\bowtie\Phi_{2}\vdash\text{if true then }M\text{ else }N:A\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Sub}
\end{array} (1b) ⋯ Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ if true then M else N : A ! Pure Γ ; Π ; Φ 2 ⊢ M : A ! Pure TC - If Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ if true then M else N : A ! Mut Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ if true then M else N : A ! Pure TC - Sub
TC-Sub on (1a) gives us (1b), so it suffices to show the conclusions given (1b).
Conclusion (iii-a) is given by Lemma A.10 (Φ \Phi Φ -weakening) on (1b).
Conclusion (iv) follows from premise (ii) and the fact that ids ( M ) ⊆ ids ( M ) ∪ ids ( N ) \operatorname{ids}(M) \subseteq\operatorname{ids}(M) \cup\operatorname{ids}(N) ids ( M ) ⊆ ids ( M ) ∪ ids ( N ) .
We show conclusion (v) as follows:
⟦ H ⟧ ϱ ; ⟦ if true then M else N ⟧ ϱ (def. of translation) = if true then ⟦ M ⟧ ϱ else ⟦ N ⟧ ϱ ; ⟦ H ⟧ ϱ (EC-IfT) ⇝ ⟦ M ⟧ ϱ ; ⟦ H ⟧ ϱ \begin{aligned}
\llbracket\mathcal{H}\rrbracket_{\varrho}\mathbin{;} \llbracket\text{if true then }M\text{ else }N\rrbracket_{\varrho}\\
\text{(def. of translation)}\quad=\text{if true then }\llbracket M\rrbracket_{\varrho}\text{ else }\llbracket N\rrbracket_{\varrho}\mathbin{;} \llbracket\mathcal{H}\rrbracket_{\varrho}\\
\text{(EC-IfT)}\quad\leadsto\llbracket M\rrbracket_{\varrho}\mathbin{;} \llbracket\mathcal{H}\rrbracket_{\varrho}
\end{aligned} [ [ H ] ] ϱ ; [ [ if true then M else N ] ] ϱ (def. of translation) = if true then [ [ M ] ] ϱ else [ [ N ] ] ϱ ; [ [ H ] ] ϱ (EC-IfT) ⇝ [ [ M ] ] ϱ ; [ [ H ] ] ϱ
Case EC-IfF is shown analogously to the above case.
Case EC-Fst: We have H ; fst ( V , W ) ⇝ val V ; H \mathcal{H}\mathbin{;} \operatorname{fst}(V,W) \leadsto\operatorname{val}\ V\mathbin{;} \mathcal{H} H ; fst ( V , W ) ⇝ val V ; H and
(1) (2) Γ ; Π ; Φ 1 ⊢ V : A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B Γ ; Π ; Φ 2 ⊢ W : B Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B T V - P a i r Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ fst ( V , W ) : A ! P u r e T C - F s t Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ fst ( V , W ) : A ! P u r e Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ fst ( V , W ) : A ! M u t T C - S u b \begin{array}{c}
\text{(1)}\qquad\text{(2)}\\[2pt]
\dfrac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1}\vdash V:A}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1}\bowtie\Phi_{2}\vdash(V,W):A\times B}\quad
\dfrac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{2}\vdash W:B}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1}\bowtie\Phi_{2}\vdash(V,W):A\times B}\ \mathrm{TV\text{-}Pair}\\[8pt]
\dfrac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1}\bowtie\Phi_{2}\vdash(V,W):A\times B}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1}\bowtie\Phi_{2}\vdash\operatorname{fst}(V,W):A\ !\ \mathrm{Pure}}\ \mathrm{TC\text{-}Fst}\\[8pt]
\dfrac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1}\bowtie\Phi_{2}\vdash\operatorname{fst}(V,W):A\ !\ \mathrm{Pure}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1}\bowtie\Phi_{2}\vdash\operatorname{fst}(V,W):A\ !\ \mathrm{Mut}}\ \mathrm{TC\text{-}Sub}
\end{array} (1) (2) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B Γ ; Π ; Φ 1 ⊢ V : A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B Γ ; Π ; Φ 2 ⊢ W : B TV - Pair Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ fst ( V , W ) : A ! Pure Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( V , W ) : A × B TC - Fst Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ fst ( V , W ) : A ! Mut Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ fst ( V , W ) : A ! Pure TC - Sub
By Lemma A.4 (unrestriction) on (2), we get (3) that Succ ( Φ 2 ) \operatorname{Succ}(\Phi_{2}) Succ ( Φ 2 ) .
By Lemma A.9 (Φ \Phi Φ -weakening) on (1) and (3), we get (4) that Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : A \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1}\bowtie\Phi_{2}\vdash V:A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : A .
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : A ( 4 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ val V : A ! P u r e TC-Val Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ val V : A ! M u t TC-Sub \begin{aligned}
&\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \vdash V : A \qquad(4)\\
&\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{val} V : A \mathbin{!} \mathrm{Pure} \qquad\text{TC-Val}\\
&\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{val} V : A \mathbin{!} \mathrm{Mut} \qquad\text{TC-Sub}
\end{aligned} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : A ( 4 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ val V : A ! Pure TC-Val Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ val V : A ! Mut TC-Sub
Conclusion (iv) follows from premise (ii) and the fact that ids ( V ) ⊆ ids ( V ) ∪ ids ( W ) \operatorname{ids}(V) \subseteq\operatorname{ids}(V) \cup\operatorname{ids}(W) ids ( V ) ⊆ ids ( V ) ∪ ids ( W ) .
We show conclusion (v) as follows:
⟦ H ⟧ ϱ ; ⟦ fst ( V , W ) ⟧ ϱ = def. of translation fst ( ⟦ V ⟧ ϱ , ⟦ W ⟧ ϱ ) ; ⟦ H ⟧ ϱ ⇝ EC-Fst val ⟦ V ⟧ ϱ ; ⟦ H ⟧ ϱ = def. of translation ⟦ val V ⟧ ϱ ; ⟦ H ⟧ ϱ \begin{aligned}
\llbracket\mathcal{H} \rrbracket_{\varrho} \mathbin{;} \llbracket\operatorname{fst}(V,W) \rrbracket_{\varrho}\\
\mathrel{\stackrel{\text{def. of translation}}{=}} \operatorname{fst}(\llbracket V \rrbracket_{\varrho},\llbracket W \rrbracket_{\varrho}) \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho}\\
\mathrel{\stackrel{\text{EC-Fst}}{\rightsquigarrow}} \operatorname{val}\llbracket V \rrbracket_{\varrho} \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho}\\
\mathrel{\stackrel{\text{def. of translation}}{=}} \llbracket\operatorname{val} V \rrbracket_{\varrho} \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho}
\end{aligned} [ [ H ] ] ϱ ; [ [ fst ( V , W ) ] ] ϱ = def. of translation fst ( [ [ V ] ] ϱ , [ [ W ] ] ϱ ) ; [ [ H ] ] ϱ ⇝ EC-Fst val [ [ V ] ] ϱ ; [ [ H ] ] ϱ = def. of translation [ [ val V ] ] ϱ ; [ [ H ] ] ϱ
Case EC-Snd is shown analogously to the above case.
Case EC-FdN: We have H ; fold V 1 V 2 [ ] ⇝ val V 2 ; H \mathcal{H} \mathbin{;} \operatorname{fold}\ V_{1}\ V_{2}\ [] \rightsquigarrow\operatorname{val}\ V_{2} \mathbin{;} \mathcal{H} H ; fold V 1 V 2 [ ] ⇝ val V 2 ; H and
Γ ; Π ; Φ 1 ⊢ V 1 : A → M u t B → M u t B ( 1 a ) Γ ; Π ; Φ 2 ⊢ V 2 : B ( 2 ) Γ ; Π ; Φ 3 ⊢ [ ] : List A ( 3 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ fold V 1 V 2 [ ] : B ! P u r e TC-Fold \begin{aligned}
&\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \vdash V_{1} : A \xrightarrow{\mathrm{Mut}} B \xrightarrow{\mathrm{Mut}} B && (1a)\\
&\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{2} \vdash V_{2} : B && (2)\\
&\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{3} \vdash[] : \operatorname{List} A && (3)\\
&\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \bowtie\Phi_{3} \vdash\operatorname{fold}\ V_{1}\ V_{2}\ [] : B \mathbin{!} \mathrm{Pure} && \text{TC-Fold}
\end{aligned} Γ ; Π ; Φ 1 ⊢ V 1 : A Mut B Mut B Γ ; Π ; Φ 2 ⊢ V 2 : B Γ ; Π ; Φ 3 ⊢ [ ] : List A Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ fold V 1 V 2 [ ] : B ! Pure ( 1 a ) ( 2 ) ( 3 ) TC-Fold
Γ ; Π ; Φ 1 ⊢ V 1 : A → P u r e B → P u r e B ( 1 b ) Γ ; Π ; Φ 2 ⊢ V 2 : B ( 2 ) Γ ; Π ; Φ 3 ⊢ [ ] : List A ( 3 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ fold V 1 V 2 [ ] : B ! P u r e TC-Fold Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ fold V 1 V 2 [ ] : B ! M u t TC-Sub \begin{aligned}
&\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \vdash V_{1} : A \xrightarrow{\mathrm{Pure}} B \xrightarrow{\mathrm{Pure}} B && (1b)\\
&\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{2} \vdash V_{2} : B && (2)\\
&\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{3} \vdash[] : \operatorname{List} A && (3)\\
&\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \bowtie\Phi_{3} \vdash\operatorname{fold}\ V_{1}\ V_{2}\ [] : B \mathbin{!} \mathrm{Pure} && \text{TC-Fold}\\
&\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \bowtie\Phi_{3} \vdash\operatorname{fold}\ V_{1}\ V_{2}\ [] : B \mathbin{!} \mathrm{Mut} && \text{TC-Sub}
\end{aligned} Γ ; Π ; Φ 1 ⊢ V 1 : A Pure B Pure B Γ ; Π ; Φ 2 ⊢ V 2 : B Γ ; Π ; Φ 3 ⊢ [ ] : List A Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ fold V 1 V 2 [ ] : B ! Pure Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ fold V 1 V 2 [ ] : B ! Mut ( 1 b ) ( 2 ) ( 3 ) TC-Fold TC-Sub
By Lemma A.4 (unrestriction) on either of (1a) or (1b) as well as (3), we get (4) that Succ ( Φ 1 ) \operatorname{Succ}(\Phi_{1}) Succ ( Φ 1 ) and (5) that Succ ( Φ 3 ) \operatorname{Succ}(\Phi_{3}) Succ ( Φ 3 ) , respectively.
By Lemma A.9 (Φ \Phi Φ -weakening) on (2) using (4) and (5), we get (6) that Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ V 2 : B \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \bowtie\Phi_{3} \vdash V_{2} : B Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ V 2 : B .
We derive conclusion (iii-a) as follows:
Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ V 2 : B ( 6 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ val V 2 : B ! P u r e TC-Val \begin{aligned}
&\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \bowtie\Phi_{3} \vdash V_{2} : B \qquad(6)\\
&\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \bowtie\Phi_{3} \vdash\operatorname{val} V_{2} : B \mathbin{!} \mathrm{Pure} \qquad\text{TC-Val}
\end{aligned} Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ V 2 : B ( 6 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⊢ val V 2 : B ! Pure TC-Val
By premise (ii), we have Π ; ids ( V 2 ) ∪ ids ( H ) ⊨ ϱ \Pi\mathbin{;} \operatorname{ids}(V_{2}) \cup\operatorname{ids}(\mathcal{H}) \models\varrho Π ; ids ( V 2 ) ∪ ids ( H ) ⊨ ϱ , which satisfies conclusion (iv).
We show conclusion (v) as follows:
⟦ H ⟧ ϱ ; ⟦ fold V 1 V 2 [ ] ⟧ ϱ = def. of translation fold ⟦ V 1 ⟧ ϱ ⟦ V 2 ⟧ ϱ [ ] ; ⟦ H ⟧ ϱ ⇝ EC-FdN val ⟦ V 2 ⟧ ϱ ; ⟦ H ⟧ ϱ = def. of translation ⟦ val V 2 ⟧ ϱ ; ⟦ H ⟧ ϱ \begin{aligned}
\llbracket\mathcal{H} \rrbracket_{\varrho} \mathbin{;} \llbracket\operatorname{fold}\ V_{1}\ V_{2}\ [] \rrbracket_{\varrho}\\
\mathrel{\stackrel{\text{def. of translation}}{=}} \operatorname{fold}\ \llbracket V_{1} \rrbracket_{\varrho}\ \llbracket V_{2} \rrbracket_{\varrho}\ [] \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho}\\
\mathrel{\stackrel{\text{EC-FdN}}{\rightsquigarrow}} \operatorname{val}\llbracket V_{2} \rrbracket_{\varrho} \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho}\\
\mathrel{\stackrel{\text{def. of translation}}{=}} \llbracket\operatorname{val} V_{2} \rrbracket_{\varrho} \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho}
\end{aligned} [ [ H ] ] ϱ ; [ [ fold V 1 V 2 [ ] ] ] ϱ = def. of translation fold [ [ V 1 ] ] ϱ [ [ V 2 ] ] ϱ [ ] ; [ [ H ] ] ϱ ⇝ EC-FdN val [ [ V 2 ] ] ϱ ; [ [ H ] ] ϱ = def. of translation [ [ val V 2 ] ] ϱ ; [ [ H ] ] ϱ
Case EC-FdC: We have H \mathcal{H} H ; fold V 1 V 2 ( V h : : V t ) ⇝ V 1 V h ( fold V 1 V 2 V t ) \operatorname{fold}\ V_1\ V_2\ (V_h :: V_t) \leadsto V_1\ V_h\ (\operatorname{fold}\ V_1\ V_2\ V_t) fold V 1 V 2 ( V h :: V t ) ⇝ V 1 V h ( fold V 1 V 2 V t ) ; H \mathcal{H} H , whose right-hand term desugars to let x = V 1 V h in let y = fold V 1 V 2 V t in x y \operatorname{let}\ x = V_1\ V_h\ \operatorname{in}\ \operatorname{let}\ y = \operatorname{fold}\ V_1\ V_2\ V_t\ \operatorname{in}\ x\ y let x = V 1 V h in let y = fold V 1 V 2 V t in x y . Conclusion (ii) is immediate, and we also have either:
Γ ; Π ; Φ 3 ⊢ V h : A Γ ; Π ; Φ 4 ⊢ V t : List A Γ ; Π ; Φ 3 ⋈ Φ 4 ⊢ V h : : V t : List A Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⋈ Φ 4 ⊢ fold V 1 V 2 ( V h : : V t ) : B ! Mut TC-Fold \begin{gathered}
\frac{\Gamma;\Pi;\Phi_3 \vdash V_h:A \quad\Gamma;\Pi;\Phi_4 \vdash V_t:\operatorname{List}\ A}{\Gamma;\Pi;\Phi_3 \bowtie\Phi_4 \vdash V_h :: V_t:\operatorname{List}\ A}\\
\frac{\Gamma;\Pi;\Phi_1 \bowtie\Phi_2 \bowtie\Phi_3 \bowtie\Phi_4 \vdash\operatorname{fold}\ V_1\ V_2\ (V_h :: V_t):B\ !\ \operatorname{Mut}}{\operatorname{TC-Fold}}
\end{gathered} Γ ; Π ; Φ 3 ⋈ Φ 4 ⊢ V h :: V t : List A Γ ; Π ; Φ 3 ⊢ V h : A Γ ; Π ; Φ 4 ⊢ V t : List A TC-Fold Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⋈ Φ 4 ⊢ fold V 1 V 2 ( V h :: V t ) : B ! Mut
(1a) (2)
Γ ; Π ; Φ 3 ⊢ V h : A Γ ; Π ; Φ 4 ⊢ V t : List A Γ ; Π ; Φ 3 ⋈ Φ 4 ⊢ V h : : V t : List A Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⋈ Φ 4 ⊢ fold V 1 V 2 ( V h : : V t ) : B ! Pure TC-Fold Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⋈ Φ 4 ⊢ fold V 1 V 2 ( V h : : V t ) : B ! Mut TC-Sub \begin{gathered}
\frac{\Gamma;\Pi;\Phi_3 \vdash V_h:A \quad\Gamma;\Pi;\Phi_4 \vdash V_t:\operatorname{List}\ A}{\Gamma;\Pi;\Phi_3 \bowtie\Phi_4 \vdash V_h :: V_t:\operatorname{List}\ A}\\
\frac{\Gamma;\Pi;\Phi_1 \bowtie\Phi_2 \bowtie\Phi_3 \bowtie\Phi_4 \vdash\operatorname{fold}\ V_1\ V_2\ (V_h :: V_t):B\ !\ \operatorname{Pure}}{\operatorname{TC-Fold}}\\
\frac{\Gamma;\Pi;\Phi_1 \bowtie\Phi_2 \bowtie\Phi_3 \bowtie\Phi_4 \vdash\operatorname{fold}\ V_1\ V_2\ (V_h :: V_t):B\ !\ \operatorname{Mut}}{\operatorname{TC-Sub}}
\end{gathered} Γ ; Π ; Φ 3 ⋈ Φ 4 ⊢ V h :: V t : List A Γ ; Π ; Φ 3 ⊢ V h : A Γ ; Π ; Φ 4 ⊢ V t : List A TC-Fold Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⋈ Φ 4 ⊢ fold V 1 V 2 ( V h :: V t ) : B ! Pure TC-Sub Γ ; Π ; Φ 1 ⋈ Φ 2 ⋈ Φ 3 ⋈ Φ 4 ⊢ fold V 1 V 2 ( V h :: V t ) : B ! Mut
(1b) (2)
where (1a), (1b), and (2) are identical to the previous case.
By Lemma A.4 (unrestriction) on (1)-(4), choosing either of (1a) or (1b) for (1), we get that Succ ( Φ i ) \operatorname{Succ}(\Phi_i) Succ ( Φ i ) for i ∈ { 1 , 2 , 3 , 4 } i \in\{1,2,3,4\} i ∈ { 1 , 2 , 3 , 4 } . It follows (5) that Succ ( Φ ) \operatorname{Succ}(\Phi) Succ ( Φ ) , where Φ = ⋈ i = 1 4 Φ i \Phi= \bowtie_{i=1}^{4}\Phi_i Φ = ⋈ i = 1 4 Φ i .
In case (1a), we derive conclusion (iii-a) by way of intermediate derivations (6)-(8) as follows, using Φ \Phi Φ intuitionistically by (5) and weakening (1)-(4) appropriately:
Γ 6 ; Π ; Φ ⊢ x : B → Mut B Γ 6 ; Π ; Φ ⊢ y : B Γ 6 ; Π ; Φ ⊢ x y : B ! Mut TV-Var TV-Var TC-App \begin{gathered}
\frac{\Gamma_6;\Pi;\Phi\vdash x:B \xrightarrow{\operatorname{Mut}} B\quad\Gamma_6;\Pi;\Phi\vdash y:B}{\Gamma_6;\Pi;\Phi\vdash x\ y:B\ !\ \operatorname{Mut}}\\
\operatorname{TV-Var}\qquad\operatorname{TV-Var}\qquad\operatorname{TC-App}
\end{gathered} Γ 6 ; Π ; Φ ⊢ x y : B ! Mut Γ 6 ; Π ; Φ ⊢ x : B Mut B Γ 6 ; Π ; Φ ⊢ y : B TV-Var TV-Var TC-App
(6)
Γ 7 ; Π ; Φ ⊢ V 1 : A → Mut B → Mut B Γ 7 ; Π ; Φ ⊢ V 2 : B Γ 7 ; Π ; Φ ⊢ V t : List A Γ 7 ; Π ; Φ ⊢ fold V 1 V 2 V t : B ! Mut \frac{\Gamma_7;\Pi;\Phi\vdash V_1:A \xrightarrow{\operatorname{Mut}} B \xrightarrow{\operatorname{Mut}} B\quad\Gamma_7;\Pi;\Phi\vdash V_2:B\quad\Gamma_7;\Pi;\Phi\vdash V_t:\operatorname{List}\ A}{\Gamma_7;\Pi;\Phi\vdash\operatorname{fold}\ V_1\ V_2\ V_t:B\ !\ \operatorname{Mut}} Γ 7 ; Π ; Φ ⊢ fold V 1 V 2 V t : B ! Mut Γ 7 ; Π ; Φ ⊢ V 1 : A Mut B Mut B Γ 7 ; Π ; Φ ⊢ V 2 : B Γ 7 ; Π ; Φ ⊢ V t : List A
(7) TC-Fold \operatorname{TC-Fold} TC-Fold
[ ( 7 ) , Γ 7 = Γ 8 ] [ ( 6 ) , Γ 6 = Γ 8 , y : B ] [(7),\ \Gamma_7=\Gamma_8]\quad[(6),\ \Gamma_6=\Gamma_8,\ y:B] [( 7 ) , Γ 7 = Γ 8 ] [( 6 ) , Γ 6 = Γ 8 , y : B ]
Γ 8 ; Π ; Φ ⊢ let y = fold V 1 V 2 V t in ⋯ : B ! Mut TC-Let \frac{\Gamma_8;\Pi;\Phi\vdash\operatorname{let}\ y=\operatorname{fold}\ V_1\ V_2\ V_t\ \operatorname{in}\ \cdots:B\ !\ \operatorname{Mut}}{\operatorname{TC-Let}} TC-Let Γ 8 ; Π ; Φ ⊢ let y = fold V 1 V 2 V t in ⋯ : B ! Mut
(8)
Γ ; Π ; Φ ⊢ V 1 : A → Mut B → Mut E Γ ; Π ; Φ ⊢ V h : A Γ ; Π ; Φ ⊢ V 1 V h : B → Mut B ! Mut \frac{\Gamma;\Pi;\Phi\vdash V_1:A \xrightarrow{\operatorname{Mut}} B \xrightarrow{\operatorname{Mut}} E\quad\Gamma;\Pi;\Phi\vdash V_h:A}{\Gamma;\Pi;\Phi\vdash V_1\ V_h:B \xrightarrow{\operatorname{Mut}} B\ !\ \operatorname{Mut}} Γ ; Π ; Φ ⊢ V 1 V h : B Mut B ! Mut Γ ; Π ; Φ ⊢ V 1 : A Mut B Mut E Γ ; Π ; Φ ⊢ V h : A
(1) (3) TC-App \operatorname{TC-App} TC-App
[ ( 8 ) , Γ 8 = Γ , x : B → Mut B ] [(8),\ \Gamma_8=\Gamma,\ x:B \xrightarrow{\operatorname{Mut}} B] [( 8 ) , Γ 8 = Γ , x : B Mut B ]
Γ ; Π ; Φ ⊢ let x = V 1 V h in ⋯ : B ! Mut TC-Let \frac{\Gamma;\Pi;\Phi\vdash\operatorname{let}\ x=V_1\ V_h\ \operatorname{in}\ \cdots:B\ !\ \operatorname{Mut}}{\operatorname{TC-Let}} TC-Let Γ ; Π ; Φ ⊢ let x = V 1 V h in ⋯ : B ! Mut
Γ 9 ; Π ; Φ ⊢ x : B Γ 9 ; Π ; Φ ⊢ y : B Γ 9 ; Π ; Φ ⊢ x y : B ! P u r e T V - V a r \frac{\Gamma_9;\Pi;\Phi\vdash x:B \qquad\Gamma_9;\Pi;\Phi\vdash y:B}{\Gamma_9;\Pi;\Phi\vdash xy:B\mathbin{!}\mathrm{Pure}}\ \mathrm{TV\text{-}Var} Γ 9 ; Π ; Φ ⊢ x y : B ! Pure Γ 9 ; Π ; Φ ⊢ x : B Γ 9 ; Π ; Φ ⊢ y : B TV - Var
Γ 10 ; Π ; Φ ⊢ V 1 : A → P u r e B → P u r e B Γ 10 ; Π ; Φ ⊢ V 2 : B Γ 10 ; Π ; Φ ⊢ V t : L i s t A Γ 10 ; Π ; Φ ⊢ f o l d V 1 V 2 V t : B ! P u r e T C - F o l d \frac{\Gamma_{10};\Pi;\Phi\vdash V_1:A\xrightarrow{\mathrm{Pure}}B\xrightarrow{\mathrm{Pure}}B \qquad\Gamma_{10};\Pi;\Phi\vdash V_2:B \qquad\Gamma_{10};\Pi;\Phi\vdash V_t:\mathrm{List}\ A}{\Gamma_{10};\Pi;\Phi\vdash\mathrm{fold}\ V_1\ V_2\ V_t:B\mathbin{!}\mathrm{Pure}}\ \mathrm{TC\text{-}Fold} Γ 10 ; Π ; Φ ⊢ fold V 1 V 2 V t : B ! Pure Γ 10 ; Π ; Φ ⊢ V 1 : A Pure B Pure B Γ 10 ; Π ; Φ ⊢ V 2 : B Γ 10 ; Π ; Φ ⊢ V t : List A TC - Fold
[ ( 10 ) , Γ 10 = Γ 11 ] [ ( 9 ) , Γ 9 = Γ 11 , y : B ] Γ 11 ; Π ; Φ ⊢ l e t y = f o l d V 1 V 2 V t i n ⋯ : B ! P u r e T C - L e t \frac{[(10),\ \Gamma_{10}=\Gamma_{11}] \qquad[(9),\ \Gamma_9=\Gamma_{11},\ y:B]}{\Gamma_{11};\Pi;\Phi\vdash\mathrm{let}\ y=\mathrm{fold}\ V_1\ V_2\ V_t\ \mathrm{in}\ \cdots:B\mathbin{!}\mathrm{Pure}}\ \mathrm{TC\text{-}Let} Γ 11 ; Π ; Φ ⊢ let y = fold V 1 V 2 V t in ⋯ : B ! Pure [( 10 ) , Γ 10 = Γ 11 ] [( 9 ) , Γ 9 = Γ 11 , y : B ] TC - Let
Γ ; Π ; Φ ⊢ V 1 : A → P u r e B → P u r e E Γ ; Π ; Φ ⊢ V h : A Γ ; Π ; Φ ⊢ V 1 V h : B → P u r e B ! P u r e T C - A p p \frac{\Gamma;\Pi;\Phi\vdash V_1:A\xrightarrow{\mathrm{Pure}}B\xrightarrow{\mathrm{Pure}}E \qquad\Gamma;\Pi;\Phi\vdash V_h:A}{\Gamma;\Pi;\Phi\vdash V_1V_h:B\xrightarrow{\mathrm{Pure}}B\mathbin{!}\mathrm{Pure}}\ \mathrm{TC\text{-}App} Γ ; Π ; Φ ⊢ V 1 V h : B Pure B ! Pure Γ ; Π ; Φ ⊢ V 1 : A Pure B Pure E Γ ; Π ; Φ ⊢ V h : A TC - App
[ ( 11 ) , Γ 11 = Γ , x : B → P u r e B ] Γ ; Π ; Φ ⊢ l e t x = V 1 V h i n ⋯ : B ! P u r e T C - L e t \frac{[(11),\ \Gamma_{11}=\Gamma,\ x:B\xrightarrow{\mathrm{Pure}}B]}{\Gamma;\Pi;\Phi\vdash\mathrm{let}\ x=V_1V_h\ \mathrm{in}\ \cdots:B\mathbin{!}\mathrm{Pure}}\ \mathrm{TC\text{-}Let} Γ ; Π ; Φ ⊢ let x = V 1 V h in ⋯ : B ! Pure [( 11 ) , Γ 11 = Γ , x : B Pure B ] TC - Let
Γ ; Π ; Φ ⊢ l e t x = V 1 V h i n ⋯ : B ! P u r e Γ ; Π ; Φ ⊢ l e t x = V 1 V h i n ⋯ : B ! M u t T C - S u b \frac{\Gamma;\Pi;\Phi\vdash\mathrm{let}\ x=V_1V_h\ \mathrm{in}\ \cdots:B\mathbin{!}\mathrm{Pure}}{\Gamma;\Pi;\Phi\vdash\mathrm{let}\ x=V_1V_h\ \mathrm{in}\ \cdots:B\mathbin{!}\mathrm{Mut}}\ \mathrm{TC\text{-}Sub} Γ ; Π ; Φ ⊢ let x = V 1 V h in ⋯ : B ! Mut Γ ; Π ; Φ ⊢ let x = V 1 V h in ⋯ : B ! Pure TC - Sub
By premise (ii), we have Π ; ids ( V 1 ) ∪ ids ( V 2 ) ∪ ids ( V h ) ∪ ids ( V t ) ∪ ids ( H ) ⊨ ϱ \Pi;\operatorname{ids}(V_1)\cup\operatorname{ids}(V_2)\cup\operatorname{ids}(V_h)\cup\operatorname{ids}(V_t)\cup\operatorname{ids}(\mathcal{H})\models\varrho Π ; ids ( V 1 ) ∪ ids ( V 2 ) ∪ ids ( V h ) ∪ ids ( V t ) ∪ ids ( H ) ⊨ ϱ , which satisfies conclusion (iv).
We show conclusion (v) as follows:
⟦ H ⟧ ϱ ; ⟦ f o l d V 1 V 2 ( V h : : V t ) ⟧ ϱ \llbracket\mathcal{H}\rrbracket_{\varrho};\llbracket\mathrm{fold}\ V_1\ V_2\ (V_h::V_t)\rrbracket_{\varrho} [ [ H ] ] ϱ ; [ [ fold V 1 V 2 ( V h :: V t ) ] ] ϱ
(def. of translation)
= f o l d ⟦ V 1 ⟧ ϱ ⟦ V 2 ⟧ ϱ ( ⟦ V h ⟧ ϱ : : ⟦ V t ⟧ ϱ ) ; ⟦ H ⟧ ϱ =\mathrm{fold}\ \llbracket V_1\rrbracket_{\varrho}\ \llbracket V_2\rrbracket_{\varrho}\ (\llbracket V_h\rrbracket_{\varrho}::\llbracket V_t\rrbracket_{\varrho});\llbracket\mathcal{H}\rrbracket_{\varrho} = fold [ [ V 1 ] ] ϱ [ [ V 2 ] ] ϱ ( [ [ V h ] ] ϱ :: [ [ V t ] ] ϱ ) ; [ [ H ] ] ϱ
(EC-FdC)
⇝ ⟦ V 1 ⟧ ϱ ⟦ V h ⟧ ϱ ( f o l d ⟦ V 1 ⟧ ϱ ⟦ V 2 ⟧ ϱ ⟦ V t ⟧ ϱ ) ; ⟦ H ⟧ ϱ \rightsquigarrow\llbracket V_1\rrbracket_{\varrho}\llbracket V_h\rrbracket_{\varrho}\bigl(\mathrm{fold}\ \llbracket V_1\rrbracket_{\varrho}\ \llbracket V_2\rrbracket_{\varrho}\ \llbracket V_t\rrbracket_{\varrho}\bigr);\llbracket\mathcal{H}\rrbracket_{\varrho} ⇝ [ [ V 1 ] ] ϱ [ [ V h ] ] ϱ ( fold [ [ V 1 ] ] ϱ [ [ V 2 ] ] ϱ [ [ V t ] ] ϱ ) ; [ [ H ] ] ϱ
(def. of translation)
= ⟦ V 1 V h ( f o l d V 1 V 2 V t ) ⟧ ϱ ; ⟦ H ⟧ ϱ =\llbracket V_1V_h(\mathrm{fold}\ V_1\ V_2\ V_t)\rrbracket_{\varrho};\llbracket\mathcal{H}\rrbracket_{\varrho} = [ [ V 1 V h ( fold V 1 V 2 V t ) ] ] ϱ ; [ [ H ] ] ϱ
Case EC-AppSet: We have H ; s e t p ℓ V ⇝ val ( ) ; H ′ \mathcal{H};\mathrm{set}^{\ell}_{p}\ V\rightsquigarrow\operatorname{val}();\mathcal{H}' H ; set p ℓ V ⇝ val ( ) ; H ′ for H ′ = H ∣ H [ p ] . st [ ℓ ] ↦ V \mathcal{H}'=\mathcal{H}\mid\mathcal{H}[p].\operatorname{st}[\ell]\mapsto V H ′ = H ∣ H [ p ] . st [ ℓ ] ↦ V and H [ p ] . rerender ↦ t t \mathcal{H}[p].\operatorname{rerender}\mapsto\mathrm{tt} H [ p ] . rerender ↦ tt , and
ℓ : A ∈ Π [ p ] Succ ( Φ 1 ) Γ ; Π ; Φ 1 ⊢ s e t p ℓ : A → M u t 1 T V - S e t t e r \frac{\ell:A\in\Pi[p] \qquad\operatorname{Succ}(\Phi_1)}{\Gamma;\Pi;\Phi_1\vdash\mathrm{set}^{\ell}_{p}:A\xrightarrow{\mathrm{Mut}}1}\ \mathrm{TV\text{-}Setter} Γ ; Π ; Φ 1 ⊢ set p ℓ : A Mut 1 ℓ : A ∈ Π [ p ] Succ ( Φ 1 ) TV - Setter
Γ ; Π ; Φ 1 ⊢ s e t p ℓ : A → M u t 1 Γ ; Π ; Φ 2 ⊢ V : A Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ s e t p ℓ V : 1 ! M u t T C - A p p \frac{\Gamma;\Pi;\Phi_1\vdash\mathrm{set}^{\ell}_{p}:A\xrightarrow{\mathrm{Mut}}1 \qquad\Gamma;\Pi;\Phi_2\vdash V:A}{\Gamma;\Pi;\Phi_1\mathbin{\Join}\Phi_2\vdash\mathrm{set}^{\ell}_{p}\ V:1\mathbin{!}\mathrm{Mut}}\ \mathrm{TC\text{-}App} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ set p ℓ V : 1 ! Mut Γ ; Π ; Φ 1 ⊢ set p ℓ : A Mut 1 Γ ; Π ; Φ 2 ⊢ V : A TC - App
(1) and premise (i-b) give us (4) that Γ ; Π ; Φ 3 ⊢ H [ p ] . st [ ℓ ] : A \Gamma;\Pi;\Phi_3\vdash\mathcal{H}[p].\operatorname{st}[\ell]:A Γ ; Π ; Φ 3 ⊢ H [ p ] . st [ ℓ ] : A for Φ H = Φ 3 ⋈ Φ 4 \Phi_{\mathcal{H}}=\Phi_3\mathbin{\Join}\Phi_4 Φ H = Φ 3 ⋈ Φ 4 .
By Lemma A.4 (unrestriction) on (3), we know (5) that Succ ( Φ 2 ) \operatorname{Succ}(\Phi_2) Succ ( Φ 2 ) .
Choose Φ N = Φ M \Phi_N=\Phi_M Φ N = Φ M , Φ H ′ = Φ H \Phi_{\mathcal{H}}'=\Phi_{\mathcal{H}} Φ H ′ = Φ H , Φ = Φ H ⋈ Φ 2 \Phi=\Phi_{\mathcal{H}}\mathbin{\Join}\Phi_2 Φ = Φ H ⋈ Φ 2 , and Π ′ = Π \Pi'=\Pi Π ′ = Π , trivializing conclusion (ii). By (5) and Lemma A.8 (unrestriction) on Φ H \Phi_{\mathcal{H}} Φ H , Φ H ′ \Phi_{\mathcal{H}}' Φ H ′ is defined.
By (5), ( Φ 1 ⋈ Φ 2 ) ⋈ ( Φ H ⋈ Φ 2 ) = ( Φ 1 ⋈ Φ 2 ) ⋈ Φ H (\Phi_1\mathbin{\Join}\Phi_2)\mathbin{\Join}(\Phi_{\mathcal{H}}\mathbin{\Join}\Phi_2)=(\Phi_1\mathbin{\Join}\Phi_2)\mathbin{\Join}\Phi_{\mathcal{H}} ( Φ 1 ⋈ Φ 2 ) ⋈ ( Φ H ⋈ Φ 2 ) = ( Φ 1 ⋈ Φ 2 ) ⋈ Φ H , satisfying conclusion (i).
Clearly Succ ( Φ 3 ) \operatorname{Succ}(\Phi_3) Succ ( Φ 3 ) by Lemma A.8 , so we weaken (3) by Φ 3 \Phi_3 Φ 3 (Lemma A.9 ) to get that Γ ; Π ; Φ 2 ⋈ Φ 3 ⊢ V : A \Gamma;\Pi;\Phi_2\mathbin{\Join}\Phi_3\vdash V:A Γ ; Π ; Φ 2 ⋈ Φ 3 ⊢ V : A . It then follows from premise (i-b) that Γ ; Π ; ( Φ 2 ⋈ Φ 3 ) ⋈ Φ 4 ⊨ H \Gamma;\Pi;(\Phi_2\mathbin{\Join}\Phi_3)\mathbin{\Join}\Phi_4\models\mathcal{H} Γ ; Π ; ( Φ 2 ⋈ Φ 3 ) ⋈ Φ 4 ⊨ H , i.e. conclusion (iii-b) holds.
Succ ( Φ 1 ⋈ Φ 2 ) ‾ ( 2 ) and ( 5 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( ) : 1 ‾ TV-Unit Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ val ( ) : 1 ! Pure TC-Val Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ val ( ) : 1 ! Mut TC-Sub \frac{\overline{\operatorname{Succ}(\Phi_1 \bowtie\Phi_2)}\quad(2)\text{ and }(5)}
{\frac{\overline{\Gamma\,;\,\Pi\,;\,\Phi_1 \bowtie\Phi_2 \vdash() : 1}\quad\text{TV-Unit}}
{\Gamma\,;\,\Pi\,;\,\Phi_1 \bowtie\Phi_2 \vdash\operatorname{val} () : 1\mathbin{!}\operatorname{Pure}}\quad\text{TC-Val}}
{\Gamma\,;\,\Pi\,;\,\Phi_1 \bowtie\Phi_2 \vdash\operatorname{val} () : 1\mathbin{!}\operatorname{Mut}}\quad\text{TC-Sub} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ val ( ) : 1 ! Pure Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ( ) : 1 TV-Unit TC-Val Succ ( Φ 1 ⋈ Φ 2 ) ( 2 ) and ( 5 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ val ( ) : 1 ! Mut TC-Sub
We have ids ( val ( ) ) = ∅ \operatorname{ids}(\operatorname{val} ()) = \varnothing ids ( val ( )) = ∅ , and clearly ids ( H ′ ) ⊆ ids ( H ) ∪ ids ( V ) \operatorname{ids}(\mathcal{H}') \subseteq\operatorname{ids}(\mathcal{H}) \cup\operatorname{ids}(V) ids ( H ′ ) ⊆ ids ( H ) ∪ ids ( V ) , so conclusion (iv) is given by premise (ii).
We show conclusion (v) as follows:
⟦ H ⟧ ϱ ; ⟦ set ℓ p V ⟧ ϱ = def. of translation ( λ x . ϱ ( p , ℓ ) : = x ; ϱ ( p ) : = true ) ⟦ V ⟧ ϱ ; ⟦ H ⟧ ϱ ⇝ EC-App ϱ ( p , ℓ ) : = ⟦ V ⟧ ϱ ; ϱ ( p ) : = true ; ⟦ H ⟧ ϱ ⇝ + EC-Set, EC-Val ϱ ( p ) : = true ; ⟦ H ⟧ ϱ [ ϱ ( p , ℓ ) ↦ ⟦ V ⟧ ϱ ] ⇝ EC-Set val ( ) ; ⟦ H ⟧ ϱ [ ϱ ( p , ℓ ) ↦ ⟦ V ⟧ ϱ , ϱ ( p ) ↦ true ] = def. of translation ⟦ val ( ) ⟧ ϱ ; ⟦ H ′ ⟧ ϱ \begin{aligned}
\llbracket\mathcal{H} \rrbracket_{\varrho}\,;\,\llbracket\operatorname{set}_{\ell}^{p} V \rrbracket_{\varrho}
&\mathrel{\stackrel{\text{def. of translation}}{=}} (\lambda x.\,\varrho(p,\ell) := x\,;\,\varrho(p) := \operatorname{true})\,\llbracket V \rrbracket_{\varrho}\,;\,\llbracket\mathcal{H} \rrbracket_{\varrho}\\
&\mathrel{\stackrel{\text{EC-App}}{\rightsquigarrow}} \varrho(p,\ell) := \llbracket V \rrbracket_{\varrho}\,;\,\varrho(p) := \operatorname{true}\,;\,\llbracket\mathcal{H} \rrbracket_{\varrho}\\
&\mathrel{\stackrel{\text{EC-Set, EC-Val}}{\rightsquigarrow^{+}}} \varrho(p) := \operatorname{true}\,;\,\llbracket\mathcal{H} \rrbracket_{\varrho}[\varrho(p,\ell) \mapsto\llbracket V \rrbracket_{\varrho}]\\
&\mathrel{\stackrel{\text{EC-Set}}{\rightsquigarrow}} \operatorname{val} ()\,;\,\llbracket\mathcal{H} \rrbracket_{\varrho}[\varrho(p,\ell) \mapsto\llbracket V \rrbracket_{\varrho},\varrho(p) \mapsto\operatorname{true}]\\
&\mathrel{\stackrel{\text{def. of translation}}{=}} \llbracket\operatorname{val} () \rrbracket_{\varrho}\,;\,\llbracket\mathcal{H}' \rrbracket_{\varrho}
\end{aligned} [ [ H ] ] ϱ ; [ [ set ℓ p V ] ] ϱ = def. of translation ( λ x . ϱ ( p , ℓ ) := x ; ϱ ( p ) := true ) [ [ V ] ] ϱ ; [ [ H ] ] ϱ ⇝ EC-App ϱ ( p , ℓ ) := [ [ V ] ] ϱ ; ϱ ( p ) := true ; [ [ H ] ] ϱ ⇝ + EC-Set, EC-Val ϱ ( p ) := true ; [ [ H ] ] ϱ [ ϱ ( p , ℓ ) ↦ [ [ V ] ] ϱ ] ⇝ EC-Set val ( ) ; [ [ H ] ] ϱ [ ϱ ( p , ℓ ) ↦ [ [ V ] ] ϱ , ϱ ( p ) ↦ true ] = def. of translation [ [ val ( ) ] ] ϱ ; [ [ H ′ ] ] ϱ
Case EC-Eval, ϕ = Init \phi= \operatorname{Init} ϕ = Init : We have
H ; D ⇝ Init p D ′ ; H ′ H ; ⌈ D 0 ⌉ ⇓ p Init D ⇝ Init p ⌈ D 0 ⌉ ⇓ p Init D ′ ; H ′ EC-Eval \frac{\mathcal{H}\,;\,D \mathrel{\overset{\operatorname{Init}}{\rightsquigarrow}_{p}} D'\,;\,\mathcal{H}'}
{\mathcal{H}\,;\,\left\lceil D_0\right\rceil\mathrel{\Downarrow^{\operatorname{Init}}_{p}} D \mathrel{\overset{\operatorname{Init}}{\rightsquigarrow}_{p}} \left\lceil D_0\right\rceil\mathrel{\Downarrow^{\operatorname{Init}}_{p}} D'\,;\,\mathcal{H}'}\quad\text{EC-Eval} H ; ⌈ D 0 ⌉ ⇓ p Init D ⇝ Init p ⌈ D 0 ⌉ ⇓ p Init D ′ ; H ′ H ; D ⇝ Init p D ′ ; H ′ EC-Eval
Γ ; Π ; Φ 1 ⊢ D 0 : L ⊎ Π [ p ] Γ ; Π ; Φ 2 ⊢ D : L Γ ; Π ; Φ 1 ⋈ Φ 2 , p : Init ⊢ ⌈ D 0 ⌉ ⇓ p init D : ElemInst ! Mut TC-EvalI \frac{\Gamma\,;\,\Pi\,;\,\Phi_1 \vdash D_0 : L \uplus\Pi[p]\qquad\Gamma\,;\,\Pi\,;\,\Phi_2 \vdash D : L}
{\Gamma\,;\,\Pi\,;\,\Phi_1 \bowtie\Phi_2,p:\operatorname{Init} \vdash\left\lceil D_0\right\rceil\Downarrow^{\operatorname{init}}_{p} D : \operatorname{ElemInst}\mathbin{!}\operatorname{Mut}}\quad\text{TC-EvalI} Γ ; Π ; Φ 1 ⋈ Φ 2 , p : Init ⊢ ⌈ D 0 ⌉ ⇓ p init D : ElemInst ! Mut Γ ; Π ; Φ 1 ⊢ D 0 : L ⊎ Π [ p ] Γ ; Π ; Φ 2 ⊢ D : L TC-EvalI
We are given that Φ H ⋈ Φ 1 ⋈ Φ 2 , p : Init \Phi_H \bowtie\Phi_1 \bowtie\Phi_2,p:\operatorname{Init} Φ H ⋈ Φ 1 ⋈ Φ 2 , p : Init is defined, which entails (4) p ∉ dom ( Φ H ⋈ Φ 1 ⋈ Φ 2 ) p \notin\operatorname{dom}(\Phi_H \bowtie\Phi_1 \bowtie\Phi_2) p ∈ / dom ( Φ H ⋈ Φ 1 ⋈ Φ 2 ) .
By Theorem B.28 (⇝ p Init \rightsquigarrow^{\operatorname{Init}}_{p} ⇝ p Init -simulation) on (1)–(4) and premises (i-b) and (ii), we have some Φ H ′ \Phi'_H Φ H ′ , Π ′ \Pi' Π ′ , and ϱ ′ ⊇ ϱ \varrho' \supseteq\varrho ϱ ′ ⊇ ϱ with: (5) Φ H ⋈ Φ 2 = Φ H ′ ⋈ Φ 2 \Phi_H \bowtie\Phi_2 = \Phi'_H \bowtie\Phi_2 Φ H ⋈ Φ 2 = Φ H ′ ⋈ Φ 2 , (6) Π ⊑ p : Init Π ′ \Pi\sqsubseteq_{p:\operatorname{Init}} \Pi' Π ⊑ p : Init Π ′ , (7) Γ ; Π ′ ; Φ 2 ⊢ D ′ : L ′ \Gamma\,;\,\Pi'\,;\,\Phi_2 \vdash D' : L' Γ ; Π ′ ; Φ 2 ⊢ D ′ : L ′ , (8) Γ ; Π ′ ; Φ 1 ⊢ D 0 : L ′ ⊎ Π ′ [ p ] \Gamma\,;\,\Pi'\,;\,\Phi_1 \vdash D_0 : L' \uplus\Pi'[p] Γ ; Π ′ ; Φ 1 ⊢ D 0 : L ′ ⊎ Π ′ [ p ] , (9) Γ ; Π ′ ; Φ H ′ ⊨ H ′ \Gamma\,;\,\Pi'\,;\,\Phi'_H \models\mathcal{H}' Γ ; Π ′ ; Φ H ′ ⊨ H ′ , (10) Π ′ ; ids ( D ′ ) ∪ ids ( D 0 ) ∪ ids ( H ′ ) ⊨ ϱ ′ \Pi'\,;\,\operatorname{ids}(D') \cup\operatorname{ids}(D_0) \cup\operatorname{ids}(\mathcal{H}') \models\varrho' Π ′ ; ids ( D ′ ) ∪ ids ( D 0 ) ∪ ids ( H ′ ) ⊨ ϱ ′ , and (11) ⟦ H ⟧ ϱ ; I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) ⇝ + I ⟦ D ′ ⟧ ( D 0 , p , ϱ ′ , ∅ ) ; ⟦ H ′ ⟧ ϱ ′ \llbracket\mathcal{H} \rrbracket_{\varrho}\,;\,I\llbracket D\rrbracket(D_0,p,\varrho,\varnothing) \mathrel{\rightsquigarrow^{+}} I\llbracket D'\rrbracket(D_0,p,\varrho',\varnothing)\,;\,\llbracket\mathcal{H}' \rrbracket_{\varrho'} [ [ H ] ] ϱ ; I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) ⇝ + I [ [ D ′ ] ] ( D 0 , p , ϱ ′ , ∅ ) ; [ [ H ′ ] ] ϱ ′ .
We choose this Π ′ \Pi' Π ′ , Φ H ′ \Phi'_H Φ H ′ , and ϱ ′ \varrho' ϱ ′ , and retain Φ N = Φ M = Φ 1 ⋈ Φ 2 , p : Init \Phi_N = \Phi_M = \Phi_1 \bowtie\Phi_2,p:\operatorname{Init} Φ N = Φ M = Φ 1 ⋈ Φ 2 , p : Init .
We started with Φ 1 ⋈ Φ 2 ⋈ Φ H , p : Init \Phi_1 \bowtie\Phi_2 \bowtie\Phi_H,p:\operatorname{Init} Φ 1 ⋈ Φ 2 ⋈ Φ H , p : Init as defined. By (5), we know (12) that Φ 1 ⋈ Φ 2 ⋈ Φ H ′ , p : Init \Phi_1 \bowtie\Phi_2 \bowtie\Phi'_H,p:\operatorname{Init} Φ 1 ⋈ Φ 2 ⋈ Φ H ′ , p : Init is also defined.
Conclusion (i) follows from Lemma 4.5 (fresh Φ \Phi Φ -extension) using (5) and extending by Φ 1 , p : Init \Phi_1,p:\operatorname{Init} Φ 1 , p : Init , which is valid by (12).
(12) also lets us apply Lemma A.17 (Π \Pi Π -order preservation) on (6), extending by Φ 1 ⋈ Φ 2 ⋈ Φ H ′ \Phi_1 \bowtie\Phi_2 \bowtie\Phi'_H Φ 1 ⋈ Φ 2 ⋈ Φ H ′ , to get that Π ⊑ Φ M ⋈ Φ H ′ Π ′ \Pi\sqsubseteq\Phi_{M\bowtie\Phi'_H}\Pi' Π ⊑ Φ M ⋈ Φ H ′ Π ′ , satisfying conclusion (ii).
By choice of Π \Pi Π and Φ \Phi Φ , (9) gives conclusion (iii-b).
Lemma A.3 (Π \Pi Π -weakening) on (2) using (6), which is valid by (12), gives us (13) that Γ ; Π ′ ; Φ 1 ⊢ D 0 : L ⊎ Π [ p ] \Gamma\,;\,\Pi'\,;\,\Phi_1 \vdash D_0 : \mathcal{L} \uplus\Pi[p] Γ ; Π ′ ; Φ 1 ⊢ D 0 : L ⊎ Π [ p ] .
By (10), (13) is equivalent to (14) that Γ ; Π ′ ; Φ 1 ⊢ D 0 : L ′ ⊎ Π ′ [ p ] \Gamma\,;\,\Pi'\,;\,\Phi_1 \vdash D_0 : \mathcal{L}' \uplus\Pi'[p] Γ ; Π ′ ; Φ 1 ⊢ D 0 : L ′ ⊎ Π ′ [ p ] .
We derive conclusion (iii-a) as follows:
Γ ; Π ′ ; Φ 1 ⊢ D 0 : L ′ ⊎ Π ′ [ p ] ( 14 ) Γ ; Π ′ ; Φ 2 ⊢ D ′ : L ′ ( 6 ) Γ ; Π ′ ; Φ 1 ⋈ Φ 2 , p : I n i t ⊢ ⌈ D 0 ⌉ ↓ p I n i t D ′ : E l e m I n s t ! M u t T C - E v a l I \frac{\Gamma\,;\,\Pi'\,;\,\Phi_1 \vdash D_0 : \mathcal{L}' \uplus\Pi'[p]\ \ (14)\qquad\Gamma\,;\,\Pi'\,;\,\Phi_2 \vdash D' : \mathcal{L}'\ \ (6)}
{\Gamma\,;\,\Pi'\,;\,\Phi_1 \bowtie\Phi_2,p:\mathrm{Init} \vdash\lceil D_0\rceil\downarrow^{\mathrm{Init}}_p D' : \mathrm{ElemInst}\ !\ \mathrm{Mut}}
\quad\mathrm{TC\text{-}EvalI} Γ ; Π ′ ; Φ 1 ⋈ Φ 2 , p : Init ⊢ ⌈ D 0 ⌉ ↓ p Init D ′ : ElemInst ! Mut Γ ; Π ′ ; Φ 1 ⊢ D 0 : L ′ ⊎ Π ′ [ p ] ( 14 ) Γ ; Π ′ ; Φ 2 ⊢ D ′ : L ′ ( 6 ) TC - EvalI
⟦ H ⟧ ϱ ; ⟦ ⌈ D 0 ⌉ ↓ p I n i t D ⟧ ϱ \llbracket\mathcal{H}\rrbracket_{\varrho}\ ;\ \llbracket\lceil D_0\rceil\downarrow^{\mathrm{Init}}_p D\rrbracket_{\varrho} [ [ H ] ] ϱ ; [ [ ⌈ D 0 ⌉ ↓ p Init D ] ] ϱ
= (def. of translation) l e t r r , f , x = I ⟦ D ⟧ ( D 0 , p , ϱ , ∅ ) i n compInst ( r r , f , init x ) ; ⟦ H ⟧ ϱ \underset{\text{(def. of translation)}}{=}\ \mathop{\mathrm{let}}\ rr,f,x = I\llbracket D\rrbracket(D_0,p,\varrho,\varnothing)
\quad\mathrm{in}\ \operatorname{compInst}(rr,f,\operatorname{init}x)\ ;\ \llbracket\mathcal{H}\rrbracket_{\varrho} (def. of translation) = let r r , f , x = I [ [ D ] ] ( D 0 , p , ϱ , ∅ ) in compInst ( r r , f , init x ) ; [ [ H ] ] ϱ
⇝ l e t + (Lemma B.25, let-trans. on (11)) l e t r r , f , x = I ⟦ D ′ ⟧ ( D 0 , p , ϱ ′ , ∅ ) i n compInst ( r r , f , init x ) ; ⟦ H ′ ⟧ ϱ ′ \underset{\text{(Lemma B.25, let-trans. on (11))}}{\rightsquigarrow^{+}_{\mathrm{let}}}\ \mathop{\mathrm{let}}\ rr,f,x = I\llbracket D'\rrbracket(D_0,p,\varrho',\varnothing)
\quad\mathrm{in}\ \operatorname{compInst}(rr,f,\operatorname{init}x)\ ;\ \llbracket\mathcal{H}'\rrbracket_{\varrho'} (Lemma B.25, let-trans. on (11)) ⇝ let + let r r , f , x = I [ [ D ′ ] ] ( D 0 , p , ϱ ′ , ∅ ) in compInst ( r r , f , init x ) ; [ [ H ′ ] ] ϱ ′
= (def. of translation) ⟦ ⌈ D 0 ⌉ ↓ p I n i t D ′ ⟧ ϱ ′ ; ⟦ H ′ ⟧ ϱ ′ \underset{\text{(def. of translation)}}{=}\ \llbracket\lceil D_0\rceil\downarrow^{\mathrm{Init}}_p D'\rrbracket_{\varrho'}\ ;\ \llbracket\mathcal{H}'\rrbracket_{\varrho'} (def. of translation) = [ [ ⌈ D 0 ⌉ ↓ p Init D ′ ] ] ϱ ′ ; [ [ H ′ ] ] ϱ ′
Case EC-Eval, ϕ = S u c c \phi= \mathrm{Succ} ϕ = Succ : We have
H ; D ⇝ p S u c c D ′ ; H ′ ( 1 ) H ; ⌈ D 0 ⌉ ↓ p S u c c D ⇝ p S u c c ⌈ D 0 ⌉ ↓ p S u c c D ′ ; H ′ E C - E V A L \frac{\mathcal{H}\,;\,D \mathrel{\rightsquigarrow^{\mathrm{Succ}}_p} D'\,;\,\mathcal{H}'\quad(1)}
{\mathcal{H}\,;\,\lceil D_0\rceil\downarrow^{\mathrm{Succ}}_p D \mathrel{\rightsquigarrow^{\mathrm{Succ}}_p} \lceil D_0\rceil\downarrow^{\mathrm{Succ}}_p D'\,;\,\mathcal{H}'}
\quad\mathrm{EC\text{-}EVAL} H ; ⌈ D 0 ⌉ ↓ p Succ D ⇝ p Succ ⌈ D 0 ⌉ ↓ p Succ D ′ ; H ′ H ; D ⇝ p Succ D ′ ; H ′ ( 1 ) EC - EVAL
Γ ; Π ; Φ 1 ⊢ D 0 : Π [ p ] ( 2 ) Γ ; Π ; Φ 2 ⊢ D : L ( 3 ) L ⊆ Π [ p ] ( 4 ) ( Φ 1 ⋈ Φ 2 ) [ p ] = S u c c ( 5 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ⌈ D 0 ⌉ ↓ p S u c c D : E l e m I n s t ! M u t T C - E v a l S \frac{\Gamma\,;\,\Pi\,;\,\Phi_1 \vdash D_0 : \Pi[p]\quad(2)\qquad\Gamma\,;\,\Pi\,;\,\Phi_2 \vdash D : \mathcal{L}\quad(3)\qquad\mathcal{L} \subseteq\Pi[p]\quad(4)\qquad(\Phi_1 \bowtie\Phi_2)[p] = \mathrm{Succ}\quad(5)}
{\Gamma\,;\,\Pi\,;\,\Phi_1 \bowtie\Phi_2 \vdash\lceil D_0\rceil\downarrow^{\mathrm{Succ}}_p D : \mathrm{ElemInst}\ !\ \mathrm{Mut}}
\quad\mathrm{TC\text{-}EvalS} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ⌈ D 0 ⌉ ↓ p Succ D : ElemInst ! Mut Γ ; Π ; Φ 1 ⊢ D 0 : Π [ p ] ( 2 ) Γ ; Π ; Φ 2 ⊢ D : L ( 3 ) L ⊆ Π [ p ] ( 4 ) ( Φ 1 ⋈ Φ 2 ) [ p ] = Succ ( 5 ) TC - EvalS
By premise (iii), we have (6) that Π ; ids ( D ) ∪ ids ( H ) ⊨ ϱ \Pi\,;\,\operatorname{ids}(D) \cup\operatorname{ids}(\mathcal{H}) \models\varrho Π ; ids ( D ) ∪ ids ( H ) ⊨ ϱ .
By Theorem B.27 (⇝ p S u c c \rightsquigarrow^{\mathrm{Succ}}_p ⇝ p Succ -simulation) on (1), (3), (4), (6) and premise (i-b), we have some Φ 2 ′ \Phi'_2 Φ 2 ′ such that (6) Φ 2 ′ ⋈ Φ H = Φ 2 ⋈ Φ H \Phi'_2 \bowtie\Phi_H = \Phi_2 \bowtie\Phi_H Φ 2 ′ ⋈ Φ H = Φ 2 ⋈ Φ H , (7) Γ ; Π ; Φ 2 ′ ⊢ D ′ : L ′ \Gamma\,;\,\Pi\,;\,\Phi'_2 \vdash D' : \mathcal{L}' Γ ; Π ; Φ 2 ′ ⊢ D ′ : L ′ , (8) H ′ = H \mathcal{H}' = \mathcal{H} H ′ = H , (9) L ′ ⊆ L \mathcal{L}' \subseteq\mathcal{L} L ′ ⊆ L , (10) Π ; ids ( D ′ ) ∪ ids ( H ′ ) ⊨ ϱ \Pi\,;\,\operatorname{ids}(D') \cup\operatorname{ids}(\mathcal{H}') \models\varrho Π ; ids ( D ′ ) ∪ ids ( H ′ ) ⊨ ϱ , and (11) ⟦ H ⟧ ϱ ; S ⟦ D ⟧ ( p , ϱ , ∅ ) ⇝ + S ⟦ D ′ ⟧ ( p , ϱ , ∅ ) ; ⟦ H ⟧ ϱ \llbracket\mathcal{H}\rrbracket_{\varrho}\ ;\ S\llbracket D\rrbracket(p,\varrho,\varnothing) \rightsquigarrow^{+} S\llbracket D'\rrbracket(p,\varrho,\varnothing)\ ;\ \llbracket\mathcal{H}\rrbracket_{\varrho} [ [ H ] ] ϱ ; S [ [ D ] ] ( p , ϱ , ∅ ) ⇝ + S [ [ D ′ ] ] ( p , ϱ , ∅ ) ; [ [ H ] ] ϱ .
Choose Φ N = Φ 1 ⋈ Φ 2 ′ \Phi_N = \Phi_1 \bowtie\Phi'_2 Φ N = Φ 1 ⋈ Φ 2 ′ and Φ H ′ = Φ H \Phi'_H = \Phi_H Φ H ′ = Φ H . By Lemma A.6 (unrestriction) on (2) and (7), both S u c c ( Φ 1 ) \mathrm{Succ}(\Phi_1) Succ ( Φ 1 ) and S u c c ( Φ 2 ′ ) \mathrm{Succ}(\Phi'_2) Succ ( Φ 2 ′ ) , so Φ N \Phi_N Φ N is defined. Lemma 4.5 (fresh Φ \Phi Φ -extension) on (6) then gives us conclusion (i).
Choose Π ′ = Π \Pi' = \Pi Π ′ = Π . Conclusion (ii) is trivial, and (8) and premise (i-b) give us conclusion (iii-b).
By (4) and (9), we have (12) that L ′ ⊆ Π [ p ] \mathcal{L}' \subseteq\Pi[p] L ′ ⊆ Π [ p ] .
Γ ; Π ; Φ 1 ⊢ D 0 : Π [ p ] ( 2 ) Γ ; Π ; Φ 2 ′ ⊢ D ′ : L ′ ( 7 ) L ′ ⊆ Π [ p ] ( 12 ) ( Φ 1 ⋈ Φ 2 ′ ) [ p ] = Succ ( 13 ) Γ ; Π ; Φ 1 ⋈ Φ 2 ′ ⊢ ∣ D 0 ∣ p Succ D ′ : ElemInst ! Mut \frac{\frac{\Gamma; \Pi; \Phi_1 \vdash D_0 : \Pi[p]}{(2)} \qquad\frac{\Gamma; \Pi; \Phi'_2 \vdash D' : \mathcal{L}'}{(7)} \qquad\frac{\mathcal{L}' \subseteq\Pi[p]}{(12)} \qquad\frac{(\Phi_1 \bowtie\Phi'_2)[p] = \operatorname{Succ}}{(13)}}{\Gamma; \Pi; \Phi_1 \bowtie\Phi'_2 \vdash\lvert D_0 \rvert^{\operatorname{Succ}}_p D' : \operatorname{ElemInst}\ !\ \operatorname{Mut}} Γ ; Π ; Φ 1 ⋈ Φ 2 ′ ⊢ ∣ D 0 ∣ p Succ D ′ : ElemInst ! Mut ( 2 ) Γ ; Π ; Φ 1 ⊢ D 0 : Π [ p ] ( 7 ) Γ ; Π ; Φ 2 ′ ⊢ D ′ : L ′ ( 12 ) L ′ ⊆ Π [ p ] ( 13 ) ( Φ 1 ⋈ Φ 2 ′ ) [ p ] = Succ
⟦ H ⟧ ϱ ; ⟦ ∣ D 0 ∣ p Succ D ⟧ ϱ \llbracket\mathcal{H} \rrbracket_\varrho; \llbracket\lvert D_0 \rvert^{\operatorname{Succ}}_p D \rrbracket_\varrho [ [ H ] ] ϱ ; [ [ ∣ D 0 ∣ p Succ D ] ] ϱ
(def. of translation)
= let x = S ⟦ D ⟧ ( p , ϱ , ∅ ) in = \operatorname{let}\ x = S\llbracket D \rrbracket(p,\varrho,\varnothing)\ \operatorname{in} = let x = S [ [ D ] ] ( p , ϱ , ∅ ) in
compInst ( S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , init x ) ; ⟦ H ⟧ ϱ \operatorname{compInst}(S\llbracket D_0 \rrbracket(p,\varrho,\varnothing),\varrho(p),\operatorname{init}\ x) ; \llbracket\mathcal{H} \rrbracket_\varrho compInst ( S [ [ D 0 ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , init x ) ; [ [ H ] ] ϱ
(Lemma B.25, let-trans. on (11))
⇝ let + let x = S ⟦ D ′ ⟧ ( p , ϱ , ∅ ) in \rightsquigarrow^{+}_{\operatorname{let}}\ \operatorname{let}\ x = S\llbracket D' \rrbracket(p,\varrho,\varnothing)\ \operatorname{in} ⇝ let + let x = S [ [ D ′ ] ] ( p , ϱ , ∅ ) in
compInst ( S ⟦ D 0 ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , init x ) ; ⟦ H ⟧ ϱ \operatorname{compInst}(S\llbracket D_0 \rrbracket(p,\varrho,\varnothing),\varrho(p),\operatorname{init}\ x) ; \llbracket\mathcal{H} \rrbracket_\varrho compInst ( S [ [ D 0 ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , init x ) ; [ [ H ] ] ϱ
(def. of translation)
= ⟦ ∣ D 0 ∣ p Succ D ′ ⟧ ϱ ; ⟦ H ⟧ ϱ = \llbracket\lvert D_0 \rvert^{\operatorname{Succ}}_p D' \rrbracket_\varrho; \llbracket\mathcal{H} \rrbracket_\varrho = [ [ ∣ D 0 ∣ p Succ D ′ ] ] ϱ ; [ [ H ] ] ϱ
Case EC-EvalDone, ϕ = Init \phi= \operatorname{Init} ϕ = Init : We have
H ; ∣ D ∣ p Init val V ⇝ let x = init V in val compInst p ( ∣ D ∣ , x ) ; H \mathcal{H} ; \lvert D \rvert^{\operatorname{Init}}_p \operatorname{val}\ V \rightsquigarrow\operatorname{let}\ x = \operatorname{init}\ V\ \operatorname{in}\ \operatorname{val}\ \operatorname{compInst}_p(\lvert D \rvert,x) ; \mathcal{H} H ; ∣ D ∣ p Init val V ⇝ let x = init V in val compInst p (∣ D ∣ , x ) ; H
Γ ; Π ; Φ 1 ⊢ D 0 : ∅ ⊎ Π [ p ] ( 1 ) Γ ; Π ; Φ 2 ⊢ V : Element ( 2 ) Γ ; Π ; Φ 1 ⋈ Φ 2 , p : Init ⊢ ∣ D 0 ∣ p Init val V : ElemInst ! Mut \frac{\frac{\Gamma; \Pi; \Phi_1 \vdash D_0 : \varnothing\uplus\Pi[p]}{(1)} \qquad\frac{\Gamma; \Pi; \Phi_2 \vdash V : \operatorname{Element}}{(2)}}{\Gamma; \Pi; \Phi_1 \bowtie\Phi_2,p : \operatorname{Init} \vdash\lvert D_0 \rvert^{\operatorname{Init}}_p \operatorname{val}\ V : \operatorname{ElemInst}\ !\ \operatorname{Mut}} Γ ; Π ; Φ 1 ⋈ Φ 2 , p : Init ⊢ ∣ D 0 ∣ p Init val V : ElemInst ! Mut ( 1 ) Γ ; Π ; Φ 1 ⊢ D 0 : ∅ ⊎ Π [ p ] ( 2 ) Γ ; Π ; Φ 2 ⊢ V : Element
We choose Φ H ′ = Φ H \Phi'_H = \Phi_H Φ H ′ = Φ H and Φ N = Φ 1 ⋈ Φ 2 , p : Succ \Phi_N = \Phi_1 \bowtie\Phi_2,p : \operatorname{Succ} Φ N = Φ 1 ⋈ Φ 2 , p : Succ . Clearly Φ M ⋈ Φ H ⊑ f r e s h Φ N ⋈ Φ H ′ \Phi_M \bowtie\Phi_H \sqsubseteq_{\mathrm{fresh}} \Phi_N \bowtie\Phi'_H Φ M ⋈ Φ H ⊑ fresh Φ N ⋈ Φ H ′ , satisfying conclusion (i).
By Lemmas A.6 and A.4 on (1) and (2), we get Succ ( Φ 1 ) \operatorname{Succ}(\Phi_1) Succ ( Φ 1 ) and Succ ( Φ 2 ) \operatorname{Succ}(\Phi_2) Succ ( Φ 2 ) , respectively. Clearly then (3) Succ ( Φ N ) \operatorname{Succ}(\Phi_N) Succ ( Φ N ) .
Succ ( Φ N ) Γ 6 ; Π ; Φ N ⊢ x : ElemInst T V - V a r Γ 6 ; Π ; Φ N ⊢ D : Π [ p ] Φ N [ p ] = Succ Γ 6 ; Π ; Φ N ⊢ compInst p ( ⌈ D ⌉ , x ) : ElemInst Γ 6 ; Π ; Φ N ⊢ val compInst p ( ⌈ D ⌉ , x ) : ElemInst ! Pure ( 6 ) Γ 6 ; Π ; Φ N ⊢ val compInst p ( ⌈ D ⌉ , x ) : ElemInst ! Mut Γ ; Π ; Φ N ⊢ V : Element Γ ; Π ; Φ N ⊢ init V : ElemInst ! Mut Γ ; Π ; Φ N ⊢ let x = init V in val compInst p ( ⌈ D ⌉ , x ) : ElemInst ! Mut \begin{aligned}
&\frac{\operatorname{Succ}(\Phi_N)}{\Gamma_6;\Pi;\Phi_N \vdash x:\operatorname{ElemInst}}\ \mathrm{TV\text{-}Var}\\
&\frac{\Gamma_6;\Pi;\Phi_N \vdash D:\Pi[p]}{ } \quad
\frac{\Phi_N[p]=\operatorname{Succ}}{ }\\
&\Gamma_6;\Pi;\Phi_N \vdash\operatorname{compInst}_p(\lceil D\rceil,x):\operatorname{ElemInst}\\
&\Gamma_6;\Pi;\Phi_N \vdash\operatorname{val}\operatorname{compInst}_p(\lceil D\rceil,x):\operatorname{ElemInst}!\operatorname{Pure}\\
&(6)\quad\Gamma_6;\Pi;\Phi_N \vdash\operatorname{val}\operatorname{compInst}_p(\lceil D\rceil,x):\operatorname{ElemInst}!\operatorname{Mut}\\
&\Gamma;\Pi;\Phi_N \vdash V:\operatorname{Element}\\
&\Gamma;\Pi;\Phi_N \vdash\operatorname{init}V:\operatorname{ElemInst}!\operatorname{Mut}\\
&\Gamma;\Pi;\Phi_N \vdash\operatorname{let}\ x=\operatorname{init}V\ \operatorname{in}\ \operatorname{val}\operatorname{compInst}_p(\lceil D\rceil,x):\operatorname{ElemInst}!\operatorname{Mut}
\end{aligned} Γ 6 ; Π ; Φ N ⊢ x : ElemInst Succ ( Φ N ) TV - Var Γ 6 ; Π ; Φ N ⊢ D : Π [ p ] Φ N [ p ] = Succ Γ 6 ; Π ; Φ N ⊢ compInst p (⌈ D ⌉ , x ) : ElemInst Γ 6 ; Π ; Φ N ⊢ val compInst p (⌈ D ⌉ , x ) : ElemInst ! Pure ( 6 ) Γ 6 ; Π ; Φ N ⊢ val compInst p (⌈ D ⌉ , x ) : ElemInst ! Mut Γ ; Π ; Φ N ⊢ V : Element Γ ; Π ; Φ N ⊢ init V : ElemInst ! Mut Γ ; Π ; Φ N ⊢ let x = init V in val compInst p (⌈ D ⌉ , x ) : ElemInst ! Mut
⟦ H ⟧ ϱ ; ⟦ ⌈ D ⌉ ↓ p I n i t val V ⟧ ϱ = def. of translation let r r , f , x = ( λ ( ) . S ⟦ D ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , ⟦ V ⟧ ϱ ) in compInst ( r r , f , init x ) ; ⟦ H ⟧ ϱ ⇝ + E C - V a l / F s t / S n d compInst ( λ ( ) . S ⟦ D ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , init ⟦ V ⟧ ϱ ) ; ⟦ H ⟧ ϱ = desugar let x = init ⟦ V ⟧ ϱ in val compInst ( λ ( ) . S ⟦ D ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , x ) ; ⟦ H ⟧ ϱ = def. of translation ⟦ let x = init V in val compInst p ( ⌈ D ⌉ , x ) ⟧ ϱ ; ⟦ H ⟧ ϱ \begin{aligned}
\llbracket H\rrbracket_\varrho;\llbracket\lceil D\rceil\mathord{\downarrow}_{p}^{\mathrm{Init}}\operatorname{val}V\rrbracket_\varrho
&\mathrel{\overset{\text{def. of translation}}{=}}\operatorname{let}\ rr,f,x=(\lambda().S\llbracket D\rrbracket(p,\varrho,\varnothing),\varrho(p),\llbracket V\rrbracket_\varrho)\\
&\qquad\operatorname{in}\operatorname{compInst}(rr,f,\operatorname{init}x);\llbracket H\rrbracket_\varrho\\
&\mathrel{\overset{\mathrm{EC\text{-}Val/Fst/Snd}}{\rightsquigarrow^+}}\operatorname{compInst}(\lambda().S\llbracket D\rrbracket(p,\varrho,\varnothing),\varrho(p),\operatorname{init}\llbracket V\rrbracket_\varrho);\llbracket H\rrbracket_\varrho\\
&\mathrel{\overset{\text{desugar}}{=}}\operatorname{let}\ x=\operatorname{init}\llbracket V\rrbracket_\varrho\ \operatorname{in}\ \operatorname{val}\operatorname{compInst}(\lambda().S\llbracket D\rrbracket(p,\varrho,\varnothing),\varrho(p),x);\llbracket H\rrbracket_\varrho\\
&\mathrel{\overset{\text{def. of translation}}{=}}\llbracket\operatorname{let}\ x=\operatorname{init}V\ \operatorname{in}\ \operatorname{val}\operatorname{compInst}_p(\lceil D\rceil,x)\rrbracket_\varrho;\llbracket H\rrbracket_\varrho
\end{aligned} [ [ H ] ] ϱ ; [ [ ⌈ D ⌉ ↓ p Init val V ] ] ϱ = def. of translation let r r , f , x = ( λ ( ) . S [ [ D ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , [ [ V ] ] ϱ ) in compInst ( r r , f , init x ) ; [ [ H ] ] ϱ ⇝ + EC - Val/Fst/Snd compInst ( λ ( ) . S [ [ D ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , init [ [ V ] ] ϱ ) ; [ [ H ] ] ϱ = desugar let x = init [ [ V ] ] ϱ in val compInst ( λ ( ) . S [ [ D ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , x ) ; [ [ H ] ] ϱ = def. of translation [ [ let x = init V in val compInst p (⌈ D ⌉ , x ) ] ] ϱ ; [ [ H ] ] ϱ
Case EC-EvalDone, ϕ = Succ \phi=\operatorname{Succ} ϕ = Succ :
H ; ⌈ D ⌉ ↓ p Succ val V ⇝ let x = init V in val compInst p ( ⌈ D ⌉ , x ) ; H \mathcal{H};\lceil D\rceil\mathord{\downarrow}_{p}^{\operatorname{Succ}}\operatorname{val}V\rightsquigarrow\operatorname{let}\ x=\operatorname{init}V\ \operatorname{in}\ \operatorname{val}\operatorname{compInst}_p(\lceil D\rceil,x);\mathcal{H} H ; ⌈ D ⌉ ↓ p Succ val V ⇝ let x = init V in val compInst p (⌈ D ⌉ , x ) ; H
Γ ; Π ; Φ 1 ⊢ D : Π [ p ] Γ ; Π ; Φ 2 ⊢ V : Element Γ ; Π ; Φ 2 ⊢ val V : ∅ Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ⌈ D 0 ⌉ ↓ p Succ D : ElemInst ! Mut ( Φ 1 ⋈ Φ 2 ) [ p ] = Succ ⋯ \begin{aligned}
&\frac{\Gamma;\Pi;\Phi_1\vdash D:\Pi[p]\qquad\Gamma;\Pi;\Phi_2\vdash V:\operatorname{Element}\qquad\Gamma;\Pi;\Phi_2\vdash\operatorname{val}V:\varnothing}{\Gamma;\Pi;\Phi_1\bowtie\Phi_2\vdash\lceil D_0\rceil\mathord{\downarrow}_{p}^{\operatorname{Succ}}D:\operatorname{ElemInst}!\operatorname{Mut}}\\
&\qquad(\Phi_1\bowtie\Phi_2)[p]=\operatorname{Succ}\ \cdots
\end{aligned} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ ⌈ D 0 ⌉ ↓ p Succ D : ElemInst ! Mut Γ ; Π ; Φ 1 ⊢ D : Π [ p ] Γ ; Π ; Φ 2 ⊢ V : Element Γ ; Π ; Φ 2 ⊢ val V : ∅ ( Φ 1 ⋈ Φ 2 ) [ p ] = Succ ⋯
We retain Φ N = Φ 1 ⋈ Φ 2 \Phi_N=\Phi_1\bowtie\Phi_2 Φ N = Φ 1 ⋈ Φ 2 . By Lemmas A.6 and A.4 on (1) and (2), we get Succ ( Φ 1 ) \operatorname{Succ}(\Phi_1) Succ ( Φ 1 ) and Succ ( Φ 2 ) \operatorname{Succ}(\Phi_2) Succ ( Φ 2 ) , respectively. Clearly then (4) Succ ( Φ N ) \operatorname{Succ}(\Phi_N) Succ ( Φ N ) .
By Lemma A.11 (Φ \Phi Φ -weakening) on (1) using (4), we get (5) that Γ ; Π ; Φ N ⊢ D : Π [ p ] \Gamma;\Pi;\Phi_N\vdash D:\Pi[p] Γ ; Π ; Φ N ⊢ D : Π [ p ] .
By Lemma A.9 (Φ \Phi Φ -weakening) on (2), we get (6) Γ ; Π ; Φ N ⊢ V : Element \Gamma;\Pi;\Phi_N\vdash V:\operatorname{Element} Γ ; Π ; Φ N ⊢ V : Element .
Γ 7 ; Π ; Φ N ⊢ D : Π [ p ] Γ 7 ; Π ; Φ N ⊢ compInst p ( ⌈ D ⌉ , x ) : ElemInst Φ N [ p ] = Succ Succ ( Φ D ′ ) ‾ ( 4 ) Γ 7 ; Π ; Φ N ⊢ x : ElemInst TV-Var \frac{\Gamma_7 ; \Pi; \Phi_N \vdash D : \Pi[p]}{\Gamma_7 ; \Pi; \Phi_N \vdash\operatorname{compInst}_p(\lceil D\rceil,x) : \operatorname{ElemInst}} \quad
\frac{\Phi_N[p] = \operatorname{Succ}}{\frac{\overline{\operatorname{Succ}(\Phi'_D)}^{(4)}}{\Gamma_7 ; \Pi; \Phi_N \vdash x : \operatorname{ElemInst}}\ \operatorname{TV\text{-}Var}} Γ 7 ; Π ; Φ N ⊢ compInst p (⌈ D ⌉ , x ) : ElemInst Γ 7 ; Π ; Φ N ⊢ D : Π [ p ] Γ 7 ; Π ; Φ N ⊢ x : ElemInst Succ ( Φ D ′ ) ( 4 ) TV - Var Φ N [ p ] = Succ
Γ 7 ; Π ; Φ N ⊢ compInst p ( ⌈ D ⌉ , x ) : ElemInst Γ 7 ; Π ; Φ N ⊢ val compInst p ( ⌈ D ⌉ , x ) : ElemInst ! Pure TC-Val \frac{\Gamma_7 ; \Pi; \Phi_N \vdash\operatorname{compInst}_p(\lceil D\rceil,x) : \operatorname{ElemInst}}{\Gamma_7 ; \Pi; \Phi_N \vdash\operatorname{val}\operatorname{compInst}_p(\lceil D\rceil,x) : \operatorname{ElemInst}\ !\ \operatorname{Pure}}\ \operatorname{TC\text{-}Val} Γ 7 ; Π ; Φ N ⊢ val compInst p (⌈ D ⌉ , x ) : ElemInst ! Pure Γ 7 ; Π ; Φ N ⊢ compInst p (⌈ D ⌉ , x ) : ElemInst TC - Val
Γ 7 ; Π ; Φ N ⊢ val compInst p ( ⌈ D ⌉ , x ) : ElemInst ! Pure Γ 7 ; Π ; Φ N ⊢ val compInst p ( ⌈ D ⌉ , x ) : ElemInst ! Mut TC-Sub \frac{\Gamma_7 ; \Pi; \Phi_N \vdash\operatorname{val}\operatorname{compInst}_p(\lceil D\rceil,x) : \operatorname{ElemInst}\ !\ \operatorname{Pure}}{\Gamma_7 ; \Pi; \Phi_N \vdash\operatorname{val}\operatorname{compInst}_p(\lceil D\rceil,x) : \operatorname{ElemInst}\ !\ \operatorname{Mut}}\ \operatorname{TC\text{-}Sub} Γ 7 ; Π ; Φ N ⊢ val compInst p (⌈ D ⌉ , x ) : ElemInst ! Mut Γ 7 ; Π ; Φ N ⊢ val compInst p (⌈ D ⌉ , x ) : ElemInst ! Pure TC - Sub
Γ ; Π ; Φ N ⊢ V : Element Γ ; Π ; Φ N ⊢ init V : ElemInst ! Mut TC-Init \frac{\Gamma; \Pi; \Phi_N \vdash V : \operatorname{Element}}{\Gamma; \Pi; \Phi_N \vdash\operatorname{init}\ V : \operatorname{ElemInst}\ !\ \operatorname{Mut}}\ \operatorname{TC\text{-}Init} Γ ; Π ; Φ N ⊢ init V : ElemInst ! Mut Γ ; Π ; Φ N ⊢ V : Element TC - Init
( 7 ) , Γ 7 = Γ , x : ElemInst Γ ; Π ; Φ N ⊢ let x = init V in val compInst p ( ⌈ D ⌉ , x ) : ElemInst ! Mut TC-Let \frac{(7),\ \Gamma_7 = \Gamma,\ x : \operatorname{ElemInst}}{\Gamma; \Pi; \Phi_N \vdash\operatorname{let}\ x = \operatorname{init}\ V\ \operatorname{in}\ \operatorname{val}\operatorname{compInst}_p(\lceil D\rceil,x) : \operatorname{ElemInst}\ !\ \operatorname{Mut}}\ \operatorname{TC\text{-}Let} Γ ; Π ; Φ N ⊢ let x = init V in val compInst p (⌈ D ⌉ , x ) : ElemInst ! Mut ( 7 ) , Γ 7 = Γ , x : ElemInst TC - Let
⟦ H ⟧ ϱ ; ⟦ ⌈ D ⌉ ↓ p Succ val V ⟧ ϱ \llbracket H\rrbracket_\varrho; \llbracket\lceil D\rceil\downarrow_{\!p}^{\operatorname{Succ}}\operatorname{val}\ V\rrbracket_\varrho [ [ H ] ] ϱ ; [ [ ⌈ D ⌉ ↓ p Succ val V ] ] ϱ
(def. of translation) = let y = val ⟦ V ⟧ ϱ in compInst ( λ ( ) . S ⟦ D ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , init y ) ; ⟦ H ⟧ ϱ \mathrel{\underset{\text{(def. of translation)}{=}}{}} \operatorname{let}\ y = \operatorname{val}\llbracket V\rrbracket_\varrho\ \operatorname{in}\ \operatorname{compInst}(\lambda().S\llbracket D\rrbracket(p,\varrho,\varnothing),\varrho(p),\operatorname{init}\ y)\ ;\ \llbracket H\rrbracket_\varrho (def. of translation) = let y = val [ [ V ] ] ϱ in compInst ( λ ( ) . S [ [ D ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , init y ) ; [ [ H ] ] ϱ
\mathrel{\underset{\text{(EC-Val, desugar)}{\rightsquigarrow^{+}}}}{} \operatorname{let}\ x = \operatorname{init}\llbracket V\rrbracket_\varrho\ \operatorname{in}\ \operatorname{val}\operatorname{compInst}(\lambda().S\llbracket D\rrbracket(p,\varrho,\varnothing),\varrho(p),x)\ ;\ \llbracket H\rrbracket_\varrho
(def. of translation) = ⟦ let x = init V in val compInst p ( ⌈ D ⌉ , x ) ⟧ ϱ ; ⟦ H ⟧ ϱ \mathrel{\underset{\text{(def. of translation)}{=}}{} \llbracket\operatorname{let}\ x = \operatorname{init}\ V\ \operatorname{in}\ \operatorname{val}\operatorname{compInst}_p(\lceil D\rceil,x)\rrbracket_\varrho\ ;\ \llbracket H\rrbracket_\varrho} (def. of translation) = [ [ let x = init V in val compInst p (⌈ D ⌉ , x ) ] ] ϱ ; [ [ H ] ] ϱ
Case EC-InitText: We have H ; init text V ⇝ val textInst V ; H \mathcal{H}\ ;\ \operatorname{init}\ \operatorname{text}\ V \rightsquigarrow\operatorname{val}\ \operatorname{textInst}\ V\ ;\ \mathcal{H} H ; init text V ⇝ val textInst V ; H and
Γ ; Π ; Φ M ⊢ V : Str Γ ; Π ; Φ M ⊢ text V : Element TV-Text \frac{\Gamma; \Pi; \Phi_M \vdash V : \operatorname{Str}}{\Gamma; \Pi; \Phi_M \vdash\operatorname{text}\ V : \operatorname{Element}}\ \operatorname{TV\text{-}Text} Γ ; Π ; Φ M ⊢ text V : Element Γ ; Π ; Φ M ⊢ V : Str TV - Text
Γ ; Π ; Φ M ⊢ text V : Element Γ ; Π ; Φ M ⊢ init text V : ElemInst ! Mut TC-Init \frac{\Gamma; \Pi; \Phi_M \vdash\operatorname{text}\ V : \operatorname{Element}}{\Gamma; \Pi; \Phi_M \vdash\operatorname{init}\ \operatorname{text}\ V : \operatorname{ElemInst}\ !\ \operatorname{Mut}}\ \operatorname{TC\text{-}Init} Γ ; Π ; Φ M ⊢ init text V : ElemInst ! Mut Γ ; Π ; Φ M ⊢ text V : Element TC - Init
Γ ; Π ; Φ M ⊢ V : Str Γ ; Π ; Φ M ⊢ textInst V : ElemInst TV-TextI \frac{\Gamma; \Pi; \Phi_M \vdash V : \operatorname{Str}}{\Gamma; \Pi; \Phi_M \vdash\operatorname{textInst}\ V : \operatorname{ElemInst}}\ \operatorname{TV\text{-}TextI} Γ ; Π ; Φ M ⊢ textInst V : ElemInst Γ ; Π ; Φ M ⊢ V : Str TV - TextI
Γ ; Π ; Φ M ⊢ textInst V : ElemInst Γ ; Π ; Φ M ⊢ val textInst V : ElemInst ! Pure TC-Val \frac{\Gamma; \Pi; \Phi_M \vdash\operatorname{textInst}\ V : \operatorname{ElemInst}}{\Gamma; \Pi; \Phi_M \vdash\operatorname{val}\operatorname{textInst}\ V : \operatorname{ElemInst}\ !\ \operatorname{Pure}}\ \operatorname{TC\text{-}Val} Γ ; Π ; Φ M ⊢ val textInst V : ElemInst ! Pure Γ ; Π ; Φ M ⊢ textInst V : ElemInst TC - Val
Γ ; Π ; Φ M ⊢ val textInst V : ElemInst ! Pure Γ ; Π ; Φ M ⊢ val textInst V : ElemInst ! Mut TC-Sub \frac{\Gamma; \Pi; \Phi_M \vdash\operatorname{val}\operatorname{textInst}\ V : \operatorname{ElemInst}\ !\ \operatorname{Pure}}{\Gamma; \Pi; \Phi_M \vdash\operatorname{val}\operatorname{textInst}\ V : \operatorname{ElemInst}\ !\ \operatorname{Mut}}\ \operatorname{TC\text{-}Sub} Γ ; Π ; Φ M ⊢ val textInst V : ElemInst ! Mut Γ ; Π ; Φ M ⊢ val textInst V : ElemInst ! Pure TC - Sub
⟦ H ⟧ ϱ ; ⟦ init text V ⟧ ϱ \llbracket H\rrbracket_\varrho; \llbracket\operatorname{init}\ \operatorname{text}\ V\rrbracket_\varrho [ [ H ] ] ϱ ; [ [ init text V ] ] ϱ
(def. of translation) = init text ⟦ V ⟧ ϱ ; ⟦ H ⟧ ϱ \mathrel{\underset{\text{(def. of translation)}{=}}{} \operatorname{init}\ \operatorname{text}\ \llbracket V\rrbracket_\varrho\ ;\ \llbracket H\rrbracket_\varrho} (def. of translation) = init text [ [ V ] ] ϱ ; [ [ H ] ] ϱ
(EC-InitText) ⇝ val textInst ⟦ V ⟧ ϱ ; ⟦ H ⟧ ϱ \mathrel{\underset{\text{(EC-InitText)}{\rightsquigarrow}}{} \operatorname{val}\ \operatorname{textInst}\ \llbracket V\rrbracket_\varrho\ ;\ \llbracket H\rrbracket_\varrho} (EC-InitText) ⇝ val textInst [ [ V ] ] ϱ ; [ [ H ] ] ϱ
(def. of translation) = ⟦ val textInst V ⟧ ϱ ; ⟦ H ⟧ ϱ \mathrel{\underset{\text{(def. of translation)}{=}}{} \llbracket\operatorname{val}\ \operatorname{textInst}\ V\rrbracket_\varrho\ ;\ \llbracket H\rrbracket_\varrho} (def. of translation) = [ [ val textInst V ] ] ϱ ; [ [ H ] ] ϱ
Case EC-InitTag: We have H \mathcal{H} H ; init tag( V , W ) ⇝ (V,W) \leadsto ( V , W ) ⇝ let x x x = inits W W W in val tagInsti d ( V , x ) _{id}(V,x) i d ( V , x ) ; H \mathcal{H} H and
Γ ; Π ; Φ 1 ⊢ V : L i s t A t t r Γ ; Π ; Φ 1 ◃ Φ 2 ⊢ tag ( V , W ) : E l e m e n t Γ ; Π ; Φ 2 ⊢ W : L i s t E l e m e n t Γ ; Π ; Φ 1 ◃ Φ 2 ⊢ tag ( V , W ) : E l e m e n t Γ ; Π ; Φ 1 ◃ Φ 2 ⊢ init tag ( V , W ) : E l e m I n s t ! M u t \begin{aligned}
&\frac{\Gamma;\Pi;\Phi_1 \vdash V:\mathrm{List\ Attr}}{\Gamma;\Pi;\Phi_1 \mathbin{\triangleleft} \Phi_2 \vdash\operatorname{tag}(V,W):\mathrm{Element}} \quad
\frac{\Gamma;\Pi;\Phi_2 \vdash W:\mathrm{List\ Element}}{}\\
&\Gamma;\Pi;\Phi_1 \mathbin{\triangleleft} \Phi_2 \vdash\operatorname{tag}(V,W):\mathrm{Element}\\
&\Gamma;\Pi;\Phi_1 \mathbin{\triangleleft} \Phi_2 \vdash\operatorname{init\ tag}(V,W):\mathrm{ElemInst}\ !\ \mathrm{Mut}
\end{aligned} Γ ; Π ; Φ 1 ◃ Φ 2 ⊢ tag ( V , W ) : Element Γ ; Π ; Φ 1 ⊢ V : List Attr Γ ; Π ; Φ 2 ⊢ W : List Element Γ ; Π ; Φ 1 ◃ Φ 2 ⊢ tag ( V , W ) : Element Γ ; Π ; Φ 1 ◃ Φ 2 ⊢ init tag ( V , W ) : ElemInst ! Mut
We choose ϱ ′ = ϱ , i d ↦ i d ′ \varrho' = \varrho, id \mapsto id' ϱ ′ = ϱ , i d ↦ i d ′ , where i d ′ id' i d ′ is the identifier generated by the target language semantics.
It follows from premise ( i i ) (ii) ( ii ) that Π ; ids ( let x = inits W in val tagInst i d ( V , x ) ) ∪ ids ( H ) ⊨ ϱ ′ \Pi;\operatorname{ids}(\text{let }x=\operatorname{inits}\ W\text{ in val tagInst}_{id}(V,x)) \cup\operatorname{ids}(\mathcal{H}) \models\varrho' Π ; ids ( let x = inits W in val tagInst i d ( V , x )) ∪ ids ( H ) ⊨ ϱ ′ ; in particular, we have i d ∈ dom ( ϱ ′ ) id \in\operatorname{dom}(\varrho') i d ∈ dom ( ϱ ′ ) . Therefore, conclusion ( i v ) (iv) ( i v ) holds.
We derive conclusion (iii-a) via subderivation (3) as follows, weakening (1) appropriately on Γ \Gamma Γ .
Γ 3 ; Π ; Φ 1 ⊢ V : L i s t A t t r Γ 3 ; Π ; ∅ ⊢ x : L i s t E l e m I n s t Γ 3 ; Π ; Φ 1 ⊢ tagInst i d ( V , x ) : E l e m I n s t Γ 3 ; Π ; Φ 1 ⊢ val tagInst i d ( V , x ) : E l e m I n s t ! P u r e ( 3 ) Γ 3 ; Π ; Φ 1 ⊢ val tagInst i d ( V , x ) : E l e m I n s t ! M u t Γ ; Π ; Φ 2 ⊢ W : L i s t E l e m e n t Γ ; Π ; Φ 2 ⊢ inits W : L i s t E l e m I n s t ! M u t Γ ; Π ; Φ 1 ◃ Φ 2 ⊢ let x = inits W in val tagInst i d ( V , x ) : E l e m I n s t ! M u t \begin{aligned}
&\frac{\Gamma_3;\Pi;\Phi_1 \vdash V:\mathrm{List\ Attr}\qquad\Gamma_3;\Pi;\varnothing\vdash x:\mathrm{List\ ElemInst}}{\Gamma_3;\Pi;\Phi_1 \vdash\operatorname{tagInst}_{id}(V,x):\mathrm{ElemInst}}\\
&\Gamma_3;\Pi;\Phi_1 \vdash\operatorname{val\ tagInst}_{id}(V,x):\mathrm{ElemInst}\ !\ \mathrm{Pure}\\
&(3)\quad\Gamma_3;\Pi;\Phi_1 \vdash\operatorname{val\ tagInst}_{id}(V,x):\mathrm{ElemInst}\ !\ \mathrm{Mut}\\
&\frac{\Gamma;\Pi;\Phi_2 \vdash W:\mathrm{List\ Element}}{\Gamma;\Pi;\Phi_2 \vdash\operatorname{inits}\ W:\mathrm{List\ ElemInst}\ !\ \mathrm{Mut}}\\
&\Gamma;\Pi;\Phi_1 \mathbin{\triangleleft} \Phi_2 \vdash\text{let }x=\operatorname{inits}\ W\text{ in val tagInst}_{id}(V,x):\mathrm{ElemInst}\ !\ \mathrm{Mut}
\end{aligned} Γ 3 ; Π ; Φ 1 ⊢ tagInst i d ( V , x ) : ElemInst Γ 3 ; Π ; Φ 1 ⊢ V : List Attr Γ 3 ; Π ; ∅ ⊢ x : List ElemInst Γ 3 ; Π ; Φ 1 ⊢ val tagInst i d ( V , x ) : ElemInst ! Pure ( 3 ) Γ 3 ; Π ; Φ 1 ⊢ val tagInst i d ( V , x ) : ElemInst ! Mut Γ ; Π ; Φ 2 ⊢ inits W : List ElemInst ! Mut Γ ; Π ; Φ 2 ⊢ W : List Element Γ ; Π ; Φ 1 ◃ Φ 2 ⊢ let x = inits W in val tagInst i d ( V , x ) : ElemInst ! Mut
[ ( 3 ) , Γ 3 = Γ , x : L i s t E l e m I n s t ] [(3),\ \Gamma_3=\Gamma,\ x:\mathrm{List\ ElemInst}] [( 3 ) , Γ 3 = Γ , x : List ElemInst ]
⟦ H ⟧ ϱ ; ⟦ init tag ( V , W ) ⟧ ϱ = init tag ( ⟦ V ⟧ ϱ , ⟦ W ⟧ ϱ ) ; ⟦ H ⟧ ϱ ⇝ let x = inits ⟦ W ⟧ ϱ in val tagInst i d ′ ( ⟦ V ⟧ ϱ , x ) ; ⟦ H ⟧ ϱ = let x = inits ⟦ W ⟧ ϱ ′ in val tagInst ϱ ′ ( i d ) ( ⟦ V ⟧ ϱ ′ , x ) ; ⟦ H ⟧ ϱ ′ = ⟦ let x = inits W in val tagInst i d ( V , x ) ⟧ ϱ ′ ; ⟦ H ⟧ ϱ ′ \begin{aligned}
\llbracket\mathcal{H}\rrbracket_{\varrho};\llbracket\operatorname{init\ tag}(V,W)\rrbracket_{\varrho}
&= \operatorname{init\ tag}(\llbracket V\rrbracket_{\varrho},\llbracket W\rrbracket_{\varrho});\llbracket\mathcal{H}\rrbracket_{\varrho}\\
&\leadsto\text{let }x=\operatorname{inits}\ \llbracket W\rrbracket_{\varrho}\text{ in val tagInst}_{id'}(\llbracket V\rrbracket_{\varrho},x);\llbracket\mathcal{H}\rrbracket_{\varrho}\\
&= \text{let }x=\operatorname{inits}\ \llbracket W\rrbracket_{\varrho'}\text{ in val tagInst}_{\varrho'(id)}(\llbracket V\rrbracket_{\varrho'},x);\llbracket\mathcal{H}\rrbracket_{\varrho'}\\
&= \llbracket\text{let }x=\operatorname{inits}\ W\text{ in val tagInst}_{id}(V,x)\rrbracket_{\varrho'};\llbracket\mathcal{H}\rrbracket_{\varrho'}
\end{aligned} [ [ H ] ] ϱ ; [ [ init tag ( V , W ) ] ] ϱ = init tag ( [ [ V ] ] ϱ , [ [ W ] ] ϱ ) ; [ [ H ] ] ϱ ⇝ let x = inits [ [ W ] ] ϱ in val tagInst i d ′ ( [ [ V ] ] ϱ , x ) ; [ [ H ] ] ϱ = let x = inits [ [ W ] ] ϱ ′ in val tagInst ϱ ′ ( i d ) ( [ [ V ] ] ϱ ′ , x ) ; [ [ H ] ] ϱ ′ = [ [ let x = inits W in val tagInst i d ( V , x ) ] ] ϱ ′ ; [ [ H ] ] ϱ ′
Case EC-InitComp: We have H \mathcal{H} H ; init component { D } ⇝ ⌈ D ⌉ ↓ p I n i t D ; H ′ \{D\} \leadsto\lceil D\rceil\mathrel{\downarrow_{\!p}^{\mathrm{Init}}} D;\mathcal{H}' { D } ⇝ ⌈ D ⌉ ↓ p Init D ; H ′ , where p p p is fresh, H ′ = H , p ↦ { s t : ∅ , r e r e n d e r : f f } \mathcal{H}'=\mathcal{H},p\mapsto\{\mathrm{st}:\varnothing,\mathrm{rerender}:\mathrm{ff}\} H ′ = H , p ↦ { st : ∅ , rerender : ff } , and
Γ ; Π ; Φ M ⊢ D : L Γ ; Π ; Φ M ⊢ component { D } : E l e m e n t Γ ; Π ; Φ M ⊢ init component { D } : E l e m I n s t ! M u t \begin{aligned}
&\frac{\Gamma;\Pi;\Phi_M \vdash D:\mathcal{L}}{\Gamma;\Pi;\Phi_M \vdash\operatorname{component}\ \{D\}:\mathrm{Element}}\\
&\Gamma;\Pi;\Phi_M \vdash\operatorname{init\ component}\ \{D\}:\mathrm{ElemInst}\ !\ \mathrm{Mut}
\end{aligned} Γ ; Π ; Φ M ⊢ component { D } : Element Γ ; Π ; Φ M ⊢ D : L Γ ; Π ; Φ M ⊢ init component { D } : ElemInst ! Mut
Choose Φ N = Φ M , p : I n i t \Phi_N=\Phi_M,p:\mathrm{Init} Φ N = Φ M , p : Init and Φ H ′ = Φ H \Phi'_H=\Phi_H Φ H ′ = Φ H . Since p p p is fresh, Φ N ◃ Φ H \Phi_N \mathbin{\triangleleft} \Phi_H Φ N ◃ Φ H is defined and we have Φ M ◃ Φ H ⊑ f r e s h Φ N ◃ Φ H \Phi_M \mathbin{\triangleleft} \Phi_H \sqsubseteq_{\mathrm{fresh}} \Phi_N \mathbin{\triangleleft} \Phi_H Φ M ◃ Φ H ⊑ fresh Φ N ◃ Φ H , satisfying conclusion (i).
Choose Π ′ = Π , p ↦ ∅ \Pi'=\Pi,p\mapsto\varnothing Π ′ = Π , p ↦ ∅ . By definition, we have Π ⊑ Φ N ◃ Φ H Π ′ \Pi\sqsubseteq_{\Phi_N\mathbin{\triangleleft}\Phi_H}\Pi' Π ⊑ Φ N ◃ Φ H Π ′ , satisfying conclusion (ii).
Choose ϱ ′ = ϱ , p ↦ ℓ \varrho'=\varrho,p\mapsto\ell ϱ ′ = ϱ , p ↦ ℓ , where ℓ \ell ℓ is the location generated by the target-language semantics. Since Π ′ [ p ] = ∅ \Pi'[p]=\varnothing Π ′ [ p ] = ∅ , ϱ ′ \varrho' ϱ ′ satisfies Π ′ \Pi' Π ′ , and since ids ( M ) = ids ( D ) = ids ( N ) \operatorname{ids}(M)=\operatorname{ids}(D)=\operatorname{ids}(N) ids ( M ) = ids ( D ) = ids ( N ) , conclusion (iv) holds.
By premise (i-b) and definition of each of Π ′ \Pi' Π ′ and H ′ \mathcal{H}' H ′ , we have that Γ ; Π ′ ; Φ H ⊨ H ′ \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_{\mathcal{H}} \models\mathcal{H}' Γ ; Π ′ ; Φ H ⊨ H ′ , satisfying conclusion (iii-b).
By Lemma A.3 (Π \Pi Π -weakening) on (1), using the fact that p p p is fresh and so p ∉ dom ( Φ M ) p \notin\operatorname{dom}(\Phi_M) p ∈ / dom ( Φ M ) , we get (3) that Γ ; Π ′ ; Φ M ⊢ D : L \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_M \vdash D : \mathcal{L} Γ ; Π ′ ; Φ M ⊢ D : L .
Since Π ′ [ p ] = ∅ \Pi'[p] = \varnothing Π ′ [ p ] = ∅ , (3) is equivalent to (4) that Γ ; Π ′ ; Φ M ⊢ D : L ⊎ Π ′ [ p ] \Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_M \vdash D : \mathcal{L} \uplus\Pi'[p] Γ ; Π ′ ; Φ M ⊢ D : L ⊎ Π ′ [ p ] .
By Lemma A.6 on (1), we know Succ ( Φ M ) \operatorname{Succ}(\Phi_M) Succ ( Φ M ) . It follows that (5) Φ M ⋆ Φ M = Φ M \Phi_M \star\Phi_M = \Phi_M Φ M ⋆ Φ M = Φ M .
We derive conclusion (iii-a) as follows, implicitly using (5):
Γ ; Π ′ ; Φ M ⊢ D : L ⊎ Π ′ [ p ] ( 4 ) Γ ; Π ′ ; Φ M ⊢ D : L ( 3 ) Γ ; Π ′ ; Φ M , p : Init ⊢ ⌈ D ⌉ ↓ p Init D : ElemInst ! Mut TC-EvalI \frac{\Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_M \vdash D : \mathcal{L} \uplus\Pi'[p]\mathrel{\mkern-3mu}^{(4)} \qquad\Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_M \vdash D : \mathcal{L}\mathrel{\mkern-3mu}^{(3)}}{\Gamma\mathbin{;} \Pi' \mathbin{;} \Phi_M, p : \operatorname{Init} \vdash\lceil D\rceil\mathord{\downarrow}^{\operatorname{Init}}_p D : \operatorname{ElemInst}\mathbin{!}\operatorname{Mut}}\ \operatorname{TC\text{-}EvalI} Γ ; Π ′ ; Φ M , p : Init ⊢ ⌈ D ⌉ ↓ p Init D : ElemInst ! Mut Γ ; Π ′ ; Φ M ⊢ D : L ⊎ Π ′ [ p ] ( 4 ) Γ ; Π ′ ; Φ M ⊢ D : L ( 3 ) TC - EvalI
By Lemma B.22 (δ \delta δ -elimination), we have I ⟦ D ⟧ ( D , p , ϱ ′ , flag ↦ x ) [ ϱ ′ ( p ) / x ] = I ⟦ D ⟧ ( D , p , ϱ ′ , ∅ ) [ ϱ ′ ( p ) / x ] \mathcal{I}\llbracket D\rrbracket(D,p,\varrho',\operatorname{flag}\mapsto x)[\varrho'(p)/x] = \mathcal{I}\llbracket D\rrbracket(D,p,\varrho',\varnothing)[\varrho'(p)/x] I [ [ D ] ] ( D , p , ϱ ′ , flag ↦ x ) [ ϱ ′ ( p ) / x ] = I [ [ D ] ] ( D , p , ϱ ′ , ∅ ) [ ϱ ′ ( p ) / x ] . Given that x ∉ fv ( D ) x \notin\operatorname{fv}(D) x ∈ / fv ( D ) , we have (6) that I ⟦ D ⟧ ( D , p , ϱ ′ , flag ↦ x ) [ ϱ ′ ( p ) / x ] = I ⟦ D ⟧ ( D , p , ϱ ′ , ∅ ) \mathcal{I}\llbracket D\rrbracket(D,p,\varrho',\operatorname{flag}\mapsto x)[\varrho'(p)/x] = \mathcal{I}\llbracket D\rrbracket(D,p,\varrho',\varnothing) I [ [ D ] ] ( D , p , ϱ ′ , flag ↦ x ) [ ϱ ′ ( p ) / x ] = I [ [ D ] ] ( D , p , ϱ ′ , ∅ ) .
We show conclusion (v) as follows:
⟦ H ⟧ ϱ ; ⟦ init component { D } ⟧ ϱ = = (def. of translation) = init component λ ( ) . let x = ref ( false ) in I ⟦ D ⟧ ( D , p , ϱ , flag ↦ x ) ; ⟦ H ⟧ ϱ = (EC-InitComp, EC-App) ⇝ + let r r , f , y = ( let x = ref ( false ) in I ⟦ D ⟧ ( D , p , ϱ , flag ↦ x ) ) in inst ( r r , f , init y ) ; ⟦ H ⟧ ϱ = (EC-Ref, EC-Val) ⇝ + let r r , f , y = I ⟦ D ⟧ ( D , p , ϱ , flag ↦ x ) [ ϱ ′ ( p ) / x ] in inst ( r r , f , init y ) ; ⟦ H ⟧ ϱ [ ϱ ′ ( p ) ↦ false ] = (Lemmas B.17/B.18, ϱ -ext.) = let r r , f , y = I ⟦ D ⟧ ( D , p , ϱ ′ , flag ↦ x ) [ ϱ ′ ( p ) / x ] in inst ( r r , f , init y ) ; ⟦ H ⟧ ϱ ′ [ ϱ ′ ( p ) ↦ false ] = (by (6)) = let r r , f , y = I ⟦ D ⟧ ( D , p , ϱ ′ , ∅ ) in inst ( r r , f , init y ) ; ⟦ H ⟧ ϱ ′ [ ϱ ′ ( p ) ↦ false ] = (def. of translation) = ⟦ ⌈ D ⌉ ↓ p Init D ⟧ ϱ ′ ; ⟦ H ′ ⟧ ϱ ′ \begin{aligned}
\llbracket\mathcal{H}\rrbracket_{\varrho} \mathbin{;} \llbracket\operatorname{init\ component}\ \{D\}\rrbracket_{\varrho}
&\mathrel{\phantom{=}} \\
&\mathrel{\phantom{=}} \text{(def. of translation)} = \operatorname{init\ component}\ \lambda().\operatorname{let}\ x=\operatorname{ref}(\operatorname{false})\ \operatorname{in}\ \mathcal{I}\llbracket D\rrbracket(D,p,\varrho,\operatorname{flag}\mapsto x) \mathbin{;} \llbracket\mathcal{H}\rrbracket_{\varrho} \\
&\mathrel{\phantom{=}} \text{(EC-InitComp, EC-App)} \rightsquigarrow^{+} \operatorname{let}\ rr,f,y=(\operatorname{let}\ x=\operatorname{ref}(\operatorname{false})\ \operatorname{in}\ \mathcal{I}\llbracket D\rrbracket(D,p,\varrho,\operatorname{flag}\mapsto x)) \\
&\qquad\operatorname{in}\ \operatorname{inst}(rr,f,\operatorname{init}\ y) \mathbin{;} \llbracket\mathcal{H}\rrbracket_{\varrho} \\
&\mathrel{\phantom{=}} \text{(EC-Ref, EC-Val)} \rightsquigarrow^{+} \operatorname{let}\ rr,f,y=\mathcal{I}\llbracket D\rrbracket(D,p,\varrho,\operatorname{flag}\mapsto x)[\varrho'(p)/x] \\
&\qquad\operatorname{in}\ \operatorname{inst}(rr,f,\operatorname{init}\ y) \mathbin{;} \llbracket\mathcal{H}\rrbracket_{\varrho}[\varrho'(p)\mapsto\operatorname{false}] \\
&\mathrel{\phantom{=}} \text{(Lemmas B.17/B.18, }\varrho\text{-ext.)} = \operatorname{let}\ rr,f,y=\mathcal{I}\llbracket D\rrbracket(D,p,\varrho',\operatorname{flag}\mapsto x)[\varrho'(p)/x] \\
&\qquad\operatorname{in}\ \operatorname{inst}(rr,f,\operatorname{init}\ y) \mathbin{;} \llbracket\mathcal{H}\rrbracket_{\varrho'}[\varrho'(p)\mapsto\operatorname{false}] \\
&\mathrel{\phantom{=}} \text{(by (6))} = \operatorname{let}\ rr,f,y=\mathcal{I}\llbracket D\rrbracket(D,p,\varrho',\varnothing)\ \operatorname{in}\ \operatorname{inst}(rr,f,\operatorname{init}\ y) \mathbin{;} \llbracket\mathcal{H}\rrbracket_{\varrho'}[\varrho'(p)\mapsto\operatorname{false}] \\
&\mathrel{\phantom{=}} \text{(def. of translation)} = \llbracket\lceil D\rceil\mathord{\downarrow}^{\operatorname{Init}}_p D\rrbracket_{\varrho'} \mathbin{;} \llbracket\mathcal{H}'\rrbracket_{\varrho'}
\end{aligned} [ [ H ] ] ϱ ; [ [ init component { D } ] ] ϱ = = (def. of translation) = init component λ ( ) . let x = ref ( false ) in I [ [ D ] ] ( D , p , ϱ , flag ↦ x ) ; [ [ H ] ] ϱ = (EC-InitComp, EC-App) ⇝ + let r r , f , y = ( let x = ref ( false ) in I [ [ D ] ] ( D , p , ϱ , flag ↦ x )) in inst ( r r , f , init y ) ; [ [ H ] ] ϱ = (EC-Ref, EC-Val) ⇝ + let r r , f , y = I [ [ D ] ] ( D , p , ϱ , flag ↦ x ) [ ϱ ′ ( p ) / x ] in inst ( r r , f , init y ) ; [ [ H ] ] ϱ [ ϱ ′ ( p ) ↦ false ] = (Lemmas B.17/B.18, ϱ -ext.) = let r r , f , y = I [ [ D ] ] ( D , p , ϱ ′ , flag ↦ x ) [ ϱ ′ ( p ) / x ] in inst ( r r , f , init y ) ; [ [ H ] ] ϱ ′ [ ϱ ′ ( p ) ↦ false ] = (by (6)) = let r r , f , y = I [ [ D ] ] ( D , p , ϱ ′ , ∅ ) in inst ( r r , f , init y ) ; [ [ H ] ] ϱ ′ [ ϱ ′ ( p ) ↦ false ] = (def. of translation) = [ [ ⌈ D ⌉ ↓ p Init D ] ] ϱ ′ ; [ [ H ′ ] ] ϱ ′
Case EC-ClickText: We have H ; click i d textInst V ⇝ val ( ) ; H \mathcal{H} \mathbin{;} \operatorname{click}_{id}\ \operatorname{textInst}\ V \leadsto\operatorname{val}() \mathbin{;} \mathcal{H} H ; click i d textInst V ⇝ val ( ) ; H and
Γ ; Π ; Φ M ⊢ textInst v : ElemInst ( 1 ) Γ ; Π ; Φ M ⊢ click i d textInst V : 1 ! Mut TC-Click \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash\operatorname{textInst}\ v : \operatorname{ElemInst}\mathrel{\mkern-3mu}^{(1)}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash\operatorname{click}_{id}\ \operatorname{textInst}\ V : 1\mathbin{!}\operatorname{Mut}}\ \operatorname{TC\text{-}Click} Γ ; Π ; Φ M ⊢ click i d textInst V : 1 ! Mut Γ ; Π ; Φ M ⊢ textInst v : ElemInst ( 1 ) TC - Click
By Lemma A.4 (unrestriction) on (1), we get (2) that Succ ( Φ M ) \operatorname{Succ}(\Phi_M) Succ ( Φ M ) .
We derive conclusion (iii-a) as follows:
Succ ( Φ M ) ( 2 ) Γ ; Π ; Φ M ⊢ ( ) : 1 TV-Unit \frac{\operatorname{Succ}(\Phi_M)\mathrel{\mkern-3mu}^{(2)}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash() : 1}\ \operatorname{TV\text{-}Unit} Γ ; Π ; Φ M ⊢ ( ) : 1 Succ ( Φ M ) ( 2 ) TV - Unit
Γ ; Π ; Φ M ⊢ ( ) : 1 Γ ; Π ; Φ M ⊢ val ( ) : 1 ! Pure TC-Val \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash() : 1}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash\operatorname{val}() : 1\mathbin{!}\operatorname{Pure}}\ \operatorname{TC\text{-}Val} Γ ; Π ; Φ M ⊢ val ( ) : 1 ! Pure Γ ; Π ; Φ M ⊢ ( ) : 1 TC - Val
Γ ; Π ; Φ M ⊢ val ( ) : 1 ! Pure Γ ; Π ; Φ M ⊢ val ( ) : 1 ! Mut TC-Sub \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash\operatorname{val}() : 1\mathbin{!}\operatorname{Pure}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_M \vdash\operatorname{val}() : 1\mathbin{!}\operatorname{Mut}}\ \operatorname{TC\text{-}Sub} Γ ; Π ; Φ M ⊢ val ( ) : 1 ! Mut Γ ; Π ; Φ M ⊢ val ( ) : 1 ! Pure TC - Sub
⟦ H ⟧ ϱ ; ⟦ click i d textInst V ⟧ ϱ \llbracket\mathcal{H} \rrbracket_{\varrho} ; \llbracket\operatorname{click}_{id}\ \operatorname{textInst}\ V \rrbracket_{\varrho} [ [ H ] ] ϱ ; [ [ click i d textInst V ] ] ϱ
(def. of translation) = click ϱ ( i d ) textInst ⟦ V ⟧ ϱ ; ⟦ H ⟧ ϱ (EC-ClickText) ⇝ val ( ) ; ⟦ H ⟧ ϱ (def. of translation) = ⟦ val ( ) ⟧ ϱ ; ⟦ H ⟧ ϱ \begin{aligned}
\text{(def. of translation)} \quad&= \operatorname{click}_{\varrho}(id)\ \operatorname{textInst}\ \llbracket V \rrbracket_{\varrho} ; \llbracket\mathcal{H} \rrbracket_{\varrho} \\
\text{(EC-ClickText)} \quad&\leadsto\operatorname{val} () ; \llbracket\mathcal{H} \rrbracket_{\varrho} \\
\text{(def. of translation)} \quad&= \llbracket\operatorname{val} () \rrbracket_{\varrho} ; \llbracket\mathcal{H} \rrbracket_{\varrho}
\end{aligned} (def. of translation) (EC-ClickText) (def. of translation) = click ϱ ( i d ) textInst [ [ V ] ] ϱ ; [ [ H ] ] ϱ ⇝ val ( ) ; [ [ H ] ] ϱ = [ [ val ( ) ] ] ϱ ; [ [ H ] ] ϱ
Case EC-ClickTagT: We have H \mathcal{H} H ; click i d tagInst i d ( V , W ) ⇝ runClicks V ; clicks i d W ; H \operatorname{click}_{id}\ \operatorname{tagInst}_{id}(V,W) \leadsto\operatorname{runClicks}\ V ; \operatorname{clicks}_{id}\ W ; \mathcal{H} click i d tagInst i d ( V , W ) ⇝ runClicks V ; clicks i d W ; H and
Γ ; Π ; Φ 1 ⊢ V : List Attr Γ ; Π ; Φ 2 ⊢ W : List ElemInst \frac{\Gamma; \Pi; \Phi_{1} \vdash V : \operatorname{List}\ \operatorname{Attr}}{ }
\qquad
\frac{\Gamma; \Pi; \Phi_{2} \vdash W : \operatorname{List}\ \operatorname{ElemInst}}{ } Γ ; Π ; Φ 1 ⊢ V : List Attr Γ ; Π ; Φ 2 ⊢ W : List ElemInst
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tagInst i d ( V , W ) : ElemInst TV-TagI \frac{\Gamma; \Pi; \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{tagInst}_{id}(V,W) : \operatorname{ElemInst}}{\text{TV-TagI}} TV-TagI Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tagInst i d ( V , W ) : ElemInst
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ click i d tagInst i d ( V , W ) : 1 ! Mut TC-Click \frac{\Gamma; \Pi; \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{click}_{id}\ \operatorname{tagInst}_{id}(V,W) : 1\ !\ \operatorname{Mut}}{\text{TC-Click}} TC-Click Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ click i d tagInst i d ( V , W ) : 1 ! Mut
Γ ; Π ; Φ 1 ⊢ V : List Attr Γ ; Π ; Φ 1 ⊢ runClicks V : 1 ! Mut TC-RunClicks Γ ; Π ; Φ 2 ⊢ W : List ElemInst Γ ; Π ; Φ 2 ⊢ clicks i d W : 1 ! Mut TC-Clicks \frac{\Gamma; \Pi; \Phi_{1} \vdash V : \operatorname{List}\ \operatorname{Attr}}{\Gamma; \Pi; \Phi_{1} \vdash\operatorname{runClicks}\ V : 1\ !\ \operatorname{Mut}}\ \text{TC-RunClicks}
\qquad
\frac{\Gamma; \Pi; \Phi_{2} \vdash W : \operatorname{List}\ \operatorname{ElemInst}}{\Gamma; \Pi; \Phi_{2} \vdash\operatorname{clicks}_{id}\ W : 1\ !\ \operatorname{Mut}}\ \text{TC-Clicks} Γ ; Π ; Φ 1 ⊢ runClicks V : 1 ! Mut Γ ; Π ; Φ 1 ⊢ V : List Attr TC-RunClicks Γ ; Π ; Φ 2 ⊢ clicks i d W : 1 ! Mut Γ ; Π ; Φ 2 ⊢ W : List ElemInst TC-Clicks
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ runClicks V ; clicks i d W : 1 ! Mut TC-Let \frac{\Gamma; \Pi; \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{runClicks}\ V ; \operatorname{clicks}_{id}\ W : 1\ !\ \operatorname{Mut}}{\text{TC-Let}} TC-Let Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ runClicks V ; clicks i d W : 1 ! Mut
⟦ H ⟧ ϱ ; ⟦ click i d tagInst i d ( V , W ) ⟧ ϱ \llbracket\mathcal{H} \rrbracket_{\varrho} ; \llbracket\operatorname{click}_{id}\ \operatorname{tagInst}_{id}(V,W) \rrbracket_{\varrho} [ [ H ] ] ϱ ; [ [ click i d tagInst i d ( V , W ) ] ] ϱ
(def. of translation) = click ϱ ( i d ) tagInst ϱ ( i d ) ( ⟦ V ⟧ ϱ , ⟦ W ⟧ ϱ ) ; ⟦ H ⟧ ϱ (EC-ClickTagT) ⇝ runClicks ⟦ V ⟧ ϱ ; clicks ϱ ( i d ) ⟦ W ⟧ ϱ ; ⟦ H ⟧ ϱ (def. of translation) = ⟦ runClicks V ; clicks i d W ⟧ ϱ ; ⟦ H ⟧ ϱ \begin{aligned}
\text{(def. of translation)} \quad&= \operatorname{click}_{\varrho}(id)\ \operatorname{tagInst}_{\varrho(id)}(\llbracket V \rrbracket_{\varrho},\llbracket W \rrbracket_{\varrho}) ; \llbracket\mathcal{H} \rrbracket_{\varrho} \\
\text{(EC-ClickTagT)} \quad&\leadsto\operatorname{runClicks}\ \llbracket V \rrbracket_{\varrho} ; \operatorname{clicks}_{\varrho(id)}\ \llbracket W \rrbracket_{\varrho} ; \llbracket\mathcal{H} \rrbracket_{\varrho} \\
\text{(def. of translation)} \quad&= \llbracket\operatorname{runClicks}\ V ; \operatorname{clicks}_{id}\ W \rrbracket_{\varrho} ; \llbracket\mathcal{H} \rrbracket_{\varrho}
\end{aligned} (def. of translation) (EC-ClickTagT) (def. of translation) = click ϱ ( i d ) tagInst ϱ ( i d ) ( [ [ V ] ] ϱ , [ [ W ] ] ϱ ) ; [ [ H ] ] ϱ ⇝ runClicks [ [ V ] ] ϱ ; clicks ϱ ( i d ) [ [ W ] ] ϱ ; [ [ H ] ] ϱ = [ [ runClicks V ; clicks i d W ] ] ϱ ; [ [ H ] ] ϱ
Case EC-ClickTagF: We have H \mathcal{H} H ; click i d tagInst i d ′ ( V , W ) ⇝ clicks i d W ; H \operatorname{click}_{id}\ \operatorname{tagInst}_{id'}(V,W) \leadsto\operatorname{clicks}_{id}\ W ; \mathcal{H} click i d tagInst i d ′ ( V , W ) ⇝ clicks i d W ; H and
Γ ; Π ; Φ 1 ⊢ V : List Attr Γ ; Π ; Φ 2 ⊢ W : List ElemInst \frac{\Gamma; \Pi; \Phi_{1} \vdash V : \operatorname{List}\ \operatorname{Attr}}{ }
\qquad
\frac{\Gamma; \Pi; \Phi_{2} \vdash W : \operatorname{List}\ \operatorname{ElemInst}}{ } Γ ; Π ; Φ 1 ⊢ V : List Attr Γ ; Π ; Φ 2 ⊢ W : List ElemInst
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tagInst i d ′ ( V , W ) : ElemInst TV-TagI \frac{\Gamma; \Pi; \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{tagInst}_{id'}(V,W) : \operatorname{ElemInst}}{\text{TV-TagI}} TV-TagI Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ tagInst i d ′ ( V , W ) : ElemInst
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ click i d tagInst i d ′ ( V , W ) : 1 ! Mut TC-Click \frac{\Gamma; \Pi; \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{click}_{id}\ \operatorname{tagInst}_{id'}(V,W) : 1\ !\ \operatorname{Mut}}{\text{TC-Click}} TC-Click Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ click i d tagInst i d ′ ( V , W ) : 1 ! Mut
By Lemma A.4 (unrestriction) on (1), we get (3) that Succ ( Φ 1 ) \operatorname{Succ}(\Phi_{1}) Succ ( Φ 1 ) .
By Lemma A.9 (Φ \Phi Φ -weakening) on (2) using (3), we get (4) that Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ W : List ElemInst \Gamma; \Pi; \Phi_{1} \bowtie\Phi_{2} \vdash W : \operatorname{List}\ \operatorname{ElemInst} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ W : List ElemInst .
We derive conclusion (iii-a) as follows:
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ W : List ElemInst Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ clicks i d W : 1 ! Mut TC-Clicks \frac{\Gamma; \Pi; \Phi_{1} \bowtie\Phi_{2} \vdash W : \operatorname{List}\ \operatorname{ElemInst}}{\Gamma; \Pi; \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{clicks}_{id}\ W : 1\ !\ \operatorname{Mut}}\ \text{TC-Clicks} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ clicks i d W : 1 ! Mut Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ W : List ElemInst TC-Clicks
⟦ H ⟧ ϱ ; ⟦ click i d tagInst i d ′ ( V , W ) ⟧ ϱ = (def. of translation) click ϱ ( i d ) tagInst ϱ ( i d ′ ) ( ⟦ V ⟧ ϱ , ⟦ W ⟧ ϱ ) ; ⟦ H ⟧ ϱ ⇝ (EC-ClickTagF, by (5)) clicks ϱ ( i d ) ⟦ W ⟧ ϱ ; ⟦ H ⟧ ϱ = (def. of translation) ⟦ clicks i d W ⟧ ϱ ; ⟦ H ⟧ ϱ \begin{aligned}
\llbracket\mathcal{H} \rrbracket_{\varrho} \mathbin{;} \llbracket\operatorname{click}_{id}\operatorname{tagInst}_{id'}(V,W) \rrbracket_{\varrho} \\
&\mathrel{\stackrel{\text{(def. of translation)}}{=}} \operatorname{click}_{\varrho(id)}\operatorname{tagInst}_{\varrho(id')}\left(\llbracket V \rrbracket_{\varrho},\llbracket W \rrbracket_{\varrho}\right) \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho} \\
&\mathrel{\stackrel{\text{(EC-ClickTagF, by (5))}}{\rightsquigarrow}} \operatorname{clicks}_{\varrho(id)}\llbracket W \rrbracket_{\varrho} \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho} \\
&\mathrel{\stackrel{\text{(def. of translation)}}{=}} \llbracket\operatorname{clicks}_{id}W \rrbracket_{\varrho} \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho}
\end{aligned} [ [ H ] ] ϱ ; [ [ click i d tagInst i d ′ ( V , W ) ] ] ϱ = (def. of translation) click ϱ ( i d ) tagInst ϱ ( i d ′ ) ( [ [ V ] ] ϱ , [ [ W ] ] ϱ ) ; [ [ H ] ] ϱ ⇝ (EC-ClickTagF, by (5)) clicks ϱ ( i d ) [ [ W ] ] ϱ ; [ [ H ] ] ϱ = (def. of translation) [ [ clicks i d W ] ] ϱ ; [ [ H ] ] ϱ
Case EC-ClickComp: We have H ; click i d compInst p ( ⌈ D ⌉ , V ) ⇝ click i d V ; H \mathcal{H} \mathbin{;} \operatorname{click}_{id}\operatorname{compInst}_{p}(\lceil D\rceil,V) \rightsquigarrow\operatorname{click}_{id}V \mathbin{;} \mathcal{H} H ; click i d compInst p (⌈ D ⌉ , V ) ⇝ click i d V ; H and
Γ ; Π ; Φ 1 ⊢ D : Π [ p ] ( Φ 1 ⋈ Φ 2 ) [ p ] = Succ Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ compInst p ( ⌈ D ⌉ , V ) : ElemInst \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \vdash D : \Pi[p] \qquad(\Phi_{1} \bowtie\Phi_{2})[p] = \operatorname{Succ}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{compInst}_{p}(\lceil D\rceil,V) : \operatorname{ElemInst}} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ compInst p (⌈ D ⌉ , V ) : ElemInst Γ ; Π ; Φ 1 ⊢ D : Π [ p ] ( Φ 1 ⋈ Φ 2 ) [ p ] = Succ
Γ ; Π ; Φ 2 ⊢ V : ElemInst Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ compInst p ( ⌈ D ⌉ , V ) : ElemInst \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{2} \vdash V : \operatorname{ElemInst}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{compInst}_{p}(\lceil D\rceil,V) : \operatorname{ElemInst}} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ compInst p (⌈ D ⌉ , V ) : ElemInst Γ ; Π ; Φ 2 ⊢ V : ElemInst
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ compInst p ( ⌈ D ⌉ , V ) : ElemInst Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ click i d compInst p ( ⌈ D ⌉ , V ) : 1 ! Mut \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{compInst}_{p}(\lceil D\rceil,V) : \operatorname{ElemInst}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{click}_{id}\operatorname{compInst}_{p}(\lceil D\rceil,V) : 1\mathbin{!}\operatorname{Mut}} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ click i d compInst p (⌈ D ⌉ , V ) : 1 ! Mut Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ compInst p (⌈ D ⌉ , V ) : ElemInst
By Lemma A.6 (unrestriction) on (1), we get (3) that Succ ( Φ 1 ) \operatorname{Succ}(\Phi_{1}) Succ ( Φ 1 ) .
By Lemma A.9 (Φ \Phi Φ -weakening) on (2) using (3), we get (4) that Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : ElemInst \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \vdash V : \operatorname{ElemInst} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : ElemInst .
We derive conclusion (iii-a) as follows:
Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : ElemInst Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ click i d V : 1 ! Mut \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \vdash V : \operatorname{ElemInst}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \bowtie\Phi_{2} \vdash\operatorname{click}_{id}V : 1\mathbin{!}\operatorname{Mut}} Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ click i d V : 1 ! Mut Γ ; Π ; Φ 1 ⋈ Φ 2 ⊢ V : ElemInst
⟦ H ⟧ ϱ ; ⟦ click i d compInst p ( ⌈ D ⌉ , V ) ⟧ ϱ = (def. of translation) click ϱ ( i d ) inst ( λ ( ) . S ⟦ D ⟧ ( p , ϱ , ∅ ) , ϱ ( p ) , ⟦ V ⟧ ϱ ) ; ⟦ H ⟧ ϱ ⇝ (EC-ClickComp) click ϱ ( i d ) ⟦ V ⟧ ϱ ; ⟦ H ⟧ ϱ = (def. of translation) ⟦ click i d V ⟧ ϱ ; ⟦ H ⟧ ϱ \begin{aligned}
\llbracket\mathcal{H} \rrbracket_{\varrho} \mathbin{;} \llbracket\operatorname{click}_{id}\operatorname{compInst}_{p}(\lceil D\rceil,V) \rrbracket_{\varrho} \\
&\mathrel{\stackrel{\text{(def. of translation)}}{=}} \operatorname{click}_{\varrho(id)}\operatorname{inst}\left(\lambda().S\llbracket D\rrbracket(p,\varrho,\emptyset),\varrho(p),\llbracket V\rrbracket_{\varrho}\right) \mathbin{;} \llbracket\mathcal{H}\rrbracket_{\varrho} \\
&\mathrel{\stackrel{\text{(EC-ClickComp)}}{\rightsquigarrow}} \operatorname{click}_{\varrho(id)}\llbracket V\rrbracket_{\varrho} \mathbin{;} \llbracket\mathcal{H}\rrbracket_{\varrho} \\
&\mathrel{\stackrel{\text{(def. of translation)}}{=}} \llbracket\operatorname{click}_{id}V\rrbracket_{\varrho} \mathbin{;} \llbracket\mathcal{H}\rrbracket_{\varrho}
\end{aligned} [ [ H ] ] ϱ ; [ [ click i d compInst p (⌈ D ⌉ , V ) ] ] ϱ = (def. of translation) click ϱ ( i d ) inst ( λ ( ) . S [ [ D ] ] ( p , ϱ , ∅ ) , ϱ ( p ) , [ [ V ] ] ϱ ) ; [ [ H ] ] ϱ ⇝ (EC-ClickComp) click ϱ ( i d ) [ [ V ] ] ϱ ; [ [ H ] ] ϱ = (def. of translation) [ [ click i d V ] ] ϱ ; [ [ H ] ] ϱ
Case EC-RunAttr: Analogous to EC-ClickText.
Case EC-RunClick: We have H ; runClick onClick V ⇝ V ( ) ; H \mathcal{H} \mathbin{;} \operatorname{runClick}\ \operatorname{onClick}\ V \rightsquigarrow V\ () \mathbin{;} \mathcal{H} H ; runClick onClick V ⇝ V ( ) ; H and
Γ ; Π ; Φ M ⊢ V : 1 → Mut 1 Γ ; Π ; Φ M ⊢ onClick V : Attr \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{M} \vdash V : 1 \xrightarrow{\operatorname{Mut}} 1}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{M} \vdash\operatorname{onClick}\ V : \operatorname{Attr}} Γ ; Π ; Φ M ⊢ onClick V : Attr Γ ; Π ; Φ M ⊢ V : 1 Mut 1
Γ ; Π ; Φ M ⊢ onClick V : Attr Γ ; Π ; Φ M ⊢ runClick onClick V : 1 ! Mut \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{M} \vdash\operatorname{onClick}\ V : \operatorname{Attr}}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{M} \vdash\operatorname{runClick}\ \operatorname{onClick}\ V : 1\mathbin{!}\operatorname{Mut}} Γ ; Π ; Φ M ⊢ runClick onClick V : 1 ! Mut Γ ; Π ; Φ M ⊢ onClick V : Attr
Γ ; Π ; Φ M ⊢ V : 1 → Mut 1 Γ ; Π ; ∅ ⊢ ( ) : 1 Γ ; Π ; Φ M ⊢ V ( ) : 1 ! Mut \frac{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{M} \vdash V : 1 \xrightarrow{\operatorname{Mut}} 1 \qquad\Gamma\mathbin{;} \Pi\mathbin{;} \emptyset\vdash() : 1}{\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{M} \vdash V\ () : 1\mathbin{!}\operatorname{Mut}} Γ ; Π ; Φ M ⊢ V ( ) : 1 ! Mut Γ ; Π ; Φ M ⊢ V : 1 Mut 1 Γ ; Π ; ∅ ⊢ ( ) : 1
⟦ H ⟧ ϱ ; ⟦ runClick onClick V ⟧ ϱ (def. of translation) = runClick onClick ⟦ V ⟧ ϱ ; ⟦ H ⟧ ϱ (EC-RunClick) ⇝ ⟦ V ⟧ ϱ ( ) ; ⟦ H ⟧ ϱ (def. of translation) = ⟦ V ( ) ⟧ ϱ ; ⟦ H ⟧ ϱ \begin{aligned}
\llbracket\mathcal{H} \rrbracket_{\varrho} \mathbin{;} \llbracket\operatorname{runClick}\ \operatorname{onClick}\ V \rrbracket_{\varrho}\\
\text{(def. of translation)} \quad= \operatorname{runClick}\ \operatorname{onClick}\ \llbracket V \rrbracket_{\varrho} \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho}\\
\text{(EC-RunClick)} \quad\rightsquigarrow\llbracket V \rrbracket_{\varrho}() \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho}\\
\text{(def. of translation)} \quad= \llbracket V() \rrbracket_{\varrho} \mathbin{;} \llbracket\mathcal{H} \rrbracket_{\varrho}
\end{aligned} [ [ H ] ] ϱ ; [ [ runClick onClick V ] ] ϱ (def. of translation) = runClick onClick [ [ V ] ] ϱ ; [ [ H ] ] ϱ (EC-RunClick) ⇝ [ [ V ] ] ϱ ( ) ; [ [ H ] ] ϱ (def. of translation) = [ [ V ( ) ] ] ϱ ; [ [ H ] ] ϱ
Case EC-UpdateText and Case EC-UpdateTag are analogous to EC-InitText and EC-InitTag respectively.
Case EC-UpdateCompT: We have, for H ′ = H ∣ H [ p ] . rerender ↦ ff \mathcal{H}' = \mathcal{H} \mid\mathcal{H}[p].\operatorname{rerender} \mapsto\operatorname{ff} H ′ = H ∣ H [ p ] . rerender ↦ ff ,
H [ p ] . rerender = tt H ; update compInst p ( ⟦ D ⟧ , v ) ⇝ ⟦ D ⟧ ↓ p Succ D ; H ′ EC-UpdateCompT \frac{\mathcal{H}[p].\operatorname{rerender} = \operatorname{tt}}{\mathcal{H}\mathbin{;} \operatorname{update}\ \operatorname{compInst}_{p}(\llbracket D \rrbracket,v) \rightsquigarrow\llbracket D \rrbracket\mathord{\downarrow}_{p}^{\operatorname{Succ}} D\mathbin{;} \mathcal{H}'} \ \text{EC-UpdateCompT} H ; update compInst p ( [ [ D ] ] , v ) ⇝ [ [ D ] ] ↓ p Succ D ; H ′ H [ p ] . rerender = tt EC-UpdateCompT
Γ ; Π ; Φ 1 ⊢ D : Π [ p ] ( Φ 1 ◀ Φ 2 ) [ p ] = Succ Γ ; Π ; Φ 2 ⊢ V : ElemInst Γ ; Π ; Φ 1 ◀ Φ 2 ⊢ compInst p ( ⟦ D ⟧ , V ) : ElemInst TV-CompI \frac{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \vdash D : \Pi[p]
\qquad
(\Phi_{1} \mathbin{\blacktriangleleft} \Phi_{2})[p] = \operatorname{Succ}
\qquad
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{2} \vdash V : \operatorname{ElemInst}
}{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \mathbin{\blacktriangleleft} \Phi_{2} \vdash\operatorname{compInst}_{p}(\llbracket D \rrbracket,V) : \operatorname{ElemInst}
}\ \text{TV-CompI} Γ ; Π ; Φ 1 ◀ Φ 2 ⊢ compInst p ( [ [ D ] ] , V ) : ElemInst Γ ; Π ; Φ 1 ⊢ D : Π [ p ] ( Φ 1 ◀ Φ 2 ) [ p ] = Succ Γ ; Π ; Φ 2 ⊢ V : ElemInst TV-CompI
Γ ; Π ; Φ 1 ◀ Φ 2 ⊢ compInst p ( ⟦ D ⟧ , V ) : ElemInst Γ ; Π ; Φ 1 ◀ Φ 2 ⊢ update compInst p ( ⟦ D ⟧ , V ) : ElemInst ! Mut TC-Update \frac{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \mathbin{\blacktriangleleft} \Phi_{2} \vdash\operatorname{compInst}_{p}(\llbracket D \rrbracket,V) : \operatorname{ElemInst}
}{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{1} \mathbin{\blacktriangleleft} \Phi_{2} \vdash\operatorname{update}\ \operatorname{compInst}_{p}(\llbracket D \rrbracket,V) : \operatorname{ElemInst}\ !\ \operatorname{Mut}
}\ \text{TC-Update} Γ ; Π ; Φ 1 ◀ Φ 2 ⊢ update compInst p ( [ [ D ] ] , V ) : ElemInst ! Mut Γ ; Π ; Φ 1 ◀ Φ 2 ⊢ compInst p ( [ [ D ] ] , V ) : ElemInst TC-Update
We retain Φ N = Φ M \Phi_{N} = \Phi_{M} Φ N = Φ M , Φ H ′ = Φ H \Phi'_{H} = \Phi_{H} Φ H ′ = Φ H , Π ′ = Π \Pi' = \Pi Π ′ = Π , and ϱ ′ = ϱ \varrho' = \varrho ϱ ′ = ϱ . Conclusions (i) and (ii) are trivial. By premise (i-b), we have Γ ; Π ; Φ H ⊨ H ′ \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{H} \models\mathcal{H}' Γ ; Π ; Φ H ⊨ H ′ , satisfying conclusion (iii-b).
We have ids ( ⟦ D ⟧ ↓ p Succ D ) = ids ( D ) ⊆ ids ( D ) ∪ ids ( V ) = ids ( update compInst p ( ⟦ D ⟧ , V ) ) \operatorname{ids}(\llbracket D \rrbracket\mathord{\downarrow}_{p}^{\operatorname{Succ}} D) = \operatorname{ids}(D) \subseteq\operatorname{ids}(D) \cup\operatorname{ids}(V) = \operatorname{ids}(\operatorname{update}\ \operatorname{compInst}_{p}(\llbracket D \rrbracket,V)) ids ( [ [ D ] ] ↓ p Succ D ) = ids ( D ) ⊆ ids ( D ) ∪ ids ( V ) = ids ( update compInst p ( [ [ D ] ] , V )) , so conclusion (iv) is given by premise (ii).
By Lemma A.4 (unrestriction) on (3), we must have (5) Succ ( Φ 2 ) \operatorname{Succ}(\Phi_{2}) Succ ( Φ 2 ) .
By Lemma A.11 (Φ \Phi Φ -weakening) on (1) using (5), we get (6) that Γ ; Π ; Φ M ⊢ D : Π [ p ] \Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{M} \vdash D : \Pi[p] Γ ; Π ; Φ M ⊢ D : Π [ p ] .
We derive conclusion (i) as follows, noting that Φ M ◀ Φ M = Φ M \Phi_{M} \mathbin{\blacktriangleleft} \Phi_{M} = \Phi_{M} Φ M ◀ Φ M = Φ M by (5):
Γ ; Π ; Φ M ⊢ D : Π [ p ] Π [ p ] ⊆ Π [ p ] Φ M [ p ] = Succ Γ ; Π ; Φ M ⊢ ⟦ D ⟧ ↓ p Succ D : Element ! Mut TC-EvalS \frac{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{M} \vdash D : \Pi[p]
\qquad
\Pi[p] \subseteq\Pi[p]
\qquad
\Phi_{M}[p] = \operatorname{Succ}
}{
\Gamma\mathbin{;} \Pi\mathbin{;} \Phi_{M} \vdash\llbracket D \rrbracket\mathord{\downarrow}_{p}^{\operatorname{Succ}} D : \operatorname{Element}\ !\ \operatorname{Mut}
}\ \text{TC-EvalS} Γ ; Π ; Φ M ⊢ [ [ D ] ] ↓ p Succ D : Element ! Mut Γ ; Π ; Φ M ⊢ D : Π [ p ] Π [ p ] ⊆ Π [ p ] Φ M [ p ] = Succ TC-EvalS
⟦ H ⟧ ρ ; ⟦ update compInst p ( ⌈ D ⌉ , V ) ⟧ ρ (def. of translation) = update compInst ( S ⟦ D ⟧ ( p , ρ , ∅ ) ρ ( p ) , ⟦ V ⟧ ρ ) (EC-UpdateComp) ⇝ let x = if ! ρ ( p ) then ρ ( p ) : = false ; init ( ( λ ( ) . S ⟦ D ⟧ ( p , ρ , ∅ ) ) ( ) ) else update ⟦ V ⟧ ρ in compInst ( λ ( ) . S ⟦ D ⟧ ( p , ρ , ∅ ) , ρ ( p ) , x ) ; ⟦ H ⟧ ρ (EC-Get, (7), EC-IfT) ⇝ + let x = ρ ( p ) : = false ; init ( ( λ ( ) . S ⟦ D ⟧ ( p , ρ , ∅ ) ) ( ) ) in compInst ( λ ( ) . S ⟦ D ⟧ ( p , ρ , ∅ ) , ρ ( p ) , x ) ; ⟦ H ⟧ ρ (EC-Set, EC-Val) ⇝ + let x = init ( λ ( ) . S ⟦ D ⟧ ( p , ρ , ∅ ) ( ) ) in inst ( λ ( ) . S ⟦ D ⟧ ( p , ρ , ∅ ) , ρ ( p ) , x ) ; ⟦ H ⟧ ρ [ ρ ( p ) ↦ false ] (EC-App) ⇝ let x = init ( S ⟦ D ⟧ ( p , ρ , ∅ ) ) in compInst ( λ ( ) . S ⟦ D ⟧ ( p , ρ , ∅ ) , ρ ( p ) , x ) ; ⟦ H ⟧ ρ [ ρ ( p ) ↦ false ] (def. of translation) = ⟦ ⌈ D ⌉ ↓ p S u c c D ⟧ ρ ; ⟦ H ′ ⟧ ρ \begin{aligned}
\llbracket H\rrbracket_{\rho}\ ;\ \llbracket\operatorname{update}\operatorname{compInst}_{p}(\lceil D\rceil,V)\rrbracket_{\rho}\\
&\mathrel{\text{(def. of translation)}}=\operatorname{update}\operatorname{compInst}(S\llbracket D\rrbracket(p,\rho,\emptyset)_{\rho}(p),\llbracket V\rrbracket_{\rho})\\
&\mathrel{\text{(EC-UpdateComp)}}\rightsquigarrow\operatorname{let}\ x=\operatorname{if}\ !\rho(p)\\
&\qquad\operatorname{then}\ \rho(p):=\operatorname{false}\ ;\ \operatorname{init}\left((\lambda().S\llbracket D\rrbracket(p,\rho,\emptyset))()\right)\\
&\qquad\operatorname{else}\ \operatorname{update}\ \llbracket V\rrbracket_{\rho}\\
&\qquad\operatorname{in}\ \operatorname{compInst}(\lambda().S\llbracket D\rrbracket(p,\rho,\emptyset),\rho(p),x)\ ;\ \llbracket H\rrbracket_{\rho}\\
&\mathrel{\text{(EC-Get, (7), EC-IfT)}}\rightsquigarrow^{+}\operatorname{let}\ x=\rho(p):=\operatorname{false}\ ;\ \operatorname{init}\left((\lambda().S\llbracket D\rrbracket(p,\rho,\emptyset))()\right)\\
&\qquad\operatorname{in}\ \operatorname{compInst}(\lambda().S\llbracket D\rrbracket(p,\rho,\emptyset),\rho(p),x)\ ;\ \llbracket H\rrbracket_{\rho}\\
&\mathrel{\text{(EC-Set, EC-Val)}}\rightsquigarrow^{+}\operatorname{let}\ x=\operatorname{init}\left(\lambda().S\llbracket D\rrbracket(p,\rho,\emptyset)()\right)\\
&\qquad\operatorname{in}\ \operatorname{inst}(\lambda().S\llbracket D\rrbracket(p,\rho,\emptyset),\rho(p),x)\ ;\ \llbracket H\rrbracket_{\rho}[\rho(p)\mapsto\operatorname{false}]\\
&\mathrel{\text{(EC-App)}}\rightsquigarrow\operatorname{let}\ x=\operatorname{init}\left(S\llbracket D\rrbracket(p,\rho,\emptyset)\right)\operatorname{in}\operatorname{compInst}(\lambda().S\llbracket D\rrbracket(p,\rho,\emptyset),\rho(p),x)\ ;\\
&\qquad\llbracket H\rrbracket_{\rho}[\rho(p)\mapsto\operatorname{false}]\\
&\mathrel{\text{(def. of translation)}}=\llbracket\lceil D\rceil\mathord{\downarrow}^{\mathrm{Succ}}_{p}D\rrbracket_{\rho}\ ;\ \llbracket H'\rrbracket_{\rho}
\end{aligned} [ [ H ] ] ρ ; [ [ update compInst p (⌈ D ⌉ , V ) ] ] ρ (def. of translation) = update compInst ( S [ [ D ] ] ( p , ρ , ∅ ) ρ ( p ) , [ [ V ] ] ρ ) (EC-UpdateComp) ⇝ let x = if ! ρ ( p ) then ρ ( p ) := false ; init ( ( λ ( ) . S [ [ D ] ] ( p , ρ , ∅ )) ( ) ) else update [ [ V ] ] ρ in compInst ( λ ( ) . S [ [ D ] ] ( p , ρ , ∅ ) , ρ ( p ) , x ) ; [ [ H ] ] ρ (EC-Get, (7), EC-IfT) ⇝ + let x = ρ ( p ) := false ; init ( ( λ ( ) . S [ [ D ] ] ( p , ρ , ∅ )) ( ) ) in compInst ( λ ( ) . S [ [ D ] ] ( p , ρ , ∅ ) , ρ ( p ) , x ) ; [ [ H ] ] ρ (EC-Set, EC-Val) ⇝ + let x = init ( λ ( ) . S [ [ D ] ] ( p , ρ , ∅ ) ( ) ) in inst ( λ ( ) . S [ [ D ] ] ( p , ρ , ∅ ) , ρ ( p ) , x ) ; [ [ H ] ] ρ [ ρ ( p ) ↦ false ] (EC-App) ⇝ let x = init ( S [ [ D ] ] ( p , ρ , ∅ ) ) in compInst ( λ ( ) . S [ [ D ] ] ( p , ρ , ∅ ) , ρ ( p ) , x ) ; [ [ H ] ] ρ [ ρ ( p ) ↦ false ] (def. of translation) = [ [ ⌈ D ⌉ ↓ p Succ D ] ] ρ ; [ [ H ′ ] ] ρ
Case EC-UpdateCompF: Analogous to EC-ClickTagF. □
Received 20 February 2007; revised 12 March 2009; accepted 5 June 2009.