Overlapping and order-independent patterns in type theory

Pattern matching is a mechanism to write programs by case distinction and recursion in functional programming languages. In a language based on type theory with dependent types, pattern matching allows us to write not just programs, but also proofs. In order to check whether these proofs are correct, certain restrictions are put on definitions by pattern matching [Coq92]. These restrictions allow us to write definitions by pattern matching in function of the theoretically simpler eliminators [GMM06]. This ensures that definitions by pattern matching are correct, but also limits the expressiveness of the language. One of these restrictions is that patterns must form a covering, i.e. are created by repeatedly splitting on a pattern variable. Some dependently typed languages with pattern matching like Agda [Nor07] allow more general pattern sets, but translate them to a covering internally. In this translation, overlapping patterns are treated on a first-match basis. However, the result of the translation depends on the order of the clauses, even when the patterns do not overlap. This can lead to unexpected results for a user who doesn’t know the internal workings of this translation. This is a sign of bad abstraction. This thesis is concerned with making dependent pattern matching more intuitive for the user. We do this by interpreting each clause directly as a definitional equality, even when the patterns overlap. In particular, our interpretation doesn’t depend on the order of the patterns. This allows us to give definitions with overlapping patterns, which can be used to extend a function with extra evaluation rules. To interpret pattern matching in this way, we lift the restriction that the patterns must form a covering. Instead of this restriction, we give a more general criterion for completeness. In order to ensure correctness in the presence of overlapping patterns, we also give a criterion for confluence. By making all clauses hold as definitional equalities, definitions by pattern matching feel more like mathematical definitions, rather than program instructions. However, we lose the ability to translate pattern matching to the use of eliminators, making it more complex to understand theoretically. In order to reduce this loss, we will prove a theoretical result that gives an equivalence with non-overlapping definitions.

[1]  Matthieu Sozeau Equations: A Dependent Pattern-Matching Compiler , 2010, ITP.

[2]  P. Medawar A view from the left , 1984, Nature.

[3]  Albert Gräf,et al.  Left-to-Right Tree Pattern Matching , 1991, RTA.

[4]  Conor McBride,et al.  Eliminating Dependent Pattern Matching , 2006, Essays Dedicated to Joseph A. Goguen.

[5]  Hongwei Xi,et al.  Dependently Typed Pattern Matching , 2003 .

[6]  Neil D. Jones,et al.  The size-change principle for program termination , 2001, POPL '01.

[7]  Georges Gonthier,et al.  Engineering mathematics: the odd order theorem proof , 2013, POPL.

[8]  Zhaohui Luo,et al.  Computation and reasoning - a type theory for computer science , 1994, International series of monographs on computer science.

[9]  LEO BACHMAIR,et al.  Termination Orderings for Associative-Commutative Rewriting Systems , 1985, J. Symb. Comput..

[10]  Bengt Nordström,et al.  Programming in Martin-Löf's Type Theory , 1990 .

[11]  Healfdene Goguen A typed operational semantics for type theory , 1994 .

[12]  Steven Awodey,et al.  Homotopy Type Theory , 2015, ICLA.

[13]  Thorsten Altenkirch,et al.  Under Consideration for Publication in J. Functional Programming a Predicative Analysis of Structural Recursion , 2022 .

[14]  Simon Thompson,et al.  Type theory and functional programming , 1991, International computer science series.

[15]  U. Norell,et al.  Towards a practical programming language based on dependent type theory , 2007 .

[16]  Conor McBride,et al.  A Few Constructions on Constructors , 2004, TYPES.

[17]  Conor McBride,et al.  Dependently typed functional programs and their proofs , 2000 .

[18]  Alexander Simpson Workshop on Types for Proofs and Programs , 1993 .