Graduality and parametricity: together again for the first time

Parametric polymorphism and gradual typing have proven to be a difficult combination, with no language yet produced that satisfies the fundamental theorems of each: parametricity and graduality. Notably, Toro, Labrada, and Tanter (POPL 2019) conjecture that for any gradual extension of System F that uses dynamic type generation, graduality and parametricity are ``simply incompatible''. However, we argue that it is not graduality and parametricity that are incompatible per se, but instead that combining the syntax of System F with dynamic type generation as in previous work necessitates type-directed computation, which we show has been a common source of graduality and parametricity violations in previous work. We then show that by modifying the syntax of universal and existential types to make the type name generation explicit, we remove the need for type-directed computation, and get a language that satisfies both graduality and parametricity theorems. The language has a simple runtime semantics, which can be explained by translation to a statically typed language where the dynamic type is interpreted as a dynamically extensible sum type. Far from being in conflict, we show that the parametricity theorem follows as a direct corollary of a relational interpretation of the graduality property.

[1]  Derek Dreyer,et al.  State-dependent representation independence , 2009, POPL '09.

[2]  Éric Tanter,et al.  Gradual Typestate , 2011, ECOOP.

[3]  Philip Wadler,et al.  Blame for all , 2011, POPL '11.

[4]  Atsushi Igarashi,et al.  On polymorphic gradual typing , 2017, Proc. ACM Program. Lang..

[5]  Giuseppe Castagna,et al.  Gradual typing with union and intersection types , 2017, Proc. ACM Program. Lang..

[6]  John C. Reynolds,et al.  Types, Abstraction and Parametric Polymorphism , 1983, IFIP Congress.

[7]  Matteo Cimini,et al.  Principal Type Schemes for Gradual Programs , 2015, POPL.

[8]  Dave Clarke,et al.  Gradual Ownership Types , 2012, ESOP.

[9]  Matthias Felleisen,et al.  On the Expressive Power of Programming Languages , 1990, European Symposium on Programming.

[10]  Sam Tobin-Hochstadt,et al.  Gradual typing for first-class classes , 2012, OOPSLA '12.

[11]  Amr Sabry,et al.  Reasoning about programs in continuation-passing style , 1992, LFP '92.

[12]  John C. Mitchell,et al.  Abstract types have existential type , 1988, TOPL.

[13]  Paul Blain Levy,et al.  Call-By-Push-Value: A Functional/Imperative Synthesis , 2003, Semantics Structures in Computation.

[14]  Uday S. Reddy,et al.  Parametricity as a notion of uniformity in reflexive graphs , 2002 .

[15]  Matías Toro,et al.  Type-Driven Gradual Security with References , 2018, ACM Trans. Program. Lang. Syst..

[16]  Martín Abadi,et al.  A Logic for Parametric Polymorphism , 1993, TLCA.

[17]  Sam Tobin-Hochstadt,et al.  Interlanguage migration: from scripts to programs , 2006, OOPSLA '06.

[18]  Sam Tobin-Hochstadt,et al.  The design and implementation of typed scheme , 2008, POPL '08.

[19]  John Tang Boyland,et al.  Refined Criteria for Gradual Typing , 2015, SNAPL.

[20]  Jeremy G. Siek Gradual Typing for Functional Languages , 2006 .

[21]  Georg Neis,et al.  Non-parametric parametricity , 2009, ICFP.

[22]  Éric Tanter,et al.  Abstracting gradual typing , 2016, POPL.

[23]  Daniel R. Licata,et al.  Gradual type theory , 2019, Proc. ACM Program. Lang..

[24]  John C. Reynolds,et al.  Types, Abstractions, and Parametric Polymorphism, Part 2 , 1991, MFPS.

[25]  Atsushi Igarashi,et al.  Gradual typing for generics , 2011, OOPSLA '11.

[26]  Benjamin C. Pierce,et al.  A bisimulation for dynamic sealing , 2004, Theor. Comput. Sci..

[27]  Bruno C. d. S. Oliveira,et al.  Consistent Subtyping for All , 2018, ESOP.

[28]  John Boyland The Problem of Structural Type Tests in a Gradual-Typed Language , 2014 .

[29]  Peter Thiemann,et al.  Gradual Security Typing with References , 2013, 2013 IEEE 26th Computer Security Foundations Symposium.

[30]  Peter Thiemann,et al.  Gradual session types , 2017, Journal of Functional Programming.

[31]  GarciaRonald,et al.  Principal Type Schemes for Gradual Programs , 2015 .

[32]  Max S. New,et al.  Graduality from embedding-projection pairs , 2018, Proc. ACM Program. Lang..

[33]  C. Flanagan,et al.  Gradual Information Flow Typing , 2011 .

[34]  Éric Tanter,et al.  Gradual refinement types , 2017, POPL.

[35]  Éric Tanter,et al.  A theory of gradual effect systems , 2014, ICFP.

[36]  Philip Wadler,et al.  Theorems for free for free: parametricity, with and without types , 2017, Proc. ACM Program. Lang..

[37]  Matías Toro,et al.  Gradual parametricity, revisited , 2018, Proc. ACM Program. Lang..

[38]  Walid Taha,et al.  Gradual Typing for Objects , 2007, ECOOP.