Typed Nominal Rewriting

Elliot Fairweather, Maribel Fernández
2018 ACM Transactions on Computational Logic  
Nominal terms extend first-order terms with nominal features and as such constitute a meta-language for reasoning about the named variables of an object language in the presence of meta-level variables. This paper introduces a number of type systems for nominal terms of increasing sophistication and demonstrates their application in the areas of rewriting and equational reasoning. Two simple type systems inspired by Church's simply typed lambda calculus are presented where only well-typed terms
more » ... are considered to exist, over which α-equivalence is then axiomatised. The first requires atoms to be strictly annotated whilst the second explores the consequences of a more relaxed de Bruijn style approach in the presence of atom-capturing substitution. A final type system of richer ML-like polymorphic types is then given in the style of Curry, in which elements of the term language are deemed typeable or not only subsequent to the definition of alpha-equivalence. Principal types are shown to exist and an inference algorithm given to compute them. This system is then used to define two presentations of typed nominal rewriting, one more expressive and one more efficient, the latter also giving rise to a notion of typed nominal equational reasoning. ELLIOT FAIRWEATHER and MARIBEL FERNÁNDEZ be abstracted, and meta-level variables are represented by moderated variables (a variable with an atom-permutation suspended over it). The suspended permutation acts when the variable is instantiated by a substitution, which is first-order in nature (that is, not capture-avoiding). For example, the nominal terms lam [a] X and app (lam [a] X , X ), where the permutation suspended over X is the identity and has been omitted, represent the lambda term 'contexts' λx .M (or λx .[−]) and (λx .M ) M, respectively. Unification and matching of nominal terms has been shown to be decidable [69] and linear time algorithms for matching have been developed [9] . As a result, both logic-based and functional programming languages that integrate nominal techniques have already been implemented [14, 16, 61, 66] . Type systems are another important area within the study of formal languages. First studied as a means to overcome the paradoxes of set theory [64], they were later incorporated into the lambda calculus by Church [1940]. In addition to extensive subsequent research from this theoretical standpoint, type systems were later applied to the area of programming languages; they are intrinsically linked to the specification and verification of program properties through constructivist logics and the Curry-Howard isomorphism. Type systems provide a tractable, syntactic method to define and check specifications of programs, allowing certain of their behaviours to be reasoned about even before execution [56, 57] . This is an area of increasing importance; critical domain software, such as that used in the fields of medicine, telecommunications, transport and defence, often demands mathematical certainty of program correctness. Thus there is a corresponding demand for the development of type systems of increasing power and sophistication for use in certified programming environments. However, thus far, formal research in type systems for nominal abstract syntax, nominal terms and nominal rewriting has been limited (see Related Work below). This paper contributes several type systems for nominal terms and systems of nominal reasoning, in which object-level variables (atoms) may inhabit any type and users may provide arbitrary type declarations for term-formers. Both Churchand Curry-style approaches are considered, the latter in the presence of polymorphic types. Churchstyle systems are considered in Section 3. In such systems, terms are well-typed by definition and thus the typing of terms precedes the definition of relations on terms such as freshness and alphaequivalence. The first system which is briefly considered is in strict Church-style [18] whereby atoms are annotated with their types. The second explores de Bruijn's presentation of Church's system [8] . Whilst notationally less verbose than the fully annotated system, this approach, in which types given to abstracted atoms may be added to the typing environment, is more complex due to the possibility of typing conflicts arising from atom-capture when applying variable substitutions to non-linear terms. For example, in the untyped nominal term app (lam [a] X , X ), the first occurrence of the variable X is under the scope of an abstraction for the atom a, but the second occurrence is not. Thus, a substitution [X → a] applied to this term introduces both an abstracted and a non-abstracted occurrence of a. To ensure safe interaction between capturing substitutions and atom-typing contexts, the type systems designed in this paper check the type compatibility of the abstraction contexts for each occurrence of a moderated variable, taking suspended permutations into account. This is not needed in the strict Church system where each atom has a fixed type. Two possible directions for further study then arise; one could consider polymorphic or other more powerful types in a Church setting (such as the dependent types presented in [31]), or alternatively, one could define a simple Curry-style system [8, 26] , using meta-level type variables. Here, it was decided to take a step in both directions simultaneously, and a Curry-style, ML-like polymorphic type system is presented in Section 4. Term-formers may now be assigned type schemes and only the types of unabstracted atoms are pre-determined. Elements of the term language are deemed typeable or not only after the definition of alpha-equivalence. As for the de Bruijn system, it is necessary to account for the interaction of capturing substitution but here the Curry-style typing allows freshness constraints to be taken into consideration and the effect of permutations suspended upon variables to be considered only in the case where non-linear substitutions may occur. Alternative designs are possible, for example by requiring a fixed type for all the occurrences of an atom, as in the strict Church system. The chosen approach, however, permits a more flexible use of atoms, where different occurrences of an atom may have different types, provided a compatibility condition is satisfied. This condition ensures that a well-typed capturing substitution acting on a well-typed term produces a well-typed term. Terms are also shown to have a principal type and an inference algorithm to compute them is given. This polymorphic system is then studied in the context of both rewriting and equational theories in Section 5. Two formulations of typed nominal rewriting are presented, one more expressive, using equivariant matching over sets of uniform rules and one more efficient, using nominal matching with closed rules, which nevertheless encompasses most scenarios of interest. In both cases, the rewriting relation preserves types. A formulation of typed nominal equational reasoning based on the latter of these approaches is then derived. A wide selection of examples is given. ELLIOT FAIRWEATHER and MARIBEL FERNÁNDEZ of terms, as must the atoms of abstractions, and the result type of function applications is restricted to constructed term types. Whilst implemented, the type system is not formalised. Urban [2008] describes how the nominal package for Isabelle [72], a higher-order logic theorem proving environment, is typed. Within the Isabelle type system, atoms are given a single type. Permutations are typed simply as lists of pairs of that type. The action of a permutation is an overloaded operator allowing a definition to be given for each built-in 'permutation type'. Such a type is an instance of a type class that guarantees that certain properties of elements of the type are maintained under the permutation operation. However, in later work [45] , it is explained that atoms may be given arbitrary sorts ('multi-sorted concrete atoms') at the term level which can be enforced by the Isabelle type-checker by use of sub-typing. Shinwell [2005] describes the implementation of the language Fresh OCaml, (successor to the FreshML of [67], where atom-abstractions are implemented by dynamically generating fresh names), an extension of OCaml for meta-programming with binding and data structures. Expressions for generating fresh atoms, atom abstraction, swapping atoms and freshness conditions are added to the language. Atoms are given a name type but one that is polymorphic over all types. Abstractions need not necessarily abstract atoms and the abstracted expression need not be of a 'name' type. However this language is not fully formalised. Instead a smaller subset, Mini-FreshML, is studied in which the type system is extended with a single type for names and an abstraction type, of the type of names over types. Pottier [2007] later provided a mechanism for static name control in FreshML. Type systems for first-order rewriting are studied in [70, 71] . The first-order rewriting language Maude [19, 20] has a rich type system, providing sorts, sub-sorts, operator overloading and more. Type systems for formalisms of higher-order rewriting are less well developed. Higher-order Rewrite Systems [51], use a typed lambda calculus as a meta-language together with restrictions on patterns to ensure the decidability of higher-order unification, however, rewrite rules may only be typed with base types. Richer types for function symbols in this system are considered in [47] . In 'plain' higher-order rewrite systems, the lambda calculus is extended with first-order rewriting together with first-order matching. A mixed approach of standard and plain higher-order rewriting is proposed in [46], using a system of polymorphic types. Overview. The paper is organised as follows: Section 2 gives an overview of the nominal approach to syntax with binding. Section 3 defines two approaches to Church-style simple types for nominal terms and Section 4 a more sophisticated polymorphic type system in the style of Curry. This system is then used in Section 5 to develop typed nominal equational systems. Section 6 concludes and gives directions for future work. BACKGROUND Nominal terms [69] are a meta-language designed to specify and reason about formal languages that use names and binding, such as logics or programming languages. Equational reasoning for nominal terms has been extensively studied [22, 23, 33, 34, 39] . Atoms, Permutations and Terms Atoms represent names or named variables at the object-language level. Let there be a countably infinite set of atoms, A, and following the permutative convention of [38], let a, b, c, . . ., range over distinct atoms in A. A permutation, denoted π , is a bijective function on A, such that {a | π (a) a, a ∈ A} is a finite set. Call this set the support of π and write it as supp(π ). Permutations are represented as a list of transpositions or 'swappings' of atoms, where id represents the identity permutation, that is,
doi:10.1145/3161558 fatcat:ghyr5ru2sjhi3ib4wdtsny23uq