HYBRID PARTIAL-TOTAL TYPE THEORY 1. Introduction ... - CiteSeerX

0 downloads 0 Views 269KB Size Report
1. Introduction. In the seventies, Scott proposed a Logic for Computible ... space is a total one, and neither theory has general principles for typing xed points.
International Journal of Foundations of Computer Science

c World Scienti c Publishing Company

HYBRID PARTIAL-TOTAL TYPE THEORY SCOTT F. SMITH Department of Computer Science, The Johns Hopkins University Baltimore, Maryland 21218 USA [email protected] ABSTRACT In this paper a hybrid type theory HTT is de ned which combines the programming language notion of partial type with the logical notion of total type into a single theory. A new partial type constructor A is added to the type theory: objects in A may diverge, but if they converge, they must be members of A. A xed point typing rule is given to allow for typing of xed points. The underlying theory is based on ideas from Feferman's Class Theory and Martin Lof's Intuitionistic Type Theory. The extraction paradigm of constructive type theory is extended to allow direct extraction of arbitrary xed points. Important features of general programming logics such as LCF are preserved, including the typing of all partial functions, a partial ordering <  on computations, and a xed point induction principle. The resulting theory is thus intended as a general-purpose programming logic. Rules are presented and soundness of the theory established. Keywords: Constructive Type Theory, Logics of Programs, Least Fixed Points

1. Introduction

In the seventies, Scott proposed a Logic for Computible Functions.31 This theory axiomatized an ordering v on programs based on the domain-theoretic ordering, and included rules for typing xed points and a xed-point induction principle. Milner and others extended and implement Scott's ideas in the Edinburgh LCF system.16 Another line of research developing programming logics grew out of work by logicians. Martin-Lof's Intuitionistic Type Theory22;7 has at its core a functional programming language, and contains a rich collection of types for typing programs. Through the duality of types and propositions, proofs and programs are linked. Another related approach is Feferman's class theory,12;13;18;35| classes are are arbitrary collections of untyped computations, and a rich array of classes can be de ned. In both of these approaches, however, the standard notion of function space is a total one, and neither theory has general principles for typing xed points as members of partial function spaces, or for ordering terms via v, so many of the concepts expressible in LCF are missing. The goal of this paper is to extend type/class theory to make it possible to type and reason about partial functions as is possible in LCF. This is thus a work 1

of synthesis, and the resulting theory is a hybrid partial-total type theory. It is also a hybrid of class theory and type theory; in fact the foundations bear more resemblance to class theory. We refer to it as a \type theory" only in a generic sense. The purpose of HTT should not be confused with the purpose of Intuitionistic Type Theory. We aim solely for a practical foundation that is the core of a usable programming logic, not for a philosophical foundation. We start with constructive type theory and add a new collection of types, the partial types A. There are three main principles governing the use of partial types. If an object is in a partial type A and its computation always terminates, it is in the type A of total objects. It is possible to type xed points of functions on partial types, extending the programming power of type theory to arbitrary recursive programs. This xed point typing rule is the subject of much of the metamathematical investigation of this paper, for its justi cation is somewhat dicult. With this rule, arbitrary recursive programs can be typed and in addition can be extracted from proofs following the proof-as-programs interpretation of constructive type theory. There is also a Scott-style xed point induction principle. This work grew from Constable's desire to extend the Nuprl type theory7 to encompass ideas of LCF. Early results may be found in (Ref. 9,32,34). The Nuprl type theory is derived from Martin-Lof's ITT0.22 One important di erence is that Nuprl takes an untyped view of computation: untyped computations are sensible, in particular it is possible to compute expressions before they are typed. Feferman-style class theories12;13;18;35 take a similar approach: classes are collections of untyped computations. HTT borrows additional ideas from class theory: it includes a type E of all expressions and a type-free equality judgement a  = b and ordering a <  b, making pure untyped reasoning possible. The author's original interest in this mix of type theory and class theory is due to Howe.19 In ITT0 and Nuprl, on the other hand, types come with an equivalence on their members, a = a0 2 A. Thus, types are PER's. The notion of types as PER's does not t as well with partiality, for fundamental to partiality is the idea of an ordering < . Fixed-point induction for instance is an uninteresting principle without an atomic ordering < , nontrivial equivalences cannot be directly established by the principle. It thus might seem that the idea of a partial ordering relation (POR), a <  a0 2 A, would be the natural way to generalize a PER and develop hybrid type theory. However this idea proves problematic. We thus believe the approach taken here is the most natural setting for a hybrid type theory. 1.1. Outline of the paper

In section 2 HTT is de ned. Section 3 illustrates uses of the theory through examples. Lastly, semantics is given and soundness proved in section 4. We assume the reader has some familiarity with constructive type theory.7;22;27

2. The Theory

We now de ne HTT, a hybrid theory of partial and total typed computations. 2

HTT is not a full-featured type theory, but is the core of one; some important features not included are higher-order principles such as type universes, subtypes and recursive types, and classical reasoning principles. These are removed so we may focus on the core ideas in this presentation. 2.1. The terms

The theory has one sort, terms, which includes both types and computations. This means there is no rigid separation of types and terms; it is only in how the terms are used that the separation lies. We have an untyped language with numbers, pairing and projection, functions and application, and types.

De nition 1 (Terms) The terms of HTT are

(i) Variables x, y, z ,: : : , (ii) Data constructors 0; 1; 2; : ::, ha; bi, x:a, (iii) Type constructors E, N, A, x:AB , x:A!B , a in A, a <  b, a# (iv) Computation constructors pred(a), succ(a), if zero(a; b; c), 1(a), 2(a),

a(b)

where inductively a, b, c, A, B range over terms, and x ranges over variables.

We let a{t, A{T range over terms. Although terms and types are of the same sort, we informally use capital letters to denote what is intended to be a type and small letters, terms. Notions of bound and free variables, open and closed terms and substitution of b for x in a, a[b=x], are standard (we rename bound variables to avoid capture); -variants will be considered equal. We de ne a notion of contextual substitution: contexts are terms with holes ; a[]; A[] :: : range over contexts, and a[b] denotes the replacement of all holes occurring in a[] with b, possibly capturing free variables in b. The values (also called canonical terms) are outermost a data or type constructor, and are terms which cannot be computed further. 2.2. Judgements

All judgements are sequents, and take two forms: we may assert A to be a type, \A Type", and assert a to be a member of type A, \a 2 A". The rules are organized such that in the process of showing a to inhabit A, A will be shown to be a type. An assumption list ? is of the form x1:A1; x2:A2; : : :xn:An , and signi es reasoning takes place under assumptions x1 2 A1 , : : :, xn 2 An . Two forms of judgement may be made; the rst is ? ` A Type which asserts that under assumptions ?, A is a type. The second is ?`a2A which asserts under assumptions ?, a inhabits type A. Note it is an invariant that a 2 A always implies AType: for a type to be inhabited it rst must be well-formed. 2.3. Rules and proofs

3

Before presenting the rules, some conventions are given. In the hypothesis list x1:A1 ; x2:A2; : : :xn:An, xi may occur free in any Ai+j for positive j, and free variables in the conclusion are no more than the xi. -conversion is an unmentioned rule. The judgement 0 2 a <  b will be abbreviated a