Projects per year
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.
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.
Original language | English |
---|---|
Article number | 61 |
Number of pages | 30 |
Journal | Proceedings of the ACM on Programming Languages |
Volume | 6 |
Issue number | POPL |
DOIs | |
Publication status | Published - 12 Jan 2022 |
Bibliographical note
Funding Information:We thank Dimitrios Vytiniotis, and the anonymous reviewers for their insightful comments. The work is partly supported by EPSRC Grant SCOPE: Scoped Contextual Programming with Effects (EP/S028129/1) and Grant EXHIBIT: Expressive High-Level Languages for Bidirectional Transformations (EP/T008911/1).
Publisher Copyright:
© 2022 Owner/Author.
Research Groups and Themes
- Programming Languages
Keywords
- Staging
- Type Classes
- Typed Template Haskell
Fingerprint
Dive into the research topics of 'Staging with Class: A Specification for Typed Template Haskell'. Together they form a unique fingerprint.Projects
- 1 Finished
-
8030 EPSRC EP/T008911/1 EXHIBIT : Expressive High-Level Languages for Bidirectional Transformations
Wang, M. (Principal Investigator)
1/07/20 → 30/06/23
Project: Research