
The Structure of Nuprls Typ e Theory Rob ert L Constable Cornell University Ithaca NY Intro duction Context After my lectures on this topic were delivered in July at Marktob erdorf my col leagues and I made available much more related material b oth at the Nuprl home page on the World Wide Web the Web wwwcscornelleduInfoNuPrlnuprlhtml and in publications some so on to app ear At the Web site the thesis of Jackson and the article byForester are esp ecially relevanttomy lecture Also the Nuprl b o ok is nowavailable on line at the Web site as is the Nuprl reference manual and a host of Nuprl libraries As a result of the ready access to this material and b ecause the material in the Cor nell Technical Rep ort series is part of an expanding digital library whose longevity seems guaranteed I designed this article to concentrate on the material not available elsewhere eg a discussion of the Core Theory and its relation to Nuprl A naive accountofCoreTyp e Theory is esp ecially simple and I think it provides a bridge to understanding the more daunting axiomatization of the Nuprl typ e theory which is used in all of the online libraries This article presents the Core Theory and relates it to a corresp onding part of Nuprl Comparisons are made to set theory as a way to motivate the concepts Typ es and Sets The informal language of mathematics uses typ es and sets but when mathematicians want to b e rigorous ab out a concept they tend to rely on the year old tradition of reducing it to concepts in pure set theory In this article we will nd the rigorous concepts in type theoryFor p edagogical reasons we will often mention the set theory version of a concept as well The idea of a typ e is built up inductively as is the Zermelo hierarchical concept of set We start with primitive types and typeconstructors The Core Theory needed for Nuprl involves only six typ e constructors pro duct disjoint union function space inductive typ e set typ eand quotient typ eWe need some primitive typ es as well void unit Typ eandPropIhavechosen to add coinductivetyp es as well although they are not in Nuprl TheCoreTheory PrimitiveTyp es void is a typ e with no elements unit is a typ e with one element denoted There will b e other primitivetyp es intro duced later Notice in set theory we usually have only one primitive set some innite set usually Sometimes the emptyset is primitiveaswell although it is denable by separation from Comp ound Typ es We build new typ es using typeconstructors These tell us how to construct various kinds of ob jects In pure set theory there is only one kind sets The typ e constructors wecho ose are motivated b oth by mathematical and compu tational considerations So we will see a tight relationship to the notion of type in programming languages The notes by CAR Hoare Notes on Data Structuring make the p ointwell Cartesian Pro ducts If A and B are typ es then so is their pro duct written A B There will b e many formation rules of this form so we adopt a simple convention for stating them We write A is a Type B is a Type A B is a Type The elements of a pro duct are pairs ha bi Sp ecically if a b elongs to A and b b elongs to B then ha bi b elongs to A B We abbreviate this by writing aA bB ha bi A B In programming languages these typ es are generalized to nary pro ducts say A A A They are the basis for dening records n Wesay that ha bi hc di in A B i a c in A and b d in B In set theory equalityisuniformandbuiltinbutintyp e theory we dene equality with each constructor either builtin as in Nurpl or by denition as in this core theory There is essentially only one way to decomp ose pairs Wesay things like take the rst elements of the pair P symb olically wemightsay rstP orofP We can also take the second elementof P secondP orofP Function Space We use the words function space as well as function typ e for historical reasons If A and B are typ es then A B is the typ e of computable functions from A to B These are given by rules which are dened for each a in A and which pro duce a unique valueWe summarize by A is a Type B is a Type A B is a Type The function notation we use informally comes from mathematics texts eg Bour f bakis AlgebraWe write expressions like x b or x b the latter gives a name to the function For example x x is the squaring function on numb ers If b computes to an elementof B when x has value a in A for each athenwesay x b A B We will also use lambda notation xbfor x b The informal rule for typing a function xbistosay that xb A B provided that when x is of typ e A b is of typ e B We can express these typing judgments in the form x A b B The phrase x A declares x to b e of typ e AThetyping rule is then x A b B xb A B If f g are functions we dene their equalityas f g i f xg x for all x in A If f is a function from A to B and aAwe write f a for the value of the function Disjoint Unions also called Discriminated Unions Forming the union of two sets say x y is a basic op eration in set theory It is basic in typ e theory as well but for computational purp oses wewant to discriminate based on whichtyp e an element is in To accomplish this we put tags on the elements to keep them disjoint Here weuse inl and inr as the tags A is a Type B is a Type A B is a Type The memb ership rules are bB a A inl a A B inr b A B Wesay that inl ainl a i a a and likewise for inr b We can now use a case statement to detect the tags and use expressions like if x inl z then some expression in z if x inr z then some expression in z in dening other ob jects The test for inl z or inr z is computable There is an op eration called decide that discriminates on the typ e tags The typing rule and syntax for it are given in terms of a typing judgment of the form E t T where is a list of declarations of the form x A x A called a typing environment The n n A are typ es and x are variables declared to b e of typ e A The rule is i i i E d A B E u A t T E v B t T E decided ut vt T Subtyping Intuitively A is a subtyp e of B i every elementof A is also an elementof B we write this relation as A B Clearly A for any A Notice that A is not a subtyp e of A B since the elements of A in A B have the form inl a Wehave these prop erties however A A B B A B A B A B A B A B A B For A B we also require that a a in A implies a a in B InductiveTyp es Dening typ es in terms of themselves is quite common in programming often p ointers are used in the denition in Pascal and C for example but in languages like ML direct recursive denitions are p ossible For example a list of numb ers L can b e intro duced by a denition like dene type L N N L In due course we will give conditions telling when such denitions are sensible but for now let us understand howelements of sucha typ e are created Basically a typ e of this kind will b e sensible just when we understand exactly what elements b elong to the typ e Clearly elements like inl inl are elements Given them it is clear that inr h inl iinrhinli and generally inr hn inl mi are elements and given these we can also build inr hk inr hn inl mii and so forth In general we can build elements in anyofthetyp es N N Y N N N N Y N N N N N N Y The key question ab out this pro cess is whether wewanttoallow anything else in the typ e L Our decision is nowewant only elements obtained by this nite pro cess In set theorywe can understand similar inductive denitions saya set L suchthat L N N L as least xed p oints of monotonic op erators F Set Set In general given suchanoperatorF wesay that the set inductively dened by F is the least F cl osed set call it I F We dene it as I F fY jF Y Y g We use set theory as a guide to justify recursivetyp e denitions For the sake of dening monotonicitywe use the subtyping relation S T This holds just when the elements of S are also elements of T and the equalityon S and T is the same For example if S T then N N S N N T Def Given a typ e expression F Type Type suchthatifT T then F T F T then write X F X asthetype inductively denedbyF To construct elements of X F X we basically just unwind the denition That is if tFX F X then t XFX Wesay that t t in X F X i t t in F X F X The p ower of recursivetyp es comes from the fact that we can dene total computable functions over them very elegantlyandwe can prove prop erties of elements recursively Recursive denitions are given by this term inda f zb called a recursor or recursiveform It ob eys the computation rule inda f zb evaluates in one step to baz y indy f zbf Note in this rule we use the notation bsx ty to mean that we substitute s for x and t for y in b typing The waywe gure out a typ e for this form is given by a simple rule Wesay that inda f zb is in typ e B provided that a X F X and if when Y is a Typ e and Y X F X and z b elongs to F Y and f maps Y to B then b is of typ e B induction The principle of inductive reasoning over X F X is just this induction Let R X F X and assume that Y is a subtyp e of R and that for all x in Y P x is true This is the induction hyp othesis Then if we can show z F Y P z we can conclude x RP x With this principle and the form indwe can write programs over recursivetyp es and prove prop erties of them The approach presented here is quite abstract so it applies to a large variety of sp ecic programming languages It also stands on its own as a mathematical theory of typ es typing rules We will write these informal rules
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages33 Page
-
File Size-