The swiss coercion

  • Authors:
  • Stefan Monnier

  • Affiliations:
  • Université de Montréal, Montréal, PQ, Canada

  • Venue:
  • PLPV '07 Proceedings of the 2007 workshop on Programming languages meets program verification
  • Year:
  • 2007

Quantified Score

Hi-index 0.00

Visualization

Abstract

Recent type systems allow the programmer to use types that describe more precisely the invariants on which the program relies. But in order to satisfy the type system, it often becomes necessary to help the type checker with extra annotations that justify why a piece of code is indeed well-formed. Such annotations take the form of term-level type manipulations, such as type abstractions, type applications, existential package packing and opening, as well as coercions, or casts. While those operations have no direct runtime cost, they tend to introduce extra runtime operations equivalent to n-redexes or even empty loops in order to get to the point where we can apply that supposedly free operation. We show a coercion that is like a pacific Swiss army knife of coercions: it cannot cut but it can instantiate, open, pack, abstract, analyze, or do any combination thereof, reducing the need for extra surrounding runtime operations. And all that, of course, for the price of a single coercion, which still costs absolutely nothing at runtime. This new coercion is derived from Karl Crary's coercion calculus [Crary, 2000], but can also replace Crary and Weirich's vcase [Crary and Weirich, 1999]. It additionally happens to come in handy to work around some limitations of value polymorphism. It is presented in the context of Shao et al.'s Type System for Certified Binaries [Shao et al., 2002]. Other than the coercion itself, another interesting aspect of this work is a slightly unusual proof technique to show soundness of the type erasure using a pure type assignment language, making the no-op nature of our cast more obvious.