An Introduction to Generalized Type Systems
Total Page:16
File Type:pdf, Size:1020Kb
See discussions, stats, and author profiles for this publication at: https://www.researchgate.net/publication/216300104 An Introduction to Generalized Type Systems Article in Journal of Functional Programming · April 1991 DOI: 10.1017/S0956796800020025 CITATIONS READS 189 637 1 author: Henk (Hendrik) Pieter Barendregt Radboud University 184 PUBLICATIONS 6,444 CITATIONS SEE PROFILE Some of the authors of this publication are also working on these related projects: Logic and Computability View project Research on Generalized Typed Lambda Calculi 1982--1987 View project All content following this page was uploaded by Henk (Hendrik) Pieter Barendregt on 10 December 2016. The user has requested enhancement of the downloaded file. PDF hosted at the Radboud Repository of the Radboud University Nijmegen The following full text is a publisher's version. For additional information about this publication click this link. http://hdl.handle.net/2066/17240 Please be advised that this information was generated on 2016-12-10 and may be subject to change. Journal o f Functional Programming 1 (2): 125-154, April 1991 Introduction to generalized type systems HENK BARENDREGT Catholic University Nijmegen, The Netherlands Abstract Programming languages often come with type systems. Some of these are simple, others are sophisticated. As a stylistic representation of types in programming languages several versions of typed lambda calculus are studied. During the last 20 years many of these systems have appeared, so there is some need of classification. Working towards a taxonomy, Barendregt (1991) gives a fine-structure of the theory of constructions (Coquand and Huet 1988) in the form of a canonical cube of eight type systems ordered by inclusion. Berardi (1988) and Terlouw (1988) have independently generalized the method of constructing systems in the A.-cube. Moreover, Berardi (1988, 1990) showed that the generalized type systems are flexible enough to describe many logical systems. In that way the well-known propositions-as-types interpretation obtains a nice canonical form. Capsule review This paper presents a possible classification for the simplest class of typed systems: only ß-reduction is considered, and the only type constructors are n and First, various Automath-like typed systems are analysed, with a brief presentation of their main properties (subject reduction, unicity of types and strong normalization). This analysis suggests rather naturally the notion of generalized type systems which provide a neat notation for describing the ‘propositions-as-types’ idea. The relevance of this notation is shown by the fact that it allows us to sharply express new problems, as the relative completeness of various interpretations, or to state concisely and precisely type-theoretic results (for instance, the exact formalism in which Girard’s paradox is derived). 1 Introduction In several programming languages types are assigned to expressions (occurring in a program) in a way that may be compared to dimensions assigned to entities in physics. These dimensions provide a partial correctness check 2 V o lt+ 3 Ampère is definitely wrong; the equation _ E = me is consistent at least from the point of view of dimensions, since both sides are expressed in kg.m 2.sec-2. The analogy between types and dimensions is not perfect. A physical entity always has a unique dimension. Expressions in programming may have more than one type. 5 F P R 1 126 Henk Barendregt This is the case when implicit (or Curry style) typing is allowed : the expression Âx.x denoting the identity function obtains all types A for A an arbitrary type. We write ,, . ,. .. (ax.x):(A^ A) which should be pronounced as ‘lambda x dot x in A arrow A ’, and has as its intended meaning that ‘for each (element) a in A the application (Xx.x)a is also in A ’ (which is intuitively true, since (Àx.x) a = a). Examples of programming languages with this style of typing are M L (M ilner 1984) and M iranda (Turner 1985). There is also another paradigm, the explicit or Church style of typing, in which each correct expression has exactly one type. Now there are several versions of the identity function IA = Ax: A .x and this one has as its unique type A -*■ A. Examples of languages with explicit typing are LCF (Gordon et al. 1979) and TALE (Barendregt and van Leeuwen 1985). During the last 20 years many systems have appeared for typing lambda calculi, both in the style of Curry and that of Church (see Barendregt (1991) for a survey). In this paper we give some flavour of a class of systems à la Church using the following methodology : Only the simplest versions of a system are considered ; that is, only with ß-reduction, but not with, for example r\-reduction \ only with types built up using -> and n, not using, for example, x or I. As will be seen, the systems become complicated anyhow. (For a discussion on types in programming languages see Cardelli and Wegner (1985); Reynolds (1985) and Barendregt and Hemerik (1990).) 2 A finestructure of the theory of constructions Recently a quite powerful typed lambda calculus has been introduced by Coquand and Huet (1988). The system is called ‘the theory of constructions’, and is denoted here by À.C. By analysing the way in which terms and types are built up, a fine structure of this system is given, consisting of eight systems of typed lambda calculi forming under inclusion a natural cube with oriented edges (see fig. 1). Each edge -> represents the inclusion relation £ . This cube is referred to as the X-cube. Most of the systems in the >.-cube are known, albeit in a somewhat different form. The system X ^ is the simply typed lambda calculus (Church, 1940). The system X2 is the polymorphic or second order typed lambda calculus, and is a subsystem of the system F introduced by Girard (1972). It has been introduced independently by Introduction to generalized type systems 127 Reynolds (1974). The system Xw is essentially the system Fco of Girard (1972). System XP corresponds reasonably to one of the systems in the family of a u t o m a t h languages (see de Bruijn, 1980): System A.P also appears under the name LF in Harper et al. (1987), System XP2 is studied by Longo and Moggi (1988) under the same name. System A.C is one of the versions of the theory of constructions introduced by Coquand and Huet (1988), and system A.co is related to the p o l y r e c system studied by Renardel de Lavalette (1985). System APco seems not to have been studied before. (For À.® and ÄPm read ‘weak tao’ and ‘weak XPco’, respectively.) Before defining the X-cube, it is useful to describe informally some ideas which play a role in the various systems. The first informal idea is the construction of function space types. If A and B are types, then A -> B is the type of functions from A to B. So, if F : (A -> B) and x : A, then (Fx):B. The second idea is that of dependency. Types and terms are mutually dependent; there are • terms depending on term ; • terms depending on types ; • types depending on terms; • types depending on types. Some explanation is necessary here. Terms depending on terms are extremely common : , FM is a term that depends on the term M. A term depending on a type is the identity on ^ IA = Xx : A . x. A type depending on a term is, for example, An- B (with n a natural number) defined by A ° ^ B = B; An+1 -> B = A ^(A n^B ). And a type depending on a type is, for example, A-*A for A a given type. Once there are types depending on terms one may introduce cartesian products. Suppose that for each a ; A a type B., is given, and that there is an element ba : Ba, Then we may want to form the function Xa : A . ba that should have as type the cartesian product rTa: A . Ba of the Bas. Once these product types are allowed, the function space type of A and B can be written as (A ^B ) = ITa:A.B(= BA, informally), 5-2 128 Henk Barendregt where a is a variable not occurring in B. This is similar to the fact that a product of equal factors is a power n n b i becomes bn i-1 provided that bj = b for 1 ^ i ^ n. So by using products, the type constructor -> can be eliminated. The next idea has to do with the formation of types. For some simple systems the types are - so to say - given in the metalanguage. For example, if one has informally constructed a type A, then one can formally derive I— (A.a : A . a) : (A ->• A). Since in the /.-cube terms and types are mutually dependent, one moves the formation of types from the metalevel to the formal system itself - the idea comes from the a u t o m a t h languages of de Bruijn (1970). To do this a constant * is introduced that is the sort of all types; then ‘A: *’ is a statement expressing ‘A is a type’. A sentence in the meta language like ‘if A is a type, then so is A -> A ’ now becomes a formal type derivation A : * (— (A -> A) : *. Here A stands for a variable, and since it is in *, one can say that A is a type variable. For each of the four dependencies one may want to introduce function abstraction (X,m : A . Fm) : (A ^ B) ; (Xa : *. I„) : (ITa : *. (a -> a)) ; (A.n:W.An^B ):f\J^*; (tax: *.