Affiliation:
1. University of Cambridge, UK
2. Well-Typed LLP, UK
3. Imperial College London, UK
4. University of Bristol, UK
Abstract
Multi-stage programming using typed code quotation is an established technique for writing optimizing code generators with strong type-safety guarantees. Unfortunately, quotation in Haskell interacts poorly with type classes, making it difficult to write robust multi-stage programs.
We study this unsound interaction and propose a resolution, staged type class constraints, which we formalize in a source calculus λ
⇒
that elaborates into an explicit core calculus
F
. We show type soundness of both calculi, establishing that well-typed, well-staged source programs always elaborate to well-typed, well-staged core programs, and prove beta and eta rules for code quotations.
Our design allows programmers to incorporate type classes into multi-stage programs with confidence. Although motivated by Haskell, it is also suitable as a foundation for other languages that support both overloading and quotation.
Funder
Engineering and Physical Sciences Research Council
Publisher
Association for Computing Machinery (ACM)
Subject
Safety, Risk, Reliability and Quality,Software
Cited by
3 articles.
订阅此论文施引文献
订阅此论文施引文献,注册后可以免费订阅5篇论文的施引文献,订阅后可以查看论文全部施引文献
1. MacoCaml: Staging Composable and Compilable Macros;Proceedings of the ACM on Programming Languages;2023-08-30
2. First-Class Data Types in Shallow Embedded Domain-Specific Languages using Metaprogramming;Proceedings of the 34th Symposium on Implementation and Application of Functional Languages;2022-08-31
3. Staged compilation with two-level type theory;Proceedings of the ACM on Programming Languages;2022-08-29