Tabled Typeclass Resolution

Typeclasses provide an elegant and effective way of managing ad-hoc polymorphism in both programming languages and interactive proof assistants. However, the increasingly sophisticated uses of typeclasses within proof assistants has exposed two critical problems with existing typeclass resolution procedures: the diamond problem, which causes exponential running times in both theory and practice, and the cycle problem, which causes loops in the presence of cycles and so thwarts many desired uses of typeclasses. We present a new typeclass resolution procedure, called tabled typeclass resolution, that solves these problems. We have implemented our procedure for the upcoming version (v4) of the Lean Theorem Prover, and we confirm empirically that our implementation is exponentially faster than existing systems in the presence of diamonds. Our procedure is sufficiently lightweight that it could easily be implemented in other systems. We hope our new procedure facilitates even more sophisticated uses of typeclasses in both software development and interactive theorem proving.

[1]  Enrico Tassi,et al.  Canonical Structures for the Working Coq User , 2013, ITP.

[2]  Gopal Gupta,et al.  A Simple Scheme for Implementing Tabled Logic Programming Systems Based on Dynamic Reordering of Alternatives , 2001, ICLP.

[3]  Christopher Strachey,et al.  Fundamental Concepts in Programming Languages , 2000, High. Order Symb. Comput..

[4]  Bas Spitters,et al.  Type classes for mathematics in type theory† , 2011, Mathematical Structures in Computer Science.

[5]  Bas Spitters,et al.  Type classes for efficient exact real arithmetic in Coq , 2011, Log. Methods Comput. Sci..

[6]  Johannes Hölzl,et al.  Type Classes and Filters for Mathematical Analysis in Isabelle/HOL , 2013, ITP.

[7]  Simon Peyton Jones,et al.  Type classes: an exploration of the design space , 1997 .

[8]  Li-Yan Yuan,et al.  Linear tabulated resolution based on Prolog control strategy , 2000, Theory and Practice of Logic Programming.

[9]  Konstantinos Sagonas,et al.  An abstract machine for tabled execution of fixed-order stratified logic programs , 1998, TOPL.

[10]  K. A. Ross,et al.  Tabled Evaluation with Delaying for General Logic Programs , 1996 .

[11]  Neng-Fa Zhou,et al.  Linear tabling strategies and optimizations , 2007, Theory and Practice of Logic Programming.

[12]  Simon L. Peyton Jones,et al.  Regular, shape-polymorphic, parallel arrays in Haskell , 2010, ICFP '10.

[13]  Éric Villemonte de la Clergerie,et al.  LPDA: Another look at Tabulation in Logic Programming , 1994, ICLP.

[14]  David Scott Warren,et al.  XSB: Extending Prolog with Tabled Logic Programming , 2010, Theory and Practice of Logic Programming.

[15]  Dominic Duggan,et al.  Type-checking multi-parameter type classes , 2002, J. Funct. Program..

[16]  Kenneth A. Ross,et al.  The well-founded semantics for general logic programs , 1991, JACM.

[17]  Ralf Lämmel,et al.  Software extension and integration with type classes , 2006, GPCE '06.

[18]  Peng Li,et al.  Encoding information flow in Haskell , 2006, 19th IEEE Computer Security Foundations Workshop (CSFW'06).

[19]  I. V. Ramakrishnan,et al.  Term Indexing , 1995, Lecture Notes in Computer Science.

[20]  J. A. Robinson,et al.  A Machine-Oriented Logic Based on the Resolution Principle , 1965, JACM.

[21]  Simon L. Peyton Jones,et al.  Type Classes in Haskell , 1994, ESOP.

[22]  Martin Odersky,et al.  An Overview of the Scala Programming Language , 2004 .

[23]  Bart Demoen,et al.  CHAT: the copy-hybrid approach to tabling , 2000, Future Gener. Comput. Syst..

[24]  Peyton Jones,et al.  Haskell 98 language and libraries : the revised report , 2003 .

[25]  Cesare Tinelli,et al.  Satisfiability Modulo Theories , 2021, Handbook of Satisfiability.

[26]  Robert A. Kowalski,et al.  Predicate Logic as Programming Language , 1974, IFIP Congress.

[27]  Simon L. Peyton Jones,et al.  Scrap your boilerplate with class: extensible generic functions , 2005, ICFP '05.

[28]  Simon L. Peyton Jones,et al.  Derivable Type Classes , 2001, Haskell.

[29]  Koen Claessen,et al.  QuickCheck: a lightweight tool for random testing of Haskell programs , 2011, SIGP.

[30]  Mark P. Jones,et al.  Type Classes with Functional Dependencies , 2000, ESOP.

[31]  Paul Hudak,et al.  Parametric type classes , 1992, LFP '92.

[32]  Haim Kaplan Persistent Data Structures , 2004 .

[33]  Wolfram Kahl,et al.  Named Instances for Haskell Type Classes , 2001 .

[34]  Ulf Norell,et al.  A Brief Overview of Agda - A Functional Language with Dependent Types , 2009, TPHOLs.

[35]  Bart Demoen,et al.  CAT: The Copying Approach to Tabling , 1999, J. Funct. Log. Program..

[36]  Matthieu Sozeau,et al.  First-Class Type Classes , 2008, TPHOLs.

[37]  William A. Howard,et al.  The formulae-as-types notion of construction , 1969 .

[38]  Hisao Tamaki,et al.  OLD Resolution with Tabulation , 1986, ICLP.

[39]  Jeremy Avigad,et al.  The Lean Theorem Prover (System Description) , 2015, CADE.

[40]  Laurent Vieille,et al.  Recursive Query Processing: The Power of Logic , 1989, Theor. Comput. Sci..

[41]  Lawrence C. Paulson Organizing Numerical Theories Using Axiomatic Type Classes , 2004, Journal of Automated Reasoning.

[42]  Bas Spitters,et al.  Developing the Algebraic Hierarchy with Type Classes in Coq , 2010, ITP.

[43]  H B Curry,et al.  Functionality in Combinatory Logic. , 1934, Proceedings of the National Academy of Sciences of the United States of America.

[44]  The mathlib Community The lean mathematical library , 2020, CPP.

[45]  Riccardo Pucella,et al.  Haskell session types with (almost) no class , 2008, Haskell '08.

[46]  Gill Andy Debugging Haskell by Observing Intermediate Data Structures , 2001 .

[47]  Philip Wadler,et al.  How to make ad-hoc polymorphism less ad hoc , 1989, POPL '89.

[48]  Conor McBride Faking it: Simulating dependent types in Haskell , 2002, J. Funct. Program..

[49]  Mark P. Jones Computing with Lattices: An Application of Type Classes , 1992, J. Funct. Program..

[50]  Ralf Lämmel,et al.  Strongly typed heterogeneous collections , 2004, Haskell '04.

[51]  Tobias Nipkow,et al.  A Proof Assistant for Higher-Order Logic , 2002 .

[52]  Konstantin Läufer Type Classes with Existential Types , 1996, J. Funct. Program..