We study a dependently typed extension of a multi-stage programming languageà la MetaOCaml, which supports quasi-quotation and cross-stage persistence for manipulation of code fragments as firstclass values and an evaluation construct for execution of programs dynamically generated by this code manipulation. Dependent types are expected to bring to multi-stage programming enforcement of strong invariant-beyond simple type safety-on the behavior of dynamically generated code. An extension is, however, not trivial because such a type system would have to take stages of types-roughly speaking, the number of surrounding quotations-into account. To rigorously study properties of such an extension, we develop λ MD , which is an extension of Hanada and Igarashi's typed calculus λ ⊲% with dependent types, and prove its properties including preservation, confluence, strong normalization for full reduction, and progress for staged reduction. Motivated by code generators that generate code whose type depends on a value from outside of the quotations, we argue the significance of cross-stage persistence in dependently typed multi-stage programming and certain type equivalences that are not directly derived from reduction rules.
A. Kawata, A. Igarashi
B ProofsJ is a metavariable for judgments as in Section 4. We say type environment Γ is a subsequence of type environment ∆ if and only if we can get Γ from ∆ by deleting some or no variables without changing the order of the remaining elements.Lemma 4 (Weakening). If Γ ⊢ Σ J @A and Γ is a subsequence of ∆, then ∆ ⊢ Σ J@A.Proof. By straightforward induction on the derivation of typing, kinding, wellformed kinding, term equivalence, type equivalence or kind equivalence. We show only representative cases.