skip to main content

Refinement kinds: type-safe programming with practical type-level computation

Authors Info & Claims
Published:10 October 2019Publication History
Skip Abstract Section

Abstract

This work introduces the novel concept of kind refinement, which we develop in the context of an explicitly polymorphic ML-like language with type-level computation. Just as type refinements embed rich specifications by means of comprehension principles expressed by predicates over values in the type domain, kind refinements provide rich kind specifications by means of predicates over types in the kind domain. By leveraging our powerful refinement kind discipline, types in our language are not just used to statically classify program expressions and values, but also conveniently manipulated as tree-like data structures, with their kinds refined by logical constraints on such structures. Remarkably, the resulting typing and kinding disciplines allow for powerful forms of type reflection, ad-hoc polymorphism and type-directed meta-programming, which are often found in modern software development, but not typically expressible in a type-safe manner in general purpose languages. We validate our approach both formally and pragmatically by establishing the standard meta-theoretical results of type safety and via a prototype implementation of a kind checker, type checker and interpreter for our language.

Skip Supplemental Material Section

Supplemental Material

a131-caires

Presentation at OOPSLA '19

References

  1. Martín Abadi, Luca Cardelli, Benjamin C. Pierce, and Gordon D. Plotkin. 1991. Dynamic Typing in a Statically Typed Language. ACM Trans. Program. Lang. Syst. 13, 2 (1991), 237–268. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Thorsten Altenkirch and Conor McBride. 2002. Generic Programming within Dependently Typed Programming. In Generic Programming, IFIP TC2/WG2.1 Working Conference on Generic Programming, July 11-12, 2002, Dagstuhl, Germany (IFIP Conference Proceedings), Jeremy Gibbons and Johan Jeuring (Eds.), Vol. 243. Kluwer, 1–20.Google ScholarGoogle Scholar
  3. Kshitij Bansal, Clark Barrett, Andrew Reynolds, and Cesare Tinelli. 2018. Reasoning with Finite Sets and Cardinality Constraints in SMT. Logical Methods in Computer Science 14, 4 (2018). Google ScholarGoogle ScholarCross RefCross Ref
  4. Clark Barrett, Christopher L. Conway, Morgan Deters, Liana Hadarean, Dejan Jovanovic, Tim King, Andrew Reynolds, and Cesare Tinelli. 2011. CVC4. In Computer Aided Verification - 23rd International Conference, CAV 2011, Snowbird, UT, USA, July 14-20, 2011. Proceedings. 171–177. Google ScholarGoogle ScholarCross RefCross Ref
  5. J. Bengtson, K. Bhargavan, C. Fournet, A. D. Gordon, and S. Maffeis. 2011. Refinement Types for Secure Implementations. ACM Trans. Program. Lang. Syst. (2011).Google ScholarGoogle Scholar
  6. Luís Caires and Bernardo Toninho. 2019. Refinement Kinds: Type-safe Programming with Practical Type-level Computation (Extended Version). CoRR abs/1908.00441 (2019). http://arxiv.org/abs/1908.00441Google ScholarGoogle Scholar
  7. Cristiano Calcagno, Eugenio Moggi, and Tim Sheard. 2003. Closed types for a safe imperative MetaML. J. Funct. Program. 13, 3 (2003), 545–571. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Luca Cardelli. 1991. Typeful Programming. IFIP State-of-the-Art Reports: Formal Description of Programming Concepts (1991), 431–507.Google ScholarGoogle Scholar
  9. Adam Chlipala. 2010. Ur: statically-typed metaprogramming with type-level record computation. In Proceedings of the 2010 ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2010, Toronto, Ontario, Canada, June 5-10, 2010, Benjamin G. Zorn and Alexander Aiken (Eds.). ACM, 122–133. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Robert L. Constable, Stuart F. Allen, Mark Bromley, Rance Cleaveland, J. F. Cremer, R. W. Harper, Douglas J. Howe, Todd B. Knoblock, N. P. Mendler, Prakash Panangaden, James T. Sasaki, and Scott F. Smith. 1986. Implementing mathematics with the Nuprl proof development system. Prentice Hall. http://dl.acm.org/citation.cfm?id=10510Google ScholarGoogle Scholar
  11. CoqDevelopmentTeam. 2004. The Coq proof assistant reference manual. LogiCal Project. http://coq.inria.fr Version 8.0.Google ScholarGoogle Scholar
  12. Leonardo Mendonça de Moura and Nikolaj Bjørner. 2008. Z3: An Efficient SMT Solver. In Tools and Algorithms for the Construction and Analysis of Systems, 14th International Conference, TACAS 2008, (Lecture Notes in Computer Science), C. R. Ramakrishnan and Jakob Rehof (Eds.), Vol. 4963. Springer, 337–340. Google ScholarGoogle ScholarCross RefCross Ref
  13. Manuel Fähndrich, Michael Carbin, and James R. Larus. 2006. Reflective program generation with patterns. In Generative Programming and Component Engineering, 5th International Conference, GPCE 2006, Portland, Oregon, USA, October 22-26, 2006, Proceedings, Stan Jarzabek, Douglas C. Schmidt, and Todd L. Veldhuizen (Eds.). ACM, 275–284. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Timothy S. Freeman and Frank Pfenning. 1991. Refinement Types for ML. In Proceedings of the ACM SIGPLAN’91 Conference on Programming Language Design and Implementation (PLDI), Toronto, Ontario, Canada, June 26-28, 1991, David S. Wise (Ed.). ACM, 268–277. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Benedict R. Gaster and Mark P. Jones. 1996. A Polymorphic Type System for Extensible Records and Variants. Technical Report NOT TCS-TR-96-3. Functional Programming Research Group, Department of Computer Science, University of Nottingham.Google ScholarGoogle Scholar
  16. Eduardo Giménez. 1998. Structural Recursive Definitions in Type Theory. In Automata, Languages and Programming, 25th International Colloquium, ICALP’98, Aalborg, Denmark, July 13-17, 1998, Proceedings. 397–408. Google ScholarGoogle ScholarCross RefCross Ref
  17. Jean-Yves Girard. 1986. The system F of variable types, fifteen years later. Theoretical Computer Science 45 (1986), 159 – 192. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Cordelia V. Hall, Kevin Hammond, Simon L. Peyton Jones, and Philip Wadler. 1996. Type Classes in Haskell. ACM Trans. Program. Lang. Syst. 18, 2 (1996), 109–138. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Robert Harper and Benjamin C. Pierce. 1991. A Record Calculus Based on Symmetric Concatenation. In Conference Record of the Eighteenth Annual ACM Symposium on Principles of Programming Languages, Orlando, Florida, USA, January 21-23, 1991, David S. Wise (Ed.). ACM Press, 131–142. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Martin Hofmann. 1997. Extensional constructs in intensional type theory. Springer.Google ScholarGoogle Scholar
  21. Shan Shan Huang and Yannis Smaragdakis. 2008. Expressive and safe static reflection with MorphJ. In Proceedings of the ACM SIGPLAN 2008 Conference on Programming Language Design and Implementation, Tucson, AZ, USA, June 7-13, 2008. 79–89.Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Ming Kawaguchi, Patrick Maxim Rondon, and Ranjit Jhala. 2009. Type-based data structure verification. In Proceedings of the 2009 ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2009, Dublin, Ireland, June 15-21, 2009, Michael Hind and Amer Diwan (Eds.). ACM, 304–315. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Milod Kazerounian, Sankha Narayan Guria, Niki Vazou, Jeffrey S. Foster, and David Van Horn. 2019. Type-level computations for Ruby libraries. In Proceedings of the 40th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2019, Phoenix, AZ, USA, June 22-26, 2019. 966–979. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Oleg Kiselyov, Ralf Lämmel, and Keean Schupke. 2004. Strongly typed heterogeneous collections. In Proceedings of the ACM SIGPLAN Workshop on Haskell, Haskell 2004, Snowbird, UT, USA, September 22-22, 2004. 96–107. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Daan Leijen and Erik Meijer. 1999. Domain specific embedded compilers. In Proceedings of the Second Conference on DomainSpecific Languages (DSL ’99), Austin, Texas, USA, October 3-5, 1999. 109–122. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. J. Garrett Morris and James McKinna. 2019. Abstracting extensible data types: or, rows by any other name. PACMPL 3, POPL (2019), 12:1–12:28. https://dl.acm.org/citation.cfm?id=3290325Google ScholarGoogle Scholar
  27. Ulf Norell. 2007. Towards a practical programming language based on dependent type theory. Ph.D. Dissertation. Department of Computer Science and Engineering, Chalmers University of Technology.Google ScholarGoogle Scholar
  28. Tomas Petricek, Gustavo Guerra, and Don Syme. 2016. Types from data: making structured data first-class citizens in F#. In Proceedings of the 37th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2016, Santa Barbara, CA, USA, June 13-17, 2016, Chandra Krintz and Emery Berger (Eds.). ACM, 477–490. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Benjamin C. Pierce. 2002. Types and Programming Languages (1st ed.). The MIT Press.Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Benjamin C. Pierce. 2004. Advanced Topics in Types and Programming Languages. The MIT Press.Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Andrew Reynolds, Cesare Tinelli, Amit Goel, Sava Krstic, Morgan Deters, and Clark Barrett. 2013. Quantifier Instantiation Techniques for Finite Model Finding in SMT. In Automated Deduction - CADE-24 - 24th International Conference on Automated Deduction, Lake Placid, NY, USA, June 9-14, 2013. Proceedings. 377–391. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. John C. Reynolds. 1972. Definitional Interpreters for Higher-order Programming Languages. In Proceedings of the ACM Annual Conference - Volume 2 (ACM ’72). ACM, New York, NY, USA, 717–740. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Patrick Maxim Rondon, Ming Kawaguchi, and Ranjit Jhala. 2008. Liquid types. In Proceedings of the ACM SIGPLAN 2008 Conference on Programming Language Design and Implementation, Tucson, AZ, USA, June 7-13, 2008. 159–169.Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. John M. Rushby, Sam Owre, and Natarajan Shankar. 1998. Subtypes for Specifications: Predicate Subtyping in PVS. IEEE Trans. Software Eng. 24, 9 (1998), 709–720. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Yannis Smaragdakis, George Balatsouras, George Kastrinis, and Martin Bravenboer. 2015. More Sound Static Handling of Java Reflection. In Programming Languages and Systems - 13th Asian Symposium, APLAS 2015, Pohang, South Korea, November 30 - December 2, 2015, Proceedings. 485–503.Google ScholarGoogle Scholar
  36. Christopher A. Stone and Robert Harper. 2000. Deciding Type Equivalence with Singleton Kinds. In POPL 2000, Proceedings of the 27th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Boston, Massachusetts, USA, January 19-21, 2000. 214–227. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Christopher A. Stone and Robert Harper. 2006. Extensional equivalence and singleton types. ACM Trans. Comput. Log. 7, 4 (2006), 676–722. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Nikhil Swamy, Juan Chen, Cédric Fournet, Pierre-Yves Strub, Karthikeyan Bhargavan, and Jean Yang. 2011. Secure distributed programming with value-dependent types. In Proceeding of the 16th ACM SIGPLAN international conference on Functional Programming, ICFP 2011, Tokyo, Japan, September 19-21, 2011, Manuel M. T. Chakravarty, Zhenjiang Hu, and Olivier Danvy (Eds.). ACM, 266–278. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Niki Vazou, Patrick Maxim Rondon, and Ranjit Jhala. 2013. Abstract Refinement Types. In Programming Languages and Systems - 22nd European Symposium on Programming, ESOP 2013, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2013, Rome, Italy, March 16-24, 2013. Proceedings. 209–228. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Niki Vazou, Eric L. Seidel, Ranjit Jhala, Dimitrios Vytiniotis, and Simon L. Peyton Jones. 2014. Refinement types for Haskell. In Proceedings of the 19th ACM SIGPLAN international conference on Functional programming, Gothenburg, Sweden, September 1-3, 2014, Johan Jeuring and Manuel M. T. Chakravarty (Eds.). ACM, 269–282. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Panagiotis Vekris, Benjamin Cosman, and Ranjit Jhala. 2016. Refinement types for TypeScript. In Proceedings of the 37th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2016, Santa Barbara, CA, USA, June 13-17, 2016, Chandra Krintz and Emery Berger (Eds.). ACM, 310–325. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Philip Wadler and Stephen Blott. 1989. How to Make ad-hoc Polymorphism Less ad-hoc. In Conference Record of the Sixteenth Annual ACM Symposium on Principles of Programming Languages, Austin, Texas, USA, January 11-13, 1989. 60–76. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Stephanie Weirich, Justin Hsu, and Richard A. Eisenberg. 2013. System FC with explicit kind equality. In ACM SIGPLAN International Conference on Functional Programming, ICFP’13, Boston, MA, USA - September 25 - 27, 2013. 275–286. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Hongwei Xi. 2007. Dependent ML An approach to practical programming with dependent types. J. Funct. Program. 17, 2 (2007), 215–286. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Hongwei Xi and Frank Pfenning. 1998. Eliminating Array Bound Checking Through Dependent Types. In Proceedings of the ACM SIGPLAN ’98 Conference on Programming Language Design and Implementation (PLDI), Montreal, Canada, June 17-19, 1998, Jack W. Davidson, Keith D. Cooper, and A. Michael Berman (Eds.). ACM, 249–257. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Refinement kinds: type-safe programming with practical type-level computation

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        Full Access

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!