Rank-2 intersection for recursive definitions

Size: px
Start display at page:

Download "Rank-2 intersection for recursive definitions"

Transcription

1 Fundamenta Informaticae XXI (2001) IOS Press Rank-2 intersection for recursive definitions Ferruccio Damiani Dipartimento di Informatica Università di Torino Corso Svizzera 185, I Torino, Italy Abstract. Let be an intersection type system. We say that a term is -simple (or just simple when the system is clear from the context) if system can prove that it has a simple type. In this paper we propose new typing rules and algorithms that are able to type (with rank-2 intersection types) recursive definitions that are not simple. Typing rules for assigning intersection types to (nonsimple) recursive definitions have been already proposed in the literature. However, at the best of our knowledge, previous algorithms for typing recursive definitions in the presence of intersection types allow only simple recursive definitions to be typed. The rules and algorithms proposed in this paper are also able to type interesting examples of polymorphic recursion (i.e., recursive definitions rec {x = e} where different occurrences of x in e are used with different types). Moreover, the underlying techniques do not depend on particulars of rank-2 intersection, so they can be applied to other type systems. Keywords: Type inference, Principal typings, Polymorphic recursion 1. Introduction The Hindley-Milner type system (a.k.a. the ML type system) [8], which is the core of the type systems of modern functional programming languages (like SML, OCaml, and Haskell), has several limitations that prevent safe programs from being typed. In particular, it does not allow different types to be assigned to different occurrences of a formal parameter in the body of a function. To overcome these limitations, Address for correspondence: damiani Partially supported by IST TYPES and MIUR cofin 04 EOS projects. The funding bodies are not responsible for any use that might be made of the results presented here.

2 1002 F. Damiani / Rank-2 intersection for recursive definitions various extensions of the ML system based on universal types [11, 23], intersection types [6, 3], recursive types, and combinations of them, have been proposed in the literature. The system of rank-2 intersection types [20, 1, 25, 17, 9] is particularly interesting since it is able to type all ML programs, has the principal pair property (a.k.a. principal typing property [17, 24]), decidable type inference, and the complexity of type inference is of the same order as in ML. Intersection types are obtained from simple types [15] by adding the intersection type constructor. A term has type u 1 u 2 (u 1 intersection u 2 ) if it has both type u 1 and type u 2. For example, the identity function λx.x has both type int int and bool bool, so it has type (int int) (bool bool). The rank of an intersection type t is the maximum depth of the occurrences of the type constructor in t, counting nesting in the left argument of the type constructor (a type without occurrences of is a rank-0 type and a type without occurrences of in the left argument of is a rank-1 type). Therefore, for instance, ((int int) (bool bool)) int int is a rank-2 intersection type (as usual, the arrow type constructor is right associative), while (((int int) (bool bool)) int) int is not a rank-2 intersection type. The problem of typing standard programming language constructs like local definitions, conditional expressions, and recursive definitions without losing the extra information provided by (rank-2) intersection is more difficult than one might expect (see, e.g., [16, 17, 2, 9]). Definition 1.1. ( -simple terms) Let be an intersection type system. We say that a term is -simple (or just simple when the system is clear from the context) if system can prove that it has a simple type. An example of non-simple term is λx.xx (which has principal type ((α 1 α 2 ) α 1 ) α 2, where α 1, α 2 are type variables). In previous work [9] we introduced rules and algorithms for assigning rank-2 intersection types to non-simple local definitions (i.e., terms of the shape let x = e 0 ine 1 where e 0 is non-simple) and nonsimple conditional expressions (i.e., non-simple terms of the shape if e 0 thene 1 else e 2 ). In this paper we propose new rules and algorithms for assigning rank-2 intersection types to non-simple recursive definitions (i.e., non-simple terms of the shape rec {x = e}). Typing rules for assigning intersection types to (non-simple) recursive definitions have been already proposed (see, e.g., [5, 13]), but no inference algorithms for these rules have been provided. At the best of our knowledge, previous algorithms for typing recursive definitions in the presence of intersection types [16, 17, 2, 9] allow only simple recursive definitions to be typed. Note that, the ability of typing non-simple recursive definitions is not, a priori, a fair measure for the expressive power of a system. It fact, it might be possible that a given system could type a term that is non-simple in the given system only because the given system somehow prevents the term from having a simple type. In another system that allows only simple terms to be typed, the same term might have a simple type and therefore be simple. When designing the new rules we will be careful to avoid such a pathological situation. Inferring types for polymorphic recursion (i.e., recursive definitions rec {x = e} where different occurrences of x in e are used with different types) [21, 22, 14, 19] is a recurring topic on the mailing list of popular typed programming languages (see, e.g., [13] for a discussion of several examples). The rules proposed in this paper are able to type interesting examples of polymorphic recursion. So, besides providing a solution to the problem of finding decidable rules for typing non-simple recursive definitions, the techniques proposed in this paper address also the related topic of polymorphic recursion. Moreover

3 F. Damiani / Rank-2 intersection for recursive definitions 1003 (as we will point out in Section 10), these techniques do not depend on particulars of rank-2 intersection. So they can be applied to other type systems. A preliminary version of the results presented in this paper appeared as [10] Organization of the paper Section 2 introduces a small functional programming language, which can be considered the kernel of languages like SML, OCaml, and Haskell. Section 3 introduces some basic definitions. Section 4 presents the rank-2 intersection type system ( 2 ) for the rec-free fragment of the language. Section 5 briefly reviews the rules for typing recursive definitions in the presence of rank-2 intersection types that have been proposed in the literature. Section 6 extends 2 with a new rule for typing non-simple recursive definitions and Sections 7 and 8 consider decidable restrictions of the rule. Section 9 outlines how to adapt the rules proposed in Sections 6, 7 and 8 to deal with mutual recursion. We conclude by pointing out that the proposed techniques can be applied to other type systems and by discussing some further work. The appendix contains the proofs of the main results. An on-line demonstration of a prototype implementation of the typing algorithm is available at the url 2. A small ML-like language We consider a quite rich set of constants (that will be useful to formulate the examples considered through the paper) including the booleans, the integer numbers, the constructors for pairs and lists, some logical and arithmetic operators, and the functions for decomposing pairs (fst and snd) and lists (null, hd and tl). The syntax of constants (ranged over by c) is as follows: c ::= ι pair nil cons not and or + = < fst snd null hd tl where ranges over booleans (true and false) and ι ranges over integer numbers. Expressions (ranged over by e) are defined by the pseudo-grammar: e ::= x c λ x.e e 1 e 2 rec {x = e} let x = e 0 ine 1 if e 0 thene 1 elsee 2, where x ranges over variables. Free and bound occurrences of a variable in an expression are defined as usual. The (finite) set of the free variables of an expression e is denoted by FV(e). The capture avoiding simultaneous substitution of the free occurrences of the variables x 1,...,x n in the expression e with the expressions e 1,...,e n, denoted by e[x 1 := e 1,...,x n := e n ], is defined as usual. 3. Basic definitions In this section we introduce the syntax of our rank-2 intersection types, together with other basic definitions that will be used in the rest of the paper.

4 1004 F. Damiani / Rank-2 intersection for recursive definitions We will be defining several classes of types. The set of simple types (T 0 ), ranged over by u, the set of rank-1 intersection types (T 1 ), ranged over by w, and the set of rank-2 intersection types (T 2 ), ranged over by v, are defined by the pseudo-grammar: u ::= α u 1 u 2 bool int u 1 u 2 u list (simple types) w ::= u 1 u n (rank-1 types) v ::= u w v (rank-2 types) where n 1. We have type variables (ranged over by α), arrow types, and a selection of ground types and parametric datatypes. The ground types are bool (the type of booleans) and int (the type of integers). The other types are pair types and list types. Note that T 0 = T 1 T 2 (for technical convenience, following [17] and other papers, rank-1 types are not included into rank-2 types). The constructor is right associative, e.g., u 1 u 2 u 3 means u 1 (u 2 u 3 ), and the constructors and list bind more tightly than, e.g., u 1 u 2 u 3 means u 1 (u 2 u 3 ). We consider to be associative, commutative, and idempotent. Therefore any type in T 1 can be considered (modulo elimination of duplicates) as a set of types in T 0. The constructor binds more tightly than, e.g., u 1 u 2 u 3 means (u 1 u 2 ) u 3, and less tightly than and list (which can be applied only to simple types). We assume a countable set of type variables. A substitution s is a function from type variables to simple types which is the identity on all but a finite number of type variables. The application of a substitution s to a type t, denoted by s(t), is defined as usual. Note that, since substitutions replace type variables by simple types, we have that T 0, T 1, and T 2 are closed under substitution. An environment T is a set {x 1 : t 1,...,x n : t n } of assumptions for variables such that every variable x i (1 i n) can occur at most once in T. The expression Dom(T) denotes the domain of T, which is the set {x 1,...,x n }. We write T, x : t for the environment T {x : t} where it is assumed that x Dom(T). The application of a substitution s to an environment T, denoted by s(t), is defined as usual. Definition 3.1. (Rank-1 environments) A rank-1 environment A is an environment {x 1 : w 1,..., x n : w n } of rank-1 type assumptions for variables. Given two rank-1 environments A 1 and A 2, we write A 1 A 2 to denote the rank-1 environment: {x : w 1 w 2 x : w 1 A 1 and x : w 2 A 2 } {x : w 1 A 1 x Dom(A 2 )} {x : w 2 A 2 x Dom(A 1 )}. A pair is a formula A; v where A is a rank-1 environment and v is a rank-2 type. Let p range over pairs. The following relation is fairly standard.

5 F. Damiani / Rank-2 intersection for recursive definitions 1005 Definition 3.2. (Pair specialization relation spc ) The subtyping relations 1 ( T 1 T 1 ) and 2 ( T 2 T 2 ) are defined by the following rules: 1 ( ) u 1 u n 1 u 1 u m where 1 i n {u i } 1 j m {u j } (REF) u 2 u where u is not an arrow type ( ) w 1 w v 2 v w v 2 w v Given two rank-1 environments A and A we write A 1 A to mean that Dom(A) = Dom(A ), 2 and for every assumption x : w A there is an assumption x : w A such that w 1 w. A pair A; v can be specialized to A ; v (notation A; v spc A ; v ) if A 1 s(a) and s(v) 2 v, for some substitution s. Example 3.1. We have {y : β}; α β spc {y : γ}; ((γ γ) γ) γ. Note that the relation spc is reflexive and transitive. 4. Typing the rec-free fragment of the language In this section we introduce the type system 2 for the rec-free fragment of the language (i.e., the fragment without recursive definitions). System 2 is just a reformulation of Jim s system P 2 [17] System 2 Following Wells [24], in the type inference system 2 we use typing judgements of the shape 2 e : A; v, instead of the more usual notation A 2 e : v. This slight change of notation will simplify the presentation of the new typing rules for recursive definitions (in Section 6). The judgement 2 e : A; v means e is 2 -typable with pair A; v, where A is a rank-1 environment containing the type assumptions for the free variables of e, and v is a rank-2 type. In any valid judgement 2 e : A; v it holds that Dom(A) = FV(e). The typing rules of system 2 are given in Fig. 2. Rule (SPC), which is the only non-structural rule, allows to specialize (in the sense of Definition 3.2) the pair inferred for an expression. 1 In rule (REF), the condition that u is not an arrow type (i.e., not a type of the shape u u ) is included for technical convenience only, to get a syntax-directed system. 2 The requirement Dom(A) = Dom(A ) in the definition of A 1 A is not present in most other papers. The usual definition drops this requirement, thus allowing Dom(A) Dom(A ). We have added such a requirement since it will simplify the presentation of the new typing rules for recursive definitions (in Section 6).

6 1006 F. Damiani / Rank-2 intersection for recursive definitions c type(c) c type(c) bool ι int pair α 1 α 2 (α 1 α 2 ) nil α list cons α α list α list not bool bool and, or bool bool bool Figure 1. +,,, / int int int =, < int int bool fst α 1 α 2 α 1 snd α 1 α 2 α 2 null α list bool hd α list α tl α list α list Types for constants (SPC) e : p e : p where p spc p (CON) c : ; v where v = type(c) (VAR) x : {x : u}; u where u T 0 (APP) e : A; u 1 u n v e 0 : A 1 ; u 1 e 0 : A n ; u n e e 0 : A A 1 A n ; v (ABS) e : A, x : w; v λ x.e : A; w v (ABSVAC) e : A; v λ x.e : A; u v where x FV(e) and u T 0 Figure 2. Typing rules for the rec-free fragment of the language (system 2 ) The rule for typing constants, (CON), uses the function type (tabulated in Figure 1) which specifies a type for each constant. Note that, by rule (SPC), it is possible to assign to a constant c all the specializations of the pair ; type(c). Since 2 e : A; v implies Dom(A) = FV(e), we have two rules for typing an abstraction λ x.e, (ABS) and (ABSVAC), corresponding to the two cases x FV(e) and x FV(e). Note that, by rule (VAR), it is possible to assume a different simple type for each occurrence of the λ-bound variable. The rule for typing function application, (APP), allows to use a different pair for each expected type of the argument (the operator on rank-1 environments has been defined immediately after Definition 3.1). For simplicity, we have omitted the typing rule for local definitions, which handles expressions let x = e 0 ine 1 like syntactic sugar for (λx.e 1 )e 0, and the typing rule for for conditional expressions, which handles expressions if e 0 thene 1 elsee 2 like syntactic sugar for the application ifce 0 e 1 e 2,

7 F. Damiani / Rank-2 intersection for recursive definitions 1007 where ifc is a special constant of type bool α α α. Note that, according to these rules, only simple local definitions and conditional expressions can be typed Principal pairs and decidability for 2 Definition 4.1. (Principal pairs) Let be a type system with judgements of the shape e : p. A pair p is principal for a term e if e : p, and if e : p implies p spc p. We say that system has the principal pair property to mean that every typable term has a principal pair. System 2 has the principal pair property and is decidable (see, e.g., [17]). 5. Typing simple recursive definitions In this section we briefly recall the typing rules for recursive definitions proposed by Jim [16, 17] (see also [9]) which, at the best of our knowledge, are the more powerful rules for typing recursive definitions in presence of rank-2 intersection types that can be found in the literature. In order to be able to formulate these typing rules we need some auxiliary definitions. The set of rank-2 intersection type schemes (T 2 ), ranged over by vs, is defined by the following pseudo-grammar: vs ::= α.v (rank-2 schemes), where α denotes a finite (possibly empty) unordered sequence of distinct type variables α 1 α m and v T 2. Let ɛ denote the empty sequence, ɛ.v is a legal expression, syntactically different from v, so that T 2 T 2 =. Free and bound type variables are defined as usual. For every type or scheme t T 1 T 2 T 2 let FTV(t) denote the set of free type variables of t. For every scheme α.v it is assumed that { α } FTV(v). Moreover, schemes are considered equal modulo renaming of bound type variables. Given a type v T 2 and a rank-1 environment A, we write Gen(A, v) for the -closure of v in A, that is the rank-2 scheme α.v, where α is the sequence of the type variables in FTV(v) x:w A FTV(w). Definition 5.1. (Scheme instantiation relation) For every rank-2 scheme α.v and for every rank-1 type u 1 u n, let α.v 2,1 u 1 u n mean that, for every i {1,...,n}, u i = s i (v), for some substitution s i such that s i (β) = β for all β α. ( ) Example 5.1. We have (remember that is idempotent): αβγ. (α β) (β γ) α γ ) ( ) 2,1 ((int int) int int (bool bool) bool bool. We can now present the typing rules. All these rules type recursive definitions rec {x = e} by assigning simple types to the occurrences of x in e (each occurrence may be assigned a different simple type). Therefore, they allow only simple (in the sense of Definition 1.1) non-vacuous recursive definitions to be typed (we say that a recursive definition rec {x = e} is vacuous to mean that x FV(e)). Jim [16]

8 1008 F. Damiani / Rank-2 intersection for recursive definitions proposed the following rules for typing recursive definitions: 3 (REC) e : A, x : w; v rec {x = e} : A; v where Gen((A, x : w), v) 2,1 w (RECVAC) e : p rec {x = e} : p where x FV(e) These two rules corresponds to the two cases x FV(e) and x FV(e). Note that the rule for non-vacuous recursion, (REC), requires that the rank-2 type v assigned to rec {x = e} must be such that Gen((A, x : w), v) 2,1 w. I.e., s(v) = u i for some substitution s and simple type u i such that s(a) = A and w = u 1 u i u n (1 i n). This implies rec {x = e} : A; u i. Therefore, rule (REC) allows only simple recursive definitions to be typed. System 2 +(REC) + (RECVAC) has the principal pair property and is decidable (see, e.g., [16, 9]). As pointed out by Jim [17], rule (REC) might be generalized along the lines of Mycroft s rule (FIX ) [22]: just replace the condition Gen((A, x : w), v) 2,1 w by the condition Gen(A, v) 2,1 w. Let us call (REC ) the generalized rule. Rule (REC ) is strictly more powerful than rule (REC) (see Section 3 of [17] for an example) but, again, it allows only simple recursive definitions to be typed. Jim [16] proposed also the following rule: 3 (RECINT) e : A, x : u 1 u m ; u 1 e : A, x : u 1 u m ; u m where i 0 {1,...,m} rec {x = e} : A; u i0 The decidability of 2 +(RECINT) is an open question (there is no obvious way to find an upper bound on the value of m used in the rule) [16]. Note that, since u 1,, u m T 0 (and, in particular, u i0 T 0 ), also this rule allows only simple recursive definitions to be typed. 6. System P 2: typing non-simple recursive definitions In this section we extend system 2 to type non-simple recursive definitions System P 2 In order to be able to type non-simple recursive definitions, we propose to adopt the following strategy: allow one to assign to rec {x = e} any pair p that can be assigned to e by assuming the pair p itself for x. To implement the above strategy, we introduce the notion of pair environment (taken from [9]). Definition 6.1. (Pair environments) A pair environment D is an environment {x 1 : p 1,..., x n : p n } of pair assumptions for variables such that Dom(D) VR(D) =, where VR(D) = x: A; v D Dom(A) is the set of variables occurring in the range of D. Every pair p occurring in D is implicitly universally quantified over all type variables occurring in p. 4 3 We still give these rules the original name used in [16], but we adapt them to fit in the type assignment system 2. 4 To emphasize this fact the paper [9] uses pair schemes. I.e., formulae of the shape α.p, where α is the sequence of all the type variables occurring in the pair p.

9 F. Damiani / Rank-2 intersection for recursive definitions 1009 (SPC) D e : p D e : p where p spc p (CON) D c : ; v where v = type(c) (VAR) D x : {x : u}; u where u T 0 and x Dom(D) (APP) D e : A; u 1 u n v D e 0 : A 1 ; u 1 D e 0 : A n ; u n D e e 0 : A A 1 A n ; v (ABS) D e : A, x : w; v D λ x.e : A; w v where x D (ABSVAC) D e : A; v D λ x.e : A; u v where x FV(e), u T 0, and x D (VAR-P) D, x : p x : p D, x : A; v e : A; v (REC-P) D rec {x = e} : A; v where Dom(A) = FV D (rec {x = e}) and x D Figure 3. Typing rules of system P 2 The typing rules of system 2 P (where P stands for polymorphic ) are given in Fig. 3. The judgement D 2 P e : A; v means e is P 2-typable in D with pair A; v, where D is a pair environment specifying pair assumptions for the variables introduced by a rec-binder in the program context surrounding e, A; v is the pair inferred for e, where A is a rank-1 environment containing the type assumptions for the free variables of e which are not in Dom(D), and v is a rank-2 type. Let D be a pair environment, x D is short for x Dom(D) VR(D) and FV D (e) = (FV(e) Dom(D)) VR({x : p D x FV(e)}) is the set of the free variables of the expression e in D. In any valid judgement D P 2 e : A; v it holds that Dom(D) Dom(A) = and Dom(A) = FV D(e). Rules (SPC), (CON), (VAR), (ABS), (ABSVAC), and (APP) are just the rules of system 2 (in Fig. 2) modified by adding the pair environment D on the left of the typing judgements and, when necessary, side conditions (like x Dom(D) in rule (VAR)) to ensure that Dom(D) Dom(A) =. Rule (REC-P) allows to assign to a recursive definition rec {x = e} any pair p that can be assigned to e by assuming the pair p for x. Note that the combined use of rules (VAR-P) and (SPC) allows to assign a different specialization of p to each occurrence of x in e. Remark 6.1. (About the rank of system 2 P) Looking at the typing rules of system 2 P we might wonder whether it could be considered a rank-2 intersection type system. The answer to this question depends on what is meant by rank-n type

10 1010 F. Damiani / Rank-2 intersection for recursive definitions system (where n is a natural number and is a type constructor). 5 For instance, system 2 P could be considered a rank-2 intersection type system under the interpretation that, in a rank-n type system, variables are allowed to have rank-n types as long as that does not inflate the rank of the type a term that binds the variable. Note that, according to this interpretation, both the Hindley-Milner type system [8] and the (let-free fragment of) the Milner-Mycroft type system [22] would be rank-1 type systems. Another, more restrictive, interpretation of rank-n type system would be to insist that variables are allowed to have only rank-m types, where m is either strictly less than n or (when n = 0) equal to 0, irrespective of where they are bound. Under the latter interpretation system 2 P would not be a rank-2 intersection type system and would lie between ranks 2 and 3. Similarly, both the Hindley-Milner type system and the (let-free) fragment of the Milner-Mycroft type system would not be rank-1 type system and would lie between ranks 1 and On the expressive power of system P 2 System 2 P is able to type non-simple recursive definitions, as illustrated by the following example. Example 6.1. The recursive definition rec {f = e}, where e = λ g l. if (null l) ( then nil else cons pair ( ) ( ) g (hd l)1) (g y true) f g (tl l), is non-simple since it defines a function that uses its parameter g with two different non unifiable types. The 2 P -typing judgement rec {f =e} : {y : α 2 }; ((α 1 int β 1 ) (α 2 bool β 2 )) α 1 list (β 1 β 2 )list holds and the expression e 0 = (λ y. rec {f = e}) false (λ z 1.λ z 1.pair z 1 z 2 ) (cons 0 nil), that would evaluate to cons (pair (pair 0 1) (pair false true)) nil, has 2 P -typing judgement e 0 : ; ((int int) (bool int))list. System 2 P has more expressive power than the system 2 +(REC) + (RECVAC) of Section 5 (and therefore of system P R 2 [17, 16]) and of the Milner-Mycroft system [22] (see also [21]), in the sense that the set of typable terms increases, and types express better the behaviour of terms. In particular, the following theorems hold. Theorem 6.1. If 2 +(REC)+(RECVAC) e : A; v, then P 2 e : A; v. Theorem 6.2. If e : u is Milner-Mycroft derivable, then P 2 e : ; u. The following example shows that ML-typable recursive definitions may get a more precise type by using system P 2. 5 Recall that the rank of a type t is the maximum depth of the occurrences of the type constructor in t, counting nesting in the left argument of the type constructor (a type without occurrences of is a rank-0 type and a type without occurrences of in the left argument of is a rank-1 type).

11 F. Damiani / Rank-2 intersection for recursive definitions 1011 Example 6.2. The ( 2 P-simple) recursive function rec {g = e }, where ( ) e = λ f l 1 l 2. if or pair (null l 1 ) (null l 2 ) then nil ( ) ( ) else cons pair (f (hd l 1 )) (f (hd l 2 )) g f (tl l 1 )(tl l 2 ), is ML-typable with principal type (α β) α list α list (β β) list. Therefore, the expression e 0 = let h = λ z.cons z nil in (rec {g = e }) h (cons 7 nil) (cons true nil) which uses the function h with the two non-unifiable types int int list and bool bool list is not ML-typable. System P 2 allows to assign a more informative type to the recursive function rec {g=e }, rec {g=e } : ; ((α β) (γ δ)) α list γ list (β δ)list, and is able to type the expression e 0, e 0 : ; ((int list) (bool list)) list Principal-in-D pairs and undecidability of P 2 The following notion of principal-in-d pair (taken from [9]) adapts the notion of principal pair (see Definition 4.1) to deal with the pair environment D. Definition 6.2. (Principal-in-D pairs) Let be a system with judgements of the shape D e : p. A pair p is principal-in-d for a term e if D e : p, and if D e : p implies p spc p. We say that system has the principal-in-d pair property to mean that every typable term has a principal-in-d pair. We don t know whether system 2 P has the principal-in-d pair property. The following theorem implies that the restriction of 2 P which uses only simple types, that we will call P 0 (see Appendix A.1.3 for a precise definition), is undecidable (as is the Milner-Mycroft system [14, 19]). Theorem 6.3. Let e be a closed let-free expression. Then P 0 Milner-Mycroft derivable. Not surprisingly, also the whole system 2 P is undecidable. e : ; u if and only if e : u is Theorem 6.4. System 2 P is undecidable. 7. Systems k 2 (k 1): a family of decidable restrictions of P 2 By taking inspiration from the idea of iterating type inference (see, e.g., [22, 21]) and by relying on the notion of principal-in-d pair (see Definition 6.2) we will now design a family of decidable restrictions of rule (REC-P).

12 1012 F. Damiani / Rank-2 intersection for recursive definitions 7.1. Systems k 2 (k 1) For every finite set of variables X = {x 1,...,x n } (n 0) let P X = { A; v A; v is pair such that Dom(A) = X}, and B X = { {x 1 : α 1,...,x n : α n }; α the type variables α 1,...,α n, α are all distinct} P X. The pair specialization relation spc (see Definition 3.2) is a preorder over P X and, for all pairs b B X and p P X, b spc p. For every subset S X of P X, is the set of the spc -minimum elements of S X. Min spc (S X ) = {p S X p spc p for all p S X } Fact 7.1. Let be a system with judgements of the shape D e : p. A pair p is a principal-in-d pair for a term e if and only if p Min spc ({p D e : p }). For every k 1, let k 2 be the system obtained from P 2 by replacing rule (REC-P) with the following rule: D, x : p 0 e : p 1 D, x : p k 1 e : p k (REC-k) D rec {x = e} : p k where x D, p 0 B FVD (rec {x=e}), p k 1 = p k, and for all i {1,...,k} p i Min spc ({p D, x : p i 1 e : p}) (note that D k 2 e : p implies D k+1 2 e : p). For all k 1, system k 2 has the principal-in-d pair property and is decidable the result follows from Theorem 7.5 (soundness and completeness of the inference algorithm for k 2 ) of Section 7.4. According to Fact 7.1, in rule (REC-k), the requirement is equivalent to for all i {1,...,k} p i Min spc ({p D, x : p i 1 e : p}) (1) for all i {1,...,k} p i is a principal-in-(d, x : p i 1 ) pair for e. Therefore, the checking of a purported k 2 derivation requires the ability to decide whether a pair is principal-in-d (which is a quite unusual property of a type system). Note that requirement (1) is crucial. In fact, removing it would make rule (REC-k) equivalent to rule (REC-P) for all k Understanding k 2-typability (k 1) The aim of this section is to provide some insights about how rules (REC-k) work. Let be a special constant, representing the always divergent computation, such that type( ) = α. For every natural number k, let the k-approximant of a recursive definition rec {x = e} be the term rec k {x = e} inductively defined as follows: rec 0 {x = e} = x 1 x n, where {x 1,...,x n } = FV(e) {x}, and

13 F. Damiani / Rank-2 intersection for recursive definitions 1013 rec k+1 {x = e} = e[x := rec k {x = e}]. The term rec k {x = e} approximates the behaviour of the recursive definition rec {x = e} in the sense that, if rec k {x = e} (applied to some, possibly none, arguments) yields a result, then the same result is produced by rec {x = e} (applied to the same arguments). The following theorem says that, for all k 1, the k 2-typable recursive definitions can be characterized as the recursive definitions such that system k 2 is not able to distinguish between k 1-approximant and k 2 -approximant for any k 1, k 2 k 1. Theorem 7.1. For every k 1, recursive definition rec {x = e}, and pair environment D, D k 2 rec {x = e} : p (for some pair p) if and only if {p D k 2 rec k 1 {x = e} : p } = {p D k 2 rec k {x = e} : p }. Let a top-level recursive definition be a rec-expression rec {x = e} such that e does not contain recexpressions. By observing that the h-approximant (h 0) of a top-level recursive definition is a rec-free expressions, we get immediately the following characterization of k 2-typability w.r.t. the empty pair environment of top-level recursive definitions in terms of 2 -typability. Corollary 7.1. For every k 1 and top-level recursive definition rec {x = e}, k 2 e : p (for some pair p) if and only if {p 2 rec k 1 {x = e} : p } = {p 2 rec k {x = e} : p }. Remark 7.1. (An alternative characterization of k 2-typability (k 1)) For every k 1, let k-a 2 be the system obtained from 2 by adding the following rule: (REC-k-A) where rec k 1 {x = e} : p rec k {x = e} : p rec {x = e} : p p Min spc ({p rec k 1 {x = e} : p }) and p Min spc ({p rec k {x = e} : p }) Building on Theorem 7.1, it it is possible to prove the equivalence between k 2-typability and k-a 2 - typability. Namely, for every k 1 and term e we have that k 2 e : p if and only if k-a 2 e : p. Systems k-a 2 are conceptually simpler than systems k 2 (since they avoid the introduction of the pair environment D) and enjoy the principal pair property (in the sense of Definition 4.1). However, rule (REC-k-A) seems not suitable for the design of practical inference algorithms On the expressive power of systems k 2 (k 1) Comparison with system P 2 The relation between system k 2 and system P 2 is stated by the following theorem which, roughly speaking, says that when rule (REC-k) works at all, it works as well as rule (REC-P) does.

14 1014 F. Damiani / Rank-2 intersection for recursive definitions Theorem 7.2. For every k 1: 1. If D k 2 e : p, then D P 2 e : p. 2. If e is k 2 -typable in D and D P 2 e : p, then D k 2 e : p Comparison with the ML type system Unfortunately, for every k 1, system k 2 (see Example 7.1 below). is not able to type all the ML-typable recursive definitions Example 7.1. (Rule (REC-k) and the ML rule are incomparable) The expression rec {f = e} of Example 6.1 in Section 6.2 is non-simple, therefore it is not ML-typable. Since p = {y : α 2 }; ((α 1 int β 1 ) (α 2 bool β 2 )) α 1 list (β 1 β 2 )list, is both a principal-in-{f : {y : α 1 }; α } and a principal-in-{f : p} pair for e in system 2 2, we have that p is a principal-in- pair for rec {f = e} in system k 2 (for all k 2). The expression rec {h = e }, where e = λ g y. if true then y else g (hg y), is ML-typable with principal pair ; (α α) α α and is not k 2-typable (for all k 1) in fact, for every k 1, the expression e has principal-in-{h : p k 1 } pair p k = ; ((α 0 α 1 ) (α 1 α 2 ) (α k 1 α k )) (α 1 α 2 α k ) α k in system 1 2 and, therefore, in system l 2 (for all l 1). Note that rec {h = e } is 2 P -typable with pair ; ((α γ) (γ α) (α β)) (α β γ) β More about systems 1 2, 2 2, and 3 2 System 1 2 is able to type, in any pair environment D, only recursive definitions rec {x = e} that have the pairs in B FVD (rec {x=e}). The paradigmatic example of recursive definition of this kind is the nonterminating expression rec {x = x} that has principal-in- pair ; α. System 2 2 is able to type examples of non-simple recursive definitions (like the term rec {f = e} of Example 6.1) and to assign more informative types to ML-typable recursive definitions (like the term rec {g = e } of Example 6.2). Moreover, it is also able to type many interesting examples of polymorphic recursion. Consider for instance the following O Caml program 6 type a tree = EMPTY NODE of a * ( a tree) tree ;; let rec collect t = match t with EMPTY -> [] NODE(n,t1) -> n :: flatmap collect (collect t1);; 6 This example is taken from [17], it originally comes from the ML mailing list, and has arisen in practice. Here we use O Caml syntax since this is the syntax accepted by our prototype implementation of the type inference algorithm (see Section 1.1).

15 F. Damiani / Rank-2 intersection for recursive definitions 1015 where a tree is a polymorphic tree type and flatmap is the standard list manipulation function of principal type ( a -> b list) -> a list -> b list. The function collect, which collects all the labels in an a tree and returns them in an a list, is not ML-typable (and cannot be typed by the typing rules proposed in [17]) but can be typed (with principal-in- pair <{}, a tree -> a list>) by rule (REC-2). The following example shows a recursive definition (taken from [7]) that is 3 2 -typable and not typable. Example 7.2. The (non ML-typable) expression rec {f = e}, where e = λ f 1 g n x.if n = 0 then g x ) ( ) else f f 1 (λ y.(λ h.g (hy)) n 1 x f 1 defines the function F such that F f 1 g n x = g (f 1 (f }{{} 1 x) ). Since n times p 1 = ; α (β γ) int β γ, is a principal-in-{f : ; α } pair for e in system 3 2 and p 2 = ; (α α) (α β) int α β, is both a principal-in-{f : p 1 } and a principal-in-{f : p 2 } pair for e in system 3 2, we have that p 2 is a principal-in- pair for rec {f = e} in system k 2 (for all k 3) An inference algorithm for k 2 (k 1) The inference algorithm makes use of an algorithm for checking whether the spc relation (see Definition 3.2) holds and of an algorithm for finding a most general solution to a 2,1 -satisfaction problem ( 2,1 is the relation of Definition 5.1). Existence of an algorithm for checking whether the spc relation holds is stated by the following theorem. Theorem 7.3. (Decidability of spc ) There is an algorithm that, for every p and p, decides whether p spc p holds. A 2,1 -satisfaction problem [17, 16] (see also [9]) is a formula α.p, where α is a (possibly empty) sequence of type variables occurring free in P, and P is a set in which every element is either: 1) an equality between T 0 types; or 2) an inequality between a T 2 T 2 type and a T 1 type. A substitution s is a solution to α.p if there exists a substitution s such that: s(α) = s (α) for all α α, s (u 1 ) = s (u 2 ) for every equality (u 1 = u 2 ) P, and s (vs) 2,1 s (w) (resp. s ( ɛ.v) 2,1 s (w)) for every inequality (vs w) P (resp. (v w) P ). We will write MGS( α.p) for the set of most general solutions to the 2,1 -satisfaction problem α.p (a 2,1 -satisfaction problem α.p generalizes unification and, as with unification, most general solutions are not unique). Existence of an algorithm for finding a most general solution to a 2,1 -satisfaction problem is stated by the following theorem [17, 16] (see also [9]).

16 1016 F. Damiani / Rank-2 intersection for recursive definitions Theorem 7.4. There is an algorithm that decides, for any 2,1 -satisfaction problem, whether it is solvable, and, if so, returns a most general solution. The inference algorithm is presented in a style favored by the intersection type community. For all k 1, we define a function PP k 2 which, for every expression e and environment D, returns a set of pairs PP k 2(D,e) such that if PP k 2(D,e) =, then e is not k 2-typable in D, and every element of PP k 2(D,e) is a principal-in-d pair for e. 7 Definition 7.1. (The function PP k 2) For every expression e and environment D, the set PP k 2(D,e) is defined by structural induction on e. If e = x, then If x : A; v D and the substitution s is a fresh renaming of α = FTV(A) FTV(v), then s(a); s(v) PP k 2(D, x). If x Dom(D) and α is a type variable, then {x : α}; α PP k 2(D, x). If e = c and type(c) = v, then ; v PP k 2(D,c). If e = λ x.e 0 and A; v PP k 2(D,e 0 ), then If x FV(e 0 ) and α is a fresh type variable, then A; α v PP k 2(D, λ x.e 0 ). If x FV(e 0 ) and A = A, x : w, then A ; w v PP k 2(D, λ x.e 0 ). If e = e 0 e 1 and A 0 ; v 0 PP k 2(D,e 0 ), then If v 0 = α (a type variable), α 1 and α 2 are fresh type variables, A 1 ; v 1 PP k 2(D,e 1 ) is fresh, and s MGS( ɛ.{v 1 α 1, α = α 1 α 2 }, then s(a 0 A 1 ); s(α 2 ) PP k 2(D,e 0 e 1 ). If v 0 = u 1 u n v, for all i {1,...,n} the pairs A i ; v i PP k 2(D,e 1 ) are fresh, and s MGS( ɛ.{v i u i i {1,...,n}}), then s(a 0 A 1 A n ); s(v) PP k 2(D,e 0 e 1 ). If e = rec {x = e 0 } and A; v PP k 2(D,e 0 ), then If x FV(e 0 ), then A; v PP k 2(D,e). If x FV(e 0 ), then - If h is the minimum number in {1,...,k} such that p 0 B FVD (e), p 1 PP k 2((D, x : p 0 ),e 0 ),..., p h PP k 2((D, x : p h 1 ),e 0 ), and p h spc p h 1, then p h 1 PP k 2(D,e). 7 The set PP k 2(D,e) does not contain all the principal-in-d pairs for e. For instance, for all k 1, ; (α 1 α 2) α 1 is a principal-in- pair for λ x.x in k 2, but ; (α 1 α 2) α 1 PP k 2(, λ x.x).

17 F. Damiani / Rank-2 intersection for recursive definitions 1017 For every k 1, expression e, and pair environment D, the set PP k 2(D,e) is an equivalence class of pairs modulo renaming of the type variables in a pair. Let D X denote the restriction of the pair environment D to the set of variables X, which is the pair environment {x : p D x X}. The following proposition holds (the proof is straightforward, by induction on Definition 7.1). Proposition 7.1. For every k 1, expression e, and environment D, if A; v PP k 2(D,e), then 1. Dom(A) = (FV(e) Dom(D)) VR(D FV(e) ), and 2. A ; v PP k 2(D,e) if and only if there is a bijection s : Tv Tv such that s(a) = A and s(v) = v. Indeed Definition 7.1 specifies an inference algorithm: to perform type inference on an expression e w.r.t. the environment D simply follow the definition of PP k 2(D,e), choosing fresh type variables and using the 2,1 -satisfaction and spc -checking algorithms as necessary. Theorem 7.5. (Soundness and completeness of PP k 2 for k 2 ). For every k 1, expression e, and environment D: (Soundness). If p PP k 2(D,e), then D k 2 e : p. (Completeness). If D k 2 e : p, then p spc p for some p PP k 2(D,e). 8. Systems k, 2 (k 1): recovering ML-typability In this section we show that, for all k 1, it is quite easy to modify system k 2 in order to make it to extend the ML system while preserving decidability and principal-in-d pair property Systems k, 2 (k 1) Definition 8.1. A typing rule for recursive definitions (REC- ) is 2 P-suitable if the system 2 obtained from 2 P by replacing rule (REC-P) with rule (REC- ) 1. is a restriction of system P 2 (i.e., D 2 e : A; v implies D P 2 e : A; v ), 2. has the principal-in-d pair property, and 3. there is an algorithm that, given a pair environment D and a term e, returns a principal-in-d pair for e. For instance, for every k 1, rule (REC-k) is 2 P-suitable. Definition 8.1 implies that system 2 is as powerful system 2 P on rec-free terms (i.e., for all rec-free terms e, D 2 e : A; v if and only if D 2 P e : A; v ). Theorems 7.2 and 7.5 guarantee that, for all k 1, adding to system k 2 a P 2-suitable rule (REC- ) results in a system, denoted by k, 2, with both decidability and principal-in-d pair property. To see this, assume (without loss of generality) that the inference algorithm for system 2 is described by a function PP 2, defined as the function PP k 2 (see Definition 7.1) except for the last clause, that is as follows If e = rec {x = e 0 } and A; v PP 2 (D,e 0 ), then

18 1018 F. Damiani / Rank-2 intersection for recursive definitions If x FV(e 0 ), then A; v PP 2 (D,e). If x FV(e 0 ), then PP 2 (D,e). where the formula PP 2 (D,e) is a placeholder for a suitable description corresponding to rule (REC- ). Then, the function PP k, 2, defined as the function PPk 2 except for the clause for rec-expressions that is as follows (the only difference is the presence of an additional line to deal with the case when rule REC-k is not applicable) If e = rec {x = e 0 } and A; v PP k, 2 (D,e 0), then If x FV(e 0 ), then A; v PP k, 2 (D,e). If x FV(e 0 ), then - If h is the minimum number in {1,...,k} such that p 0 B FVD (e), p 1 PP k, 2 ((D, x : p 0 ),e 0 ),..., p h PP k, 2 ((D, x : p h 1),e 0 ), and p h spc p h 1, then p h 1 PP k, 2 (D,e). - Otherwise (if such an h does not exist), PP k, 2 (D,e). describes a sound and complete inference algorithm for system k, Recovering ML-typability To extend system k 2 to type all the ML typable recursive definitions, we have just to add to system k 2 a 2 P -suitable rule which is at least as expressive as the ML rule for recursive definitions. The simplest way of doing this would be to add (a version, modified to fit into system k 2, of) the ML rule itself: (REC-ML) D e : A, x : u; u D rec {x = e} : A; u where x D (producing system k,ml 2 ). Another possibility, is to add the following rule (REC-J) D e : A, x : w; v D rec {x = e} : A; v where Gen((A, x : w), v) 2,1 w and x D which corresponds to rule (REC) of Section 5. In this way we obtain a system, k,j 2, which is more expressive that system 2 +(REC)+(RECVAC) of Section 5 (observe that 2 +(RECVAC)-typabily implies k 2 -typability). Example 8.1. The expression rec {h = e } of Example 7.1, which is not k 2-typable (for all k 1), has principal-in- pairs ; (α α) α α and ; ((α α) (α β)) (α β) β in systems 1,ML 2 and 1,J 2, respectively. An inference algorithm for system k,ml 2 (PP k,ml 2 ) and an inference algorithm for k,j 2 (PP k,j 2 ) can, illustrated at the end of Section 8.1, by replacing the (D,e) occurring in the clause for rec-expression with be obtained from the inference algorithm PP k, 2 formula PP k, 2

19 F. Damiani / Rank-2 intersection for recursive definitions 1019 if A = A, x : w, α is a fresh type variable, and s MGS( ɛ.{v α, w α}), then s(a ); s(v) PP k,ml 2 (D,e) and respectively. if A = A, x : w and s MGS( ɛ.{gen(a, v) w}), then s(a ); s(v) PP k,j 2 (D,e), 9. Typing non-simple mutually recursive definitions The results presented in Sections 6, 7, and 8 can be straightforwardly adapted to mutually recursive definitions. Let rec i {x 1 = e 1,...,x n = e n } (where 1 i n) denote the i-th expression defined by the mutually recursive definition {x 1 = e 1,...,x n = e n }. Let 2 M-P be the extension of system 2 P to mutual recursion, obtained by replacing rule (REC-P) with the following rule: (MREC-P) where D, x 1 : A 1 ; v 1,..., x n : A n ; v n e 1 : A 1 ; v 1 D, x 1 : A 1 ; v 1,..., x n : A n ; v n e n : A n ; v n D rec i0 {x 1 = e 1,...,x n = e n } : A 1 A n ; v i0 i 0 {1,...,n}, x 1,...,x n D, and (for all i {1,...,n}) Dom(A i ) = FV D (e i [x 1 :=e 1,...,x n :=e n ] [x 1 :=e 1,...,x n :=e n ]) {x }{{} 1,...,x n } n 1 times The notion of 2 P -suitable typing rule for recursive definitions (Definition 8.1) can be adapted to system 2 M-P and mutually recursive definitions just by replacing (in the text of Definition 8.1) system 2 P with system 2 M-P and rule (REC-P) with rule (MREC-P). The 2 M-P -suitable typing rules (MREC-k), (MREC-ML), and (MREC-J) for mutually recursive definitions given in Fig. 4 correspond to the 2 P -suitable rules (REC-k), (REC-ML), and (REC-J) introduced in sections 7.1 and 8.2. Decidable systems 2 M-k, M-k,ML 2, and M-k,J 2, corresponding to the decidable systems k 2, k,ml 2, and k,j 2, can be obtained from system M-P 2 by replacing rule (MREC-P) with rule (MREC-k), rules (MREC-k), (MREC-ML), and rules (MREC-k), (MREC-J), respectively.

20 1020 F. Damiani / Rank-2 intersection for recursive definitions (MREC-k) where D, x 1 : A 1,0 ; v 1,0,...,x n : A n,0 ; v n,0 e 1 : A 1,1 ; v 1,1 D, x 1 : A 1,0 ; v 1,0,...,x n : A n,0 ; v n,0 e n : A n,1 ; v n,1. D, x 1 : A 1,k 1 ; v 1,k 1,...,x n : A n,k 1 ; v n,k 1 e 1 : A 1,k ; v 1,k D, x 1 : A 1,k 1 ; v 1,k 1,...,x n : A n,k 1 ; v n,k 1 e n : A n,k ; v n,k D rec i0 {x 1 = e 1,...,x n = e n } : A 1,k A n,k ; v i0,k i 0 {1,...,n}, x 1,...,x n D, (for all i {1,...,n}) A i,0 ; v i,0 B FVD (rec {x=e}), A i,k 1 ; v i,k 1 = A i,k ; v i,k, (for all j {1,...,k}) p i,j Min spc ({p D, x 1 : p 1,j 1,...,x n : p n,j 1 e : p}), and Dom(A i,j ) = FV D (e i [x 1 :=e 1,...,x n :=e n ] [x 1 :=e 1,...,x n :=e n ]) {x }{{} 1,...,x n } n 1 times D e 1 : A 1, x 1 : u 1,...,u n ; u 1 D e n : A n, x 1 : u 1,...,u n ; u n (MREC-ML) D rec i0 {x 1 = e 1,...,x n = e n } : A 1 A n ; u i0 where i 0 {1,...,n} and x 1,...,x n D D e 1 : A 1 ; v 1 D e n : A n ; v n (MREC-J) D rec i0 {x 1 = e 1,...,x n = e n } : A; v i0 where i 0 {1,...,n}, x 1,...,x n D, A 1 A n = A, x j1 : w j1,, x jm : w jm with Dom(A) {x j1,...,x jm } =, and (for all j {j 1,...,j m }) Gen(A 1 A n, v j ) 2,1 w j Figure 4. The M-P 2 -suitable typing rules (MREC-k), (MREC-ML), and (MREC-J)

21 F. Damiani / Rank-2 intersection for recursive definitions Conclusion In this paper we have taken the system of rank-2 intersection types for the λ-calculus and have extended it with a decidable rule for typing non-simple recursive definitions. The new rules can be integrated without problems with the rules for typing non-simple local definitions and conditional expressions that we have proposed in previous work [9]. The technique developed in this paper does not depend on particulars of rank-2 intersection and could therefore be applied to other type systems. To clarify this point, we consider the following definition (taken from [24]): A typing t for a typable term e is the collection of all the information other than e which appears in the final judgement of a proof derivation showing that e is typable (for instance, in system 2 a typing is a pair A; v ). We can now describe our technique as follows: 1. Take a type system for the λ-calculus, with judgements of the shape e : t where the typing t mentions exactly the variables in FV(e) (this requirement is not restrictive, since it is always possible to adjust the judgment and the rules of a type system in order to satisfy it), such that: system has the principal typing property (which is the property described by Definition 4.1 by replacing pair with typing and spc with a suitable relation for, that we will call spc), it is decidable to establish whether a typing t 1 can be specialized to a typing t 2 (i.e, whether t 1 spc t 2 holds), and there is a known algorithm that for every term e decides whether e is -typable and, if so, returns a principal typing for e. We also require that system contains the analogous of rule (SPC) (this additional requirement is not restrictive since, whenever the previous requirements are satisfied, such a rule is admissible). 2. Modify system by introducing a typing environment D (containing typing assumptions for the rec-bound identifiers) and by adding typing rules analogous to (VAR-P) and (REC-P). Let P be the resulting system (which has judgements of the shape D P e : t). 3. Prove that, for every set of variables X = {x 1,...,x n } (n 0) the relation spc is a preorder over P X = {t the typing t mentions exactly the variables in X} and there is a known set of typings B X P X such that, for all typings b B X and t P X, b spc t. For every k 1, define the analogous of rule (REC-k) and prove the analogous of Theorem 7.2. Let k denote the system obtained from P by replacing the analogous of rule (REC-P) with the analogous of rule (REC-k). System k is guaranteed to have the principal-in-d typing property (which is the property described by Definition 6.2 by replacing pair with typing and spc with spc). 4. If necessary, add to k a P -suitable (the analogous for P of the notion of P 2 -suitable given in Section 7) rule (REC- ). Let k, denote the resulting system.

22 1022 F. Damiani / Rank-2 intersection for recursive definitions The above steps describe a procedure that transforms a type system (without rules for rec-expressions) enjoying the principal typing property into a system k, (with rules for rec-expressions) enjoying the principal-in-d (and, in general, not the principal) typing property. It is worth examining what happens when the procedure is applied to the system of simple types [15]: the system at step (1) turns out to be 0 (the restriction of 2 which uses only simple types, which is just a reformulation of the system of simple types [15]); the one obtained at step (2) is 0 P, which is just a reformulation of the Milner-Mycroft system (see Theorem 6.3); and the systems obtained at step (4) by adding the ML typing rule for recursion, k,ml 0 (k 1), are of intermediate power between the let-free fragments of the ML type system and of the Milner-Mycroft type system we believe that the systems k,ml 0 correspond to the family of abstract interpreters described in [12]. Further work includes, on the one side, designing more expressive decidable extensions of systems k 2 (we are investigating the possibility of integrating techniques from the theory of abstract interpretation [7]). On the other, verifying the applicability of the technique to other type systems, like the system with rank-2 universal and intersection types proposed in [2], System P [18], and System E [4]. Acknowledgments I thank Viviana Bono, Sebastien Carlier, Mario Coppo, Joe Hallet, Assaf Kfoury, Emiliano Leporati, Peter Møller Neergaard, and Joe Wells for useful discussions on the subject of this paper. I also thank the anonymous referees of earlier versions of this paper for many insightful and constructive comments. References [1] van Bakel, S.: Intersection Type Disciplines in Lambda Calculus and Applicative Term Rewriting Systems, Ph.D. Thesis, Katholieke Universiteit Nijmegen, [2] van Bakel, S.: Rank 2 Types for Term Graph Rewriting, TIP 02, 75, Elsevier, [3] Barendregt, H. P., Coppo, M., Dezani-Ciancaglini, M.: A filter lambda model and the completeness of type assignment, J. of Symbolic Logic, 48, 1983, [4] Carlier, S., Polakow, J., Wells, J. B., Kfoury, A. J.: System E: Expansion variables for flexible typing with linear and non-linear types and intersection types., ESOP 04, 2986, Springer, [5] Coppo, M.: An extended polymorphic type system, MFCS 80, LNCS 88, Springer, [6] Coppo, M., Dezani-Ciancaglini, M.: An extension of basic functional theory for lambda-calculus, Notre Dame Journal of Formal Logic, 21(4), 1980, [7] Cousot, P.: Types as Abstract Interpretations, POPL 97, ACM, [8] Damas, L. M. M., Milner, R.: Principal type schemas for functional programs, POPL 82, ACM, [9] Damiani, F.: Rank 2 intersection types for local definitions and conditional expressions, ACM Trans. Prog. Lang. Syst., 25(4), 2003, [10] Damiani, F.: Rank-2 Intersection and Polymorphic Recursion, TLCA 05, 3461, Springer, [11] Girard, J. Y.: Interpretation fonctionelle et elimination des coupures dans l aritmetique d ordre superieur, Ph.D. Thesis, Université Paris VII, [12] Gori, R., Levi, G.: Properties of a type abstract interpreter, VMCAI 03, 2575, Springer, 2003.

Rank 2 Intersection Types for Local Definitions and Conditional Expressions

Rank 2 Intersection Types for Local Definitions and Conditional Expressions Rank 2 Intersection Types for Local Definitions and Conditional Expressions FERRUCCIO DAMIANI Università di Torino We propose a rank 2 intersection type system with new typing rules for local definitions

More information

Type Inference. For the Simply-Typed Lambda Calculus. Peter Thiemann, Manuel Geffken. Albert-Ludwigs-Universität Freiburg. University of Freiburg

Type Inference. For the Simply-Typed Lambda Calculus. Peter Thiemann, Manuel Geffken. Albert-Ludwigs-Universität Freiburg. University of Freiburg Type Inference For the Simply-Typed Lambda Calculus Albert-Ludwigs-Universität Freiburg Peter Thiemann, Manuel Geffken University of Freiburg 24. Januar 2013 Outline 1 Introduction 2 Applied Lambda Calculus

More information

Type Inference for Bimorphic Recursion

Type Inference for Bimorphic Recursion Type Inference for Bimorphic Recursion Makoto Tatsuta National Institute of Informatics 2-1-2 Hitotsubashi, Tokyo 101-8430, Japan tatsuta@nii.ac.jp Ferruccio Damiani Dipartimento di Informatica, Università

More information

Introduction to lambda calculus Part 6

Introduction to lambda calculus Part 6 Introduction to lambda calculus Part 6 Antti-Juhani Kaijanaho 2017-02-16 1 Untyped lambda calculus 2 Typed lambda calculi 2.1 Dynamically typed lambda calculus with integers 2.2 A model of Lisp 2.3 Simply

More information

Intersection Types for

Intersection Types for Intersection Types for -Trees Steffen van Bakel Franco Barbanera Mariangiola Dezani-Ciancaglini Fer-Jan de Vries Department of Computing, Imperial College, 180 Queen s Gate, London SW7 2BZ, UK E-mail:

More information

Lazy Strong Normalization

Lazy Strong Normalization Lazy Strong Normalization Luca Paolini 1,2 Dipartimento di Informatica Università di Torino (ITALIA) Elaine Pimentel 1,2 Departamento de Matemática Universidade Federal de Minas Gerais (BRASIL) Dipartimento

More information

Intersection Types and Lambda Theories

Intersection Types and Lambda Theories Intersection Types and Lambda Theories M.Dezani-Ciancaglini S.Lusin Abstract We illustrate the use of intersection types as a semantic tool for showing properties of the lattice of λ-theories. Relying

More information

Safety Analysis versus Type Inference for Partial Types

Safety Analysis versus Type Inference for Partial Types Safety Analysis versus Type Inference for Partial Types Jens Palsberg palsberg@daimi.aau.dk Michael I. Schwartzbach mis@daimi.aau.dk Computer Science Department, Aarhus University Ny Munkegade, DK-8000

More information

Notes on Inductive Sets and Induction

Notes on Inductive Sets and Induction Notes on Inductive Sets and Induction Finite Automata Theory and Formal Languages TMV027/DIT21 Ana Bove, March 15th 2018 Contents 1 Induction over the Natural Numbers 2 1.1 Mathematical (Simple) Induction........................

More information

Safety Analysis versus Type Inference

Safety Analysis versus Type Inference Information and Computation, 118(1):128 141, 1995. Safety Analysis versus Type Inference Jens Palsberg palsberg@daimi.aau.dk Michael I. Schwartzbach mis@daimi.aau.dk Computer Science Department, Aarhus

More information

Static Program Analysis

Static Program Analysis Static Program Analysis Xiangyu Zhang The slides are compiled from Alex Aiken s Michael D. Ernst s Sorin Lerner s A Scary Outline Type-based analysis Data-flow analysis Abstract interpretation Theorem

More information

Polar Type Inference with Intersection Types and ω

Polar Type Inference with Intersection Types and ω Electronic Notes in Theoretical Computer Science 70 No. 1 (2002) URL: http://www.elsevier.nl/locate/entcs/volume70.html 16 pages Polar Type Inference with Intersection Types and ω Sébastien Carlier 1,2

More information

Type Inference with Expansion Variables and Intersection Types in System E and an Exact Correspondence with β-reduction

Type Inference with Expansion Variables and Intersection Types in System E and an Exact Correspondence with β-reduction Type Inference with Expansion Variables and Intersection Types in System E and an Exact Correspondence with β-reduction Sébastien Carlier Heriot-Watt University http://www.macs.hw.ac.uk/~sebc/ J. B. Wells

More information

Komponenten- und Service-orientierte Softwarekonstruktion

Komponenten- und Service-orientierte Softwarekonstruktion Komponenten- und Service-orientierte Softwarekonstruktion Vorlesung 5: Combinatory Logic Synthesis Jakob Rehof LS XIV Software Engineering TU Dortmund Sommersemester 2015 SS 2015 J. Rehof (TU Dortmund)

More information

On Typability for Rank-2 Intersection Types with Polymorphic Recursion

On Typability for Rank-2 Intersection Types with Polymorphic Recursion On Typability for Rank-2 Intersection Types with Polymorphic Recursion Tachio Terauchi EECS Department University of California, Berkeley Alex Aiken Computer Science Department Stanford University Abstract

More information

Krivine s Intuitionistic Proof of Classical Completeness (for countable languages)

Krivine s Intuitionistic Proof of Classical Completeness (for countable languages) Krivine s Intuitionistic Proof of Classical Completeness (for countable languages) Berardi Stefano Valentini Silvio Dip. Informatica Dip. Mat. Pura ed Applicata Univ. Torino Univ. Padova c.so Svizzera

More information

System E: Expansion Variables for Flexible Typing with Linear and Non-linear Types and Intersection Types

System E: Expansion Variables for Flexible Typing with Linear and Non-linear Types and Intersection Types System E: Expansion Variables for Flexible Typing with Linear and Non-linear Types and Intersection Types Sébastien Carlier 1, Jeff Polakow 1, J.B. Wells 1, and A.J. Kfoury 2 1 Heriot-Watt University,

More information

ON FIRST-ORDER CONS-FREE TERM REWRITING AND PTIME

ON FIRST-ORDER CONS-FREE TERM REWRITING AND PTIME ON FIRST-ORDER CONS-FREE TERM REWRITING AND PTIME CYNTHIA KOP Department of Computer Science, Copenhagen University e-mail address: kop@diku.dk Abstract. In this paper, we prove that (first-order) cons-free

More information

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach EDA045F: Program Analysis LECTURE 10: TYPES 1 Christoph Reichenbach In the last lecture... Performance Counters Challenges in Dynamic Performance Analysis Taint Analysis Binary Instrumentation 2 / 44 Types

More information

Programming Languages and Types

Programming Languages and Types Programming Languages and Types Klaus Ostermann based on slides by Benjamin C. Pierce Subtyping Motivation With our usual typing rule for applications the term is not well typed. ` t 1 : T 11!T 12 ` t

More information

Partial Collapses of the Σ 1 Complexity Hierarchy in Models for Fragments of Bounded Arithmetic

Partial Collapses of the Σ 1 Complexity Hierarchy in Models for Fragments of Bounded Arithmetic Partial Collapses of the Σ 1 Complexity Hierarchy in Models for Fragments of Bounded Arithmetic Zofia Adamowicz Institute of Mathematics, Polish Academy of Sciences Śniadeckich 8, 00-950 Warszawa, Poland

More information

Beyond First-Order Logic

Beyond First-Order Logic Beyond First-Order Logic Software Formal Verification Maria João Frade Departmento de Informática Universidade do Minho 2008/2009 Maria João Frade (DI-UM) Beyond First-Order Logic MFES 2008/09 1 / 37 FOL

More information

Programming Languages Fall 2013

Programming Languages Fall 2013 Programming Languages Fall 2013 Lecture 11: Subtyping Prof Liang Huang huang@qccscunyedu Big Picture Part I: Fundamentals Functional Programming and Basic Haskell Proof by Induction and Structural Induction

More information

Realisability methods of proof and semantics with application to expansion

Realisability methods of proof and semantics with application to expansion Realisability methods of proof and semantics with application to expansion First Year Examination Supervisors : Professor Fairouz Kamareddine and Doctor Joe B. Wells Student : Vincent Rahli ULTRA group,

More information

Combined Satisfiability Modulo Parametric Theories

Combined Satisfiability Modulo Parametric Theories Intel 07 p.1/39 Combined Satisfiability Modulo Parametric Theories Sava Krstić*, Amit Goel*, Jim Grundy*, and Cesare Tinelli** *Strategic CAD Labs, Intel **The University of Iowa Intel 07 p.2/39 This Talk

More information

Propositional and Predicate Logic. jean/gbooks/logic.html

Propositional and Predicate Logic.   jean/gbooks/logic.html CMSC 630 February 10, 2009 1 Propositional and Predicate Logic Sources J. Gallier. Logic for Computer Science, John Wiley and Sons, Hoboken NJ, 1986. 2003 revised edition available on line at http://www.cis.upenn.edu/

More information

hal , version 1-21 Oct 2009

hal , version 1-21 Oct 2009 ON SKOLEMISING ZERMELO S SET THEORY ALEXANDRE MIQUEL Abstract. We give a Skolemised presentation of Zermelo s set theory (with notations for comprehension, powerset, etc.) and show that this presentation

More information

Code Generation for a Simple First-Order Prover

Code Generation for a Simple First-Order Prover Code Generation for a Simple First-Order Prover Jørgen Villadsen, Anders Schlichtkrull, and Andreas Halkjær From DTU Compute, Technical University of Denmark, 2800 Kongens Lyngby, Denmark Abstract. We

More information

Proof Theoretical Studies on Semilattice Relevant Logics

Proof Theoretical Studies on Semilattice Relevant Logics Proof Theoretical Studies on Semilattice Relevant Logics Ryo Kashima Department of Mathematical and Computing Sciences Tokyo Institute of Technology Ookayama, Meguro, Tokyo 152-8552, Japan. e-mail: kashima@is.titech.ac.jp

More information

Type Soundness for Path Polymorphism

Type Soundness for Path Polymorphism Type Soundness for Path Polymorphism Andrés Ezequiel Viso 1,2 joint work with Eduardo Bonelli 1,3 and Mauricio Ayala-Rincón 4 1 CONICET, Argentina 2 Departamento de Computación, FCEyN, UBA, Argentina 3

More information

Polymorphism, Subtyping, and Type Inference in MLsub

Polymorphism, Subtyping, and Type Inference in MLsub Polymorphism, Subtyping, and Type Inference in MLsub Stephen Dolan and Alan Mycroft November 8, 2016 Computer Laboratory University of Cambridge The select function select p v d = if (p v) then v else

More information

Lecture Notes on Data Abstraction

Lecture Notes on Data Abstraction Lecture Notes on Data Abstraction 15-814: Types and Programming Languages Frank Pfenning Lecture 14 October 23, 2018 1 Introduction Since we have moved from the pure λ-calculus to functional programming

More information

The Locally Nameless Representation

The Locally Nameless Representation Noname manuscript No. (will be inserted by the editor) The Locally Nameless Representation Arthur Charguéraud Received: date / Accepted: date Abstract This paper provides an introduction to the locally

More information

Call-by-value non-determinism in a linear logic type discipline

Call-by-value non-determinism in a linear logic type discipline Call-by-value non-determinism in a linear logic type discipline Alejandro Díaz-Caro? Giulio Manzonetto Université Paris-Ouest & INRIA LIPN, Université Paris 13 Michele Pagani LIPN, Université Paris 13

More information

Notes on Proving Arithmetic Equations

Notes on Proving Arithmetic Equations Massachusetts Institute of Technology Course Notes 1 6.844, Spring 03: Computability Theory of and with Scheme February 10 Prof. Albert Meyer revised February 25, 2003, 1300 minutes Notes on Proving Arithmetic

More information

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications NICTA Advanced Course Theorem Proving Principles, Techniques, Applications λ 1 CONTENT Intro & motivation, getting started with Isabelle Foundations & Principles Lambda Calculus Higher Order Logic, natural

More information

Functional Database Query Languages as. Typed Lambda Calculi of Fixed Order. Gerd G. Hillebrand and Paris C. Kanellakis

Functional Database Query Languages as. Typed Lambda Calculi of Fixed Order. Gerd G. Hillebrand and Paris C. Kanellakis Functional Database Query Languages as Typed Lambda Calculi of Fixed Order Gerd G. Hillebrand and Paris C. Kanellakis Department of Computer Science Brown University Providence, Rhode Island 02912 CS-94-26

More information

1 Introduction. 2 Recap The Typed λ-calculus λ. 3 Simple Data Structures

1 Introduction. 2 Recap The Typed λ-calculus λ. 3 Simple Data Structures CS 6110 S18 Lecture 21 Products, Sums, and Other Datatypes 1 Introduction In this lecture, we add constructs to the typed λ-calculus that allow working with more complicated data structures, such as pairs,

More information

Non-Idempotent Typing Operators, beyond the λ-calculus

Non-Idempotent Typing Operators, beyond the λ-calculus Non-Idempotent Typing Operators, beyond the λ-calculus Soutenance de thèse Pierre VIAL IRIF (Univ. Paris Diderot and CNRS) December 7, 2017 Non-idempotent typing operators P. Vial 0 1 /46 Certification

More information

On Typability for Rank-2 Intersection Types with Polymorphic Recursion

On Typability for Rank-2 Intersection Types with Polymorphic Recursion On Typability for Rank-2 Intersection Types with Polymorphic Recursion Tachio Terauchi Alex Aiken Electrical Engineering and Computer Sciences University of California at Berkeley Technical Report No.

More information

An extension of HM(X) with bounded existential and universal data-types

An extension of HM(X) with bounded existential and universal data-types Groupe de travail Cristal July, 2003 An extension of HM(X) with bounded existential and universal data-types (To appear at ICFP 03) Vincent Simonet INRIA Rocquencourt Cristal project Vincent.Simonet@inria.fr

More information

Type inference in context

Type inference in context Type inference in context Adam Gundry University of Strathclyde Microsoft Research PhD Scholar Conor McBride University of Strathclyde James McKinna Radboud University Nijmegen MSFP 25 September 2010 Two

More information

CS522 - Programming Language Semantics

CS522 - Programming Language Semantics 1 CS522 - Programming Language Semantics Simply Typed Lambda Calculus Grigore Roşu Department of Computer Science University of Illinois at Urbana-Champaign 2 We now discuss a non-trivial extension of

More information

COMP6463: λ-calculus

COMP6463: λ-calculus COMP6463: λ-calculus 1. Basics Michael Norrish Michael.Norrish@nicta.com.au Canberra Research Lab., NICTA Semester 2, 2015 Outline Introduction Lambda Calculus Terms Alpha Equivalence Substitution Dynamics

More information

Consequence Relations and Natural Deduction

Consequence Relations and Natural Deduction Consequence Relations and Natural Deduction Joshua D. Guttman Worcester Polytechnic Institute September 9, 2010 Contents 1 Consequence Relations 1 2 A Derivation System for Natural Deduction 3 3 Derivations

More information

Compositionality in SLD-derivations and their abstractions Marco Comini, Giorgio Levi and Maria Chiara Meo Dipartimento di Informatica, Universita di

Compositionality in SLD-derivations and their abstractions Marco Comini, Giorgio Levi and Maria Chiara Meo Dipartimento di Informatica, Universita di Compositionality in SLD-derivations and their abstractions Marco Comini Giorgio Levi and Maria Chiara Meo Dipartimento di Informatica Universita di Pisa Corso Italia 40 56125 Pisa Italy fcomini levi meog@di.unipi.it

More information

On the Complexity of the Reflected Logic of Proofs

On the Complexity of the Reflected Logic of Proofs On the Complexity of the Reflected Logic of Proofs Nikolai V. Krupski Department of Math. Logic and the Theory of Algorithms, Faculty of Mechanics and Mathematics, Moscow State University, Moscow 119899,

More information

Type Inference Algorithms

Type Inference Algorithms Type Inference Algorithms February 19, 2009 S. Saeidi Mobarakeh ( 0559938 ) Abstract In this paper we are going to describe the Wand s type inference algorithm and we ll try to extend this algorithm with

More information

Implementing -Reduction by. Hypergraph Rewriting. Sabine Kuske 1. Fachbereich Mathematik und Informatik. Universitat Bremen. D{28334 Bremen, Germany

Implementing -Reduction by. Hypergraph Rewriting. Sabine Kuske 1. Fachbereich Mathematik und Informatik. Universitat Bremen. D{28334 Bremen, Germany URL: http://www.elsevier.nl/locate/entcs/volume2.html 8 pages Implementing -Reduction by Hypergraph Rewriting abine Fachbereich Mathematik und Informatik Universitat Bremen D{28334 Bremen, Germany email:

More information

From Constructibility and Absoluteness to Computability and Domain Independence

From Constructibility and Absoluteness to Computability and Domain Independence From Constructibility and Absoluteness to Computability and Domain Independence Arnon Avron School of Computer Science Tel Aviv University, Tel Aviv 69978, Israel aa@math.tau.ac.il Abstract. Gödel s main

More information

The Curry-Howard Isomorphism

The Curry-Howard Isomorphism The Curry-Howard Isomorphism Software Formal Verification Maria João Frade Departmento de Informática Universidade do Minho 2008/2009 Maria João Frade (DI-UM) The Curry-Howard Isomorphism MFES 2008/09

More information

Principal Type Schemes for Functional Programs with Overloading and Subtyping

Principal Type Schemes for Functional Programs with Overloading and Subtyping Principal Type Schemes for Functional Programs with Overloading and Subtyping Geoffrey S. Smith Cornell University December 1994 Abstract We show how the Hindley/Milner polymorphic type system can be extended

More information

A proof of correctness for the Hindley-Milner type inference algorithm

A proof of correctness for the Hindley-Milner type inference algorithm A proof of correctness for the Hindley-Milner type inference algorithm Jeff Vaughan vaughan2@cis.upenn.edu May 5, 2005 (Revised July 23, 2008) 1 Introduction This report details a proof that the Hindley-Milner

More information

Categories, Proofs and Programs

Categories, Proofs and Programs Categories, Proofs and Programs Samson Abramsky and Nikos Tzevelekos Lecture 4: Curry-Howard Correspondence and Cartesian Closed Categories In A Nutshell Logic Computation 555555555555555555 5 Categories

More information

Partial model checking via abstract interpretation

Partial model checking via abstract interpretation Partial model checking via abstract interpretation N. De Francesco, G. Lettieri, L. Martini, G. Vaglini Università di Pisa, Dipartimento di Ingegneria dell Informazione, sez. Informatica, Via Diotisalvi

More information

A Subtyping for Extensible, Incomplete Objects

A Subtyping for Extensible, Incomplete Objects Fundamenta Informaticae XX (1999) 1 39 1 IOS Press A Subtyping for Extensible, Incomplete Objects To Helena Rasiowa: in memoriam Viviana Bono Dipartimento di Informatica Università di Torino C.so Svizzera

More information

Equational Reasoning in Algebraic Structures: a Complete Tactic

Equational Reasoning in Algebraic Structures: a Complete Tactic Equational Reasoning in Algebraic Structures: a Complete Tactic Luís Cruz-Filipe 1,2 and Freek Wiedijk 1 1 NIII, University of Nijmegen, Netherlands and 2 CLC, Lisbon, Portugal Abstract We present rational,

More information

3 Propositional Logic

3 Propositional Logic 3 Propositional Logic 3.1 Syntax 3.2 Semantics 3.3 Equivalence and Normal Forms 3.4 Proof Procedures 3.5 Properties Propositional Logic (25th October 2007) 1 3.1 Syntax Definition 3.0 An alphabet Σ consists

More information

Review. Principles of Programming Languages. Equality. The Diamond Property. The Church-Rosser Theorem. Corollaries. CSE 230: Winter 2007

Review. Principles of Programming Languages. Equality. The Diamond Property. The Church-Rosser Theorem. Corollaries. CSE 230: Winter 2007 CSE 230: Winter 2007 Principles of Programming Languages Lecture 12: The λ-calculus Ranjit Jhala UC San Diego Review The lambda calculus is a calculus of functions: e := x λx. e e 1 e 2 Several evaluation

More information

Symbolic Graphs for Attributed Graph Constraints

Symbolic Graphs for Attributed Graph Constraints Symbolic Graphs for Attributed Graph Constraints Fernando Orejas Dpt. L.S.I., Universitat Politècnica de Catalunya, Campus Nord, Mòdul Omega, Jordi Girona 1-3, 08034 Barcelona, Spain. Abstract In this

More information

Mathematics 114L Spring 2018 D.A. Martin. Mathematical Logic

Mathematics 114L Spring 2018 D.A. Martin. Mathematical Logic Mathematics 114L Spring 2018 D.A. Martin Mathematical Logic 1 First-Order Languages. Symbols. All first-order languages we consider will have the following symbols: (i) variables v 1, v 2, v 3,... ; (ii)

More information

Information Flow Inference for ML

Information Flow Inference for ML POPL 02 INRIA Rocquencourt Projet Cristal Francois.Pottier@inria.fr http://cristal.inria.fr/~fpottier/ Vincent.Simonet@inria.fr http://cristal.inria.fr/~simonet/ Information flow analysis account number

More information

Operationally-Based Theories of Program Equivalence

Operationally-Based Theories of Program Equivalence Operationally-Based Theories of Program Equivalence Andrew Pitts Contents 1 Introduction : : : : : : : : : : : : : : : : : : : : : : : : : : : : 241 2 Contextual Equivalence : : : : : : : : : : : : : :

More information

A More Direct Algorithm for Type Inference in the Rank-2 Fragment of the Second-Order λ-calculus

A More Direct Algorithm for Type Inference in the Rank-2 Fragment of the Second-Order λ-calculus A More Direct Algorithm for Type Inference in the Rank-2 Fragment of the Second-Order λ-calculus (Revised July 27, 2007) Brad Lushman University of Waterloo 200 University Ave. W. Waterloo, Ontario, Canada

More information

Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions

Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions Chapter 1 Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions 1.1 The IMP Language IMP is a programming language with an extensible syntax that was developed in the late 1960s. We will

More information

Introduction to Logic in Computer Science: Autumn 2006

Introduction to Logic in Computer Science: Autumn 2006 Introduction to Logic in Computer Science: Autumn 2006 Ulle Endriss Institute for Logic, Language and Computation University of Amsterdam Ulle Endriss 1 Plan for Today Today s class will be an introduction

More information

Predicate Logic. Xinyu Feng 09/26/2011. University of Science and Technology of China (USTC)

Predicate Logic. Xinyu Feng 09/26/2011. University of Science and Technology of China (USTC) University of Science and Technology of China (USTC) 09/26/2011 Overview Predicate logic over integer expressions: a language of logical assertions, for example x. x + 0 = x Why discuss predicate logic?

More information

Silvia Ghilezan and Jelena Ivetić

Silvia Ghilezan and Jelena Ivetić PUBLICATIONS DE L INSTITUT MATHÉMATIQUE Nouvelle série, tome 82(96) (2007), 85 91 DOI 102298/PIM0796085G INTERSECTION TYPES FOR λ Gtz -CALCULUS Silvia Ghilezan and Jelena Ivetić Abstract. We introduce

More information

Typing λ-terms. Types. Typed λ-terms. Base Types. The Typing Relation. Advanced Formal Methods. Lecture 3: Simply Typed Lambda calculus

Typing λ-terms. Types. Typed λ-terms. Base Types. The Typing Relation. Advanced Formal Methods. Lecture 3: Simply Typed Lambda calculus Course 2D1453, 200607 Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Some material from B. Pierce: TAPL + some from G. Klein, NICTA Typing λterms The uptyped λcalculus

More information

Clausal Presentation of Theories in Deduction Modulo

Clausal Presentation of Theories in Deduction Modulo Gao JH. Clausal presentation of theories in deduction modulo. JOURNAL OF COMPUTER SCIENCE AND TECHNOL- OGY 28(6): 1085 1096 Nov. 2013. DOI 10.1007/s11390-013-1399-0 Clausal Presentation of Theories in

More information

Limitations of OCAML records

Limitations of OCAML records Limitations of OCAML records The record types must be declared before they are used; a label e can belong to only one record type (otherwise fun x x.e) would have several incompatible types; we cannot

More information

The Complexity of Entailment Problems over Conditional Equality Constraints

The Complexity of Entailment Problems over Conditional Equality Constraints The Complexity of Entailment Problems over Conditional Equality Constraints Zhendong Su Department of Computer Science, University of California, Davis, CA 95616-8562 +1 530 7545376 (phone) +1 530 7524767

More information

The Minimal Graph Model of Lambda Calculus

The Minimal Graph Model of Lambda Calculus The Minimal Graph Model of Lambda Calculus Antonio Bucciarelli 1 and Antonino Salibra 2 1 Université Paris 7, Equipe PPS, 2 place Jussieu, 72251 Paris Cedex 05, France buccia@pps.jussieu.fr, 2 Università

More information

Operational reasoning for functions with local state

Operational reasoning for functions with local state Operational reasoning for functions with local state Andrew Pitts and Ian Stark Abstract Languages such as ML or Lisp permit the use of recursively defined function expressions with locally declared storage

More information

A Behavioural Model for Klop s Calculus

A Behavioural Model for Klop s Calculus Replace this file with prentcsmacro.sty for your meeting, or with entcsmacro.sty for your meeting. Both can be found at the ENTCS Macro Home Page. A Behavioural Model for Klop s Calculus Mariangiola Dezani-Ciancaglini

More information

Automatic Discovery of Covariant Read-Only Fields

Automatic Discovery of Covariant Read-Only Fields Automatic Discovery of Covariant Read-Only Fields Jens Palsberg Purdue University Tian Zhao Purdue University May 30, 2002 Trevor Jim AT&T Labs Research Abstract Read-only fields are useful in object calculi,

More information

Models of computation

Models of computation Lambda-Calculus (I) jean-jacques.levy@inria.fr 2nd Asian-Pacific Summer School on Formal ethods Tsinghua University, August 23, 2010 Plan computation models lambda-notation bound variables odels of computation

More information

Pairing Transitive Closure and Reduction to Efficiently Reason about Partially Ordered Events

Pairing Transitive Closure and Reduction to Efficiently Reason about Partially Ordered Events Pairing Transitive Closure and Reduction to Efficiently Reason about Partially Ordered Events Massimo Franceschet Angelo Montanari Dipartimento di Matematica e Informatica, Università di Udine Via delle

More information

Depending on equations

Depending on equations Depending on equations A proof-relevant framework for unification in dependent type theory Jesper Cockx DistriNet KU Leuven 3 September 2017 Unification for dependent types Unification is used for many

More information

Lambda-Calculus (I) 2nd Asian-Pacific Summer School on Formal Methods Tsinghua University, August 23, 2010

Lambda-Calculus (I) 2nd Asian-Pacific Summer School on Formal Methods Tsinghua University, August 23, 2010 Lambda-Calculus (I) jean-jacques.levy@inria.fr 2nd Asian-Pacific Summer School on Formal Methods Tsinghua University, August 23, 2010 Plan computation models lambda-notation bound variables conversion

More information

An Algebraic View of the Relation between Largest Common Subtrees and Smallest Common Supertrees

An Algebraic View of the Relation between Largest Common Subtrees and Smallest Common Supertrees An Algebraic View of the Relation between Largest Common Subtrees and Smallest Common Supertrees Francesc Rosselló 1, Gabriel Valiente 2 1 Department of Mathematics and Computer Science, Research Institute

More information

arxiv: v3 [cs.pl] 15 May 2011

arxiv: v3 [cs.pl] 15 May 2011 A Step-indexed Semantic Model of Types for the Call-by-Name Lambda Calculus arxiv:1105.1985v3 [cs.pl] 15 May 2011 Abstract Step-indexed semantic models of types were proposed as an alternative to purely

More information

Information Flow Inference for ML

Information Flow Inference for ML Information Flow Inference for ML Vincent Simonet INRIA Rocquencourt Projet Cristal MIMOSA September 27, 2001 Information flow account number bank applet order vendor account H order L bank H vendor L

More information

KRIPKE S THEORY OF TRUTH 1. INTRODUCTION

KRIPKE S THEORY OF TRUTH 1. INTRODUCTION KRIPKE S THEORY OF TRUTH RICHARD G HECK, JR 1. INTRODUCTION The purpose of this note is to give a simple, easily accessible proof of the existence of the minimal fixed point, and of various maximal fixed

More information

Context Free Grammars

Context Free Grammars Automata and Formal Languages Context Free Grammars Sipser pages 101-111 Lecture 11 Tim Sheard 1 Formal Languages 1. Context free languages provide a convenient notation for recursive description of languages.

More information

A Type-Coercion Problem in Computer Algebra

A Type-Coercion Problem in Computer Algebra Lecture Notes in Computer Science 737, pages 188 194 A Type-Coercion Problem in Computer Algebra Andreas Weber Wilhelm-Schickard-Institut Universität Tübingen W-7400 Tübingen, Germany hweber@informatik.uni-tuebingen.dei

More information

M ::= x M M x = M M :: M x :: x

M ::= x M M x = M M :: M x :: x Mini-ML expressions M ::= x variable true boolean values false if M then M else M conditional lx (M) function abstraction MM function application let x = M in M local declaration nil nil list M :: M list

More information

Type inference with structural subtyping: A faithful formalization of an efficient constraint solver

Type inference with structural subtyping: A faithful formalization of an efficient constraint solver Type inference with structural subtyping: A faithful formalization of an efficient constraint solver Vincent Simonet INRIA Rocquencourt Vincent.Simonet@inria.fr Abstract. We are interested in type inference

More information

3. Only sequences that were formed by using finitely many applications of rules 1 and 2, are propositional formulas.

3. Only sequences that were formed by using finitely many applications of rules 1 and 2, are propositional formulas. 1 Chapter 1 Propositional Logic Mathematical logic studies correct thinking, correct deductions of statements from other statements. Let us make it more precise. A fundamental property of a statement is

More information

Simply Typed Lambda Calculus

Simply Typed Lambda Calculus Simply Typed Lambda Calculus Language (ver1) Lambda calculus with boolean values t ::= x variable x : T.t abstraction tt application true false boolean values if ttt conditional expression Values v ::=

More information

Entailment with Conditional Equality Constraints (Extended Version)

Entailment with Conditional Equality Constraints (Extended Version) Entailment with Conditional Equality Constraints (Extended Version) Zhendong Su Alexander Aiken Report No. UCB/CSD-00-1113 October 2000 Computer Science Division (EECS) University of California Berkeley,

More information

HOW DO ULTRAFILTERS ACT ON THEORIES? THE CUT SPECTRUM AND TREETOPS

HOW DO ULTRAFILTERS ACT ON THEORIES? THE CUT SPECTRUM AND TREETOPS HOW DO ULTRAFILTERS ACT ON THEORIES? THE CUT SPECTRUM AND TREETOPS DIEGO ANDRES BEJARANO RAYO Abstract. We expand on and further explain the work by Malliaris and Shelah on the cofinality spectrum by doing

More information

Short Introduction to Admissible Recursion Theory

Short Introduction to Admissible Recursion Theory Short Introduction to Admissible Recursion Theory Rachael Alvir November 2016 1 Axioms of KP and Admissible Sets An admissible set is a transitive set A satisfying the axioms of Kripke-Platek Set Theory

More information

Subtyping and Intersection Types Revisited

Subtyping and Intersection Types Revisited Subtyping and Intersection Types Revisited Frank Pfenning Carnegie Mellon University International Conference on Functional Programming (ICFP 07) Freiburg, Germany, October 1-3, 2007 Joint work with Rowan

More information

On the Stable Model Semantics for Intensional Functions

On the Stable Model Semantics for Intensional Functions Under consideration for publication in Theory and Practice of Logic Programming 1 On the Stable Model Semantics for Intensional Functions Michael Bartholomew and Joohyung Lee School of Computing, Informatics,

More information

Interpolation via translations

Interpolation via translations Interpolation via translations Walter Carnielli 2,3 João Rasga 1,3 Cristina Sernadas 1,3 1 DM, IST, TU Lisbon, Portugal 2 CLE and IFCH, UNICAMP, Brazil 3 SQIG - Instituto de Telecomunicações, Portugal

More information

Lecture 1: The arithmetic hierarchy

Lecture 1: The arithmetic hierarchy MODEL THEORY OF ARITHMETIC Lecture 1: The arithmetic hierarchy Tin Lok Wong 8 October, 2014 [These theorems] go a long way to explaining why recursion theory is relevant to the study of models of arithmetic.

More information

2.5.2 Basic CNF/DNF Transformation

2.5.2 Basic CNF/DNF Transformation 2.5. NORMAL FORMS 39 On the other hand, checking the unsatisfiability of CNF formulas or the validity of DNF formulas is conp-complete. For any propositional formula φ there is an equivalent formula in

More information

TR : Binding Modalities

TR : Binding Modalities City University of New York (CUNY) CUNY Academic Works Computer Science Technical Reports Graduate Center 2012 TR-2012011: Binding Modalities Sergei N. Artemov Tatiana Yavorskaya (Sidon) Follow this and

More information

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65 Undecidable Problems Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, 2018 1/ 65 Algorithmically Solvable Problems Let us assume we have a problem P. If there is an algorithm solving

More information