Visible to the public Expressive and Strongly Type-Safe Code Generation

TitleExpressive and Strongly Type-Safe Code Generation
Publication TypeConference Paper
Year of Publication2017
AuthorsWinant, Thomas, Cockx, Jesper, Devriese, Dominique
Conference NameProceedings of the 19th International Symposium on Principles and Practice of Declarative Programming
PublisherACM
Conference LocationNew York, NY, USA
ISBN Number978-1-4503-5291-8
KeywordsCollaboration, Dependent types, human factors, meta-programming, Metrics, policy-based governance, Policy-Governed Secure Collaboration, pubcrawl, resilience, Resiliency, Safe Coding
Abstract

Meta-programs are programs that generate other programs, but in weakly type-safe systems, type-checking a meta-program only establishes its own type safety, and generated programs need additional type-checking after generation. Strong type safety of a meta-program implies type safety of any generated object program, a property with important engineering benefits. Current strongly type-safe systems suffer from expressivity limitations and cannot support many meta-programs found in practice, for example automatic generation of lenses. To overcome this, we move away from the idea of staged meta-programming. Instead, we use an off-the-shelf dependently-typed language as the meta-language and a relatively standard, intrinsically well-typed representation of the object language. We scale this approach to practical meta-programming, by choosing a high-level, explicitly typed intermediate representation as the object language, rather than a surface programming language. We implement our approach as a library for the Glasgow Haskell Compiler (GHC) and evaluate it on several meta-programs, including a deriveLenses meta-program taken from a real-world Haskell lens library. Our evaluation demonstrates expressivity beyond the state of the art and applicability to real settings, at little cost in terms of code size.

URLhttps://dl.acm.org/citation.cfm?doid=3131851.3131872
DOI10.1145/3131851.3131872
Citation Keywinant_expressive_2017