The Simple Essence of Monomorphization
Monomorphization is a common implementation technique for parametric type-polymorphism, which avoids the potential runtime overhead of uniform representations at the cost of code duplication. While important as a folklore implementation technique, there is a lack of general formal treatments in the published literature. Moreover, it is commonly believed to be incompatible with higher-rank polymorphism. In this paper, we formally present a simple monomorphization technique based on a type-based flow analysis that generalizes to programs with higher-rank types, existential types, and arbitrary combinations. Inspired by algebraic subtyping, we track the flow of type instantiations through the program. Our approach only supports monomorphization up to polymorphic recursion, which we uniformly detect as cyclic flow. Treating universal and existential quantification uniformly, we identify a novel form of polymorphic recursion in the presence of existential types, which we coin polymorphic packing. We study the meta-theory of our approach, showing that our translation is type-preserving and preserves semantics step-wise.
Authors
- Matthew Lutze (ORCID: https://orcid.org/0000-0002-2904-5099)
- Jonathan Immanuel Brachthäuser (ORCID: https://orcid.org/0000-0001-9128-0391)
- Philipp Schuster (ORCID: https://orcid.org/0000-0001-8011-0506)
Institutions
- Aarhus University (DK)
- University of Tübingen (DE)
Publication Details
- Journal
- Proceedings of the ACM on Programming Languages
- Published
- 2025-04-09
- DOI
- https://doi.org/10.1145/3720472
- Citations
- 2
- Primary Topic
- Logic, programming, and type systems
- Type
- article
- Field-Weighted Citation Impact
- 4.96