Open GADTs and declaration-site variance: a problem statement

  • Authors:
  • Paolo G. Giarrusso

  • Affiliations:
  • Philipps University Marburg

  • Venue:
  • Proceedings of the 4th Workshop on Scala
  • Year:
  • 2013

Quantified Score

Hi-index 0.00

Visualization

Abstract

Generalized algebraic data types (GADTs) allow embedding extensible typed ASTs and transformations on them. Such transformations on typed ASTs are useful for code optimization in deeply embedded DSLs, for instance when using Lightweight Modular Staging (LMS). However, in Scala it is hard to make transformations for typed ASTs type-safe. Therefore, AST transformations in LMS are often not fully typechecked, preventing bugs from being caught early and without extensive testing. We show that writing type-safe transformations in such embeddings is in fact not just hard, but impossible without using unsafe casts or significantly restricting extensibility: Declaration-site variance opens GADTs representing typed ASTs not only to desirable extensions, but also to extensions that introduce exotic terms. We make the problem concrete on an embedding of λ through covariant GADTs. We discuss solution approaches, and sketch a Scala extension to address this problem without either introducing unsafe casts or restricting extensibility. We believe a complete solution would significantly ease writing transformations by allowing type-checking to verify them, and thus would ease their development.