Moebius: Metaprogramming using Contextual Types – The stage where System F can pattern match on itself (Long Version)

11/15/2021
by   Junyoung Jang, et al.
0

We describe the foundation of the metaprogramming language, Moebius, which supports the generation of polymorphic code and, more importantly the analysis of polymorphic code via pattern matching. Moebius has two main ingredients: 1) we exploit contextual modal types to describe open code together with the context in which it is meaningful. In Moebius, open code can depend on type and term variables (level 0) whose values are supplied at a later stage, as well as code variables (level 1) that stand for code templates supplied at a later stage. This leads to a multi-level modal lambda-calculus that supports System-F style polymorphism and forms the basis for polymorphic code generation. 2) we extend the multi-level modal lambda-calculus to support pattern matching on code. As pattern matching on polymorphic code may refine polymorphic type variables, we extend our type-theoretic foundation to generate and track typing constraints that arise. We also give an operational semantics and prove type preservation. Our multi-level modal foundation for Moebius provides the appropriate abstractions for both generating and pattern matching on open code without committing to a concrete representation of variable binding and contexts. Hence, our work is a step towards building a general type-theoretic foundation for multi-staged metaprogramming that, on the one hand, enforces strong type guarantees and, on the other hand, makes it easy to generate and manipulate code. This will allow us to exploit the full potential of metaprogramming without sacrificing the reliability of and trust in the code we are producing and running.

READ FULL TEXT

page 1

page 2

page 3

page 4

research
11/22/2022

A Categorical Normalization Proof for the Modal Lambda-Calculus

We investigate a simply typed modal λ-calculus, λ^→□, due to Pfenning, W...
research
01/28/2018

Polymorphic Context for Contextual Modality

Through the Curry-Howard isomorphism between logics and calculi, necessi...
research
03/04/2021

Contextual Modal Types for Algebraic Effects and Handlers

Programming languages with algebraic effects often rely on effect annota...
research
05/11/2023

Layered Modal Type Theories

We introduce layers to modal type theories, which subsequently enables t...
research
12/07/2021

A Specification for Typed Template Haskell

Multi-stage programming is a proven technique that provides predictable ...
research
08/06/2019

A Dependently Typed Multi-Stage Calculus

We study a dependently typed extension of a multi-stage programming lang...
research
09/15/2022

A case for DOT: Theoretical Foundations for Objects With Pattern Matching and GADT-style Reasoning

Many programming languages in the OO tradition now support pattern match...

Please sign up or login with your details

Forgot password? Click here to reset