# The Delta-calculus: syntax and types

We present the Delta-calculus, an explicitly typed lambda-calculus with strong pairs, projections and explicit type coercions. The calculus can be parametrized with different intersection type theories T, e.g. the Coppo-Dezani, the Coppo-Dezani-Salle', the Coppo-Dezani-Venneri and the Barendregt-Coppo-Dezani ones, producing a family of Delta-calculi with related intersection type systems. We prove the main properties like Church-Rosser, unicity of type, subject reduction, strong normalization, decidability of type checking and type reconstruction. We state the relationship between the intersection type assignment systems a la Curry and the corresponding intersection type systems a la Church by means of an essence function translating an explicitly typed Delta-term into a pure lambda-term one. We finally translate a Delta-term with type coercions into an equivalent one without them; the translation is proved to be coherent because its essence is the identity. The generic Delta-calculus can be parametrized to take into account other intersection type theories as the ones in the Barendregt et al. book.

Comments

There are no comments yet.

## Authors

• 3 publications
• 3 publications
07/12/2019

### Type Assignment for the Computational lambda-Calculus

We study polymorphic type assignment systems for untyped lambda-calculi ...
07/20/2019

### Factoring Derivation Spaces via Intersection Types (Extended Version)

In typical non-idempotent intersection type systems, proof normalization...
02/04/2020

### Intersection Type Distributors

Building on previous works, we present a general method to define proof ...
09/15/2020

### An Abstract Machine for Strong Call by Value

We present an abstract machine that implements a full-reducing (a.k.a. s...
10/13/2020

### Resolution as Intersection Subtyping via Modus Ponens

Resolution and subtyping are two common mechanisms in programming langua...
02/25/2020

### A Type Checker for a Logical Framework with Union and Intersection Types

We present the syntax, semantics, and typing rules of Bull, a prototype ...
05/05/2021

### Uniqueness typing for intersection types

Working in a variant of the intersection type assignment system of Coppo...
##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1 Introduction

Intersection type theories were first introduced as a form of ad hoc polymorphism in (pure) -calculi à la Curry. The paper by Barendregt, Coppo, and Dezani [4] is a classic reference, while [5] is a definitive reference.

Intersection type assignment systems have been well-known in the literature for almost 40 years for many reasons: among them, characterization of strongly normalizing -terms [5], -models [1], automatic type inference [26], type inhabitation [43, 37], type unification [17]. As intersection had its classical development for type assignment systems, many papers tried to find an explicitly typed -calculus à la Church corresponding to the original intersection type assignment systems à la Curry. The programming language Forsythe, by Reynolds [38]

, is probably the first reference, while Pierce’s Ph.D. thesis

[33] combines also unions, intersections and bounded polymorphism. In [45] intersection types were used as a foundation for typed intermediate languages for optimizing compilers for higher-order polymorphic programming languages; implementations of typed programming language featuring intersection (and union) types can be found in SML-CIDRE [14] and in StardustML [18, 19].

Annotating pure -terms with intersection types is not simple: a classical example is the difficulty to decorate the bound variable of the explicitly typed polymorphic identity such that the type of the identity is : previous attempts showed that the full power of the intersection type discipline can be easily lost.

In this paper, we define and prove the main properties of the -calculus, a generic intersection typed system for an explicitly typed -calculus à la Church enriched with strong pairs, denoted by , projections, denoted by , and type coercions, denoted by .

A strong pair is a special kind of cartesian product such that the two parts of a pair satisfies a given property on their “essence”, that is .

An essence of a -term is a pure -term obtained by erasing type decorations, projections and choosing one of the two elements inside a strong pair. As examples,

 ≀⟨λx:σ∩τ.pr2x,λx:σ∩τ.pr1x⟩≀ = λx.x ≀λx:(σ→τ)∩σ.(pr1x)(pr2x)≀ = λx.x\andx ≀λx:σ∩(τ∩ρ).⟨⟨pr1x,pr2pr1x⟩,pr2pr2x⟩≀ = λx.x

and so on. Therefore, the essence of a -term is its untyped skeleton: a strong pair can be typechecked if and only if is verified, otherwise the strong pair will be ill-typed. The essence also gives the exact mapping between a term and its typing à la Church and its corresponding term and type assignment à la Curry. Changing the parameters and results in defining a totally different intersection typed system. For the purpose of this paper, we study the four well-known intersection type theories , namely Coppo-Dezani [11], Coppo-Dezani-Sallé [12], Coppo-Dezani-Venneri [13] and Barendregt-Coppo-Dezani [4]. We will inspect the above type theories using three equivalence relations on pure -terms, namely and .

The combination of the above and allows to define ten meaningful typed systems for the -calculus that can be pictorially displayed in a “-chair” (see Definition 2.2). Following the same style as in the Barendrengt et al. book [5], the edges in the chair represent an inclusion relation over the set of derivable judgments.

A type coercion is a term of type whose type-decoration denotes an application of a subsumption rule to the term of type such that : if we omit type coercions, then we lose the uniqueness of type property.

Section 3 shows a number of typable examples in the systems presented in the -chair: each example is provided with a corresponding type assignment derivation of its essence. Some historical examples of Pottinger [36], Hindley [23] and Ben-Yelles [6] are essentially re-decorated and inhabited (when possible) in the -calculus. The aims of this section is both to make the reader comfortable with the different intersection typed systems, and to give a first intuition of the correspondence between Church-style and Curry-style calculi.

Section 4 proves the metatheory for all the systems in the -chair: Church-Rosser, unicity of type, subject reduction, strong normalization, decidability of type checking and type reconstruction and studies the relations between intersection type assignment systems à la Curry and the corresponding intersection typed systems à la Church. Notions of soundness, completeness and isomorphism will relate type assignment and typed systems. We also show how to get rid of type coercions defining a translation function, denoted by , inspired by the one of Tannen et al. [42]: the intuition of the translation is that if has type and , then is a -term of type , has type and is the identity .

### 1.1 λ-calculi with intersection types à la Church

Several calculi à la Church appeared in the literature: they capture the power of intersection types; we briefly review them.

The Forsythe programming language by Reynolds [38] annotates a -abstraction with types as in . However, we cannot type a typed term, whose type erasure is the combinator , with the type .

Pierce [34] improves Forsythe by using a for construct to build ad hoc polymorphic typing, as in . However, we cannot type a typed term, whose type erasure is , with the type

Freeman and Pfenning [20] introduced refinement types, that is types that allow ad hoc

polymorphism for ML constructors. Intuitively, refinement types can be seen as subtypes of a standard type: the user first defines a type and then the refinement types of this type. The main motivation for these refinement types is to allow non-exhaustive pattern matching, which becomes exhaustive for a given refinement of the type of the argument. As an example, we can define a type

boolexp for boolean expressions, with constructors True, And, Not and Var, and a refinement type ground for boolean expressions without variables, with the same constructors except Var: then, the constructor True has type , the constructor And has type and so on. However, intersection is meaningful only when using constructors.

Wells et al. [45] introduced , a typed intermediate -calculus for optimizing compilers for higher-order programming languages. The calculus features intersection, union and flow types, the latter being useful to optimize data representation. can faithfully encode an intersection type assignment derivation by introducing the concept of virtual tuple, i.e. a special kind of pair whose type erasure leads to exactly the same untyped -term. A parallel context and parallel substitution, similar to the notion of [27, 28], is defined to reduce expressions in parallel inside a virtual tuple. Subtyping is defined only on flow types and not on intersection types: this system can encode the type assignment system.

Wells and Haak [46] introduced , a more compact typed calculus encoding of : in fact, by comparing Fig. 1 and Fig. 2 of [46] we can see that the set of typable terms with intersection types of and are the same. In that paper, virtual tuples are removed by introducing branching terms, typable with branching types, the latter representing intersection type schemes. Two operations on types and terms are defined, namely expand, expanding the branching shape of type annotations when a term is substituted into a new context, and select, to choose the correct branch in terms and types. As there are no virtual tuples, reductions do not need to be done in parallel. As in [45], the type assignment system can be encoded.

Frisch et al. [21] designed a typed system with intersection, union, negation and recursive types. The authors inherit the usual problem of having a domain space that contains all the terms and, at the same time, all the functions from to . They prevent this by having an auxiliary domain space which is the disjoint union of and . The authors interpret types as sets in a well-suited model where the set-inspired type constructs are interpreted as the corresponding to set-theoretical constructs. Moreover, the model manages higher-order functions in an elegant way. The subtyping relation is defined as a relation on the set-theoretical interpretation of the types. For instance, the problem will be interpreted as , where becomes the set intersection operator, and the decision program actually decides whether is the empty set.

Bono et al. [7] introduced a relevant and strict parallel term constructor to build inhabitants of intersections and a simple call-by-value parallel reduction strategy. An infinite number of constants is applied to typed variables such that is upcasted to type . It also uses a local renaming typing rule, which changes type decoration in -abstractions, as well as coercions. Term synchronicity in the tuples is guaranteed by the typing rules. The calculus uses van Bakel’s strict version [2] of the intersection type theory.

### 1.2 Logics for intersection types

Proof-functional (or strong) logical connectives, introduced by Pottinger [36], take into account the shape of logical proofs, thus allowing for polymorphic features of proofs to be made explicit in formulæ. This differs from classical or intuitionistic connectives where the meaning of a compound formula is only dependent on the truth value or the provability of its subformulæ.

Pottinger was the first to consider the intersection as a proof-functional connective. He contrasted it to the intuitionistic connective as follows: “The intuitive meaning of can be explained by saying that to assert is to assert that one has a reason for asserting which is also a reason for asserting , while to assert is to assert that one has a pair of reasons, the first of which is a reason for asserting and the second of which is a reason for asserting .

A simple example of a logical theorem involving intuitionistic conjunction which does not hold for proof-functional conjunction is . Otherwise there would exist a term which behaves both as and as . Later, Lopez-Escobar [30] and Mints [31] investigated extensively logics featuring both proof-functional and intuitionistic connectives especially in the context of realizability interpretations.

It is not immediate to extend the judgments-as-types Curry-Howard paradigm to logics supporting proof-functional connectives. These connectives need to compare the shapes of derivations and do not just take into account their provability, i.e. the inhabitation of the corresponding type.

There are many proposals to find a suitable logics to fit intersection types; among them we cite [44, 39, 32, 9, 7, 35], and previous papers by the authors [15, 29, 40].

### 1.3 Raising the Δ-calculus to a Δ-framework.

Our goal is to build a prototype of a theorem prover based on the -calculus and proof-functional logic. Recently [25], we have extended a subset of the generic -calculus with other proof-functional operators like union types, relevant arrow types, together with dependent types as in the Edinburgh Logical Framework [22]: a preliminary implementation of a type checker appeared in [40] by the authors. In a nutshell:

Strong disjunction is a proof-functional connective that can be interpreted as the union type [15, 40]: it contrasts with the intuitionistic connective . As Pottinger did for intersection, we could say that asserting is to assert that one has a reason for , which is also a reason to assert and . A simple example of a logical theorem involving intuitionistic disjunction which does not hold for strong disjunction is . Otherwise there would exist a term which behaves both as and as .

Strong (relevant) implication is yet another proof-functional connective that was interpreted in [3] as a relevant arrow type . As explained in [3], it can be viewed as a special case of implication whose related function space is the simplest one, namely the one containing only the identity function. Because the operators and differ, is not derivable.

Dependent types, as introduced in the Edinburgh Logical Framework [22] by Harper et al., allows considering proofs as first-class citizens albeit differently with respect to proof-functional logics. The interaction of both dependent and proof-functional operators is intriguing: the former mentions proofs explicitly, while the latter mentions proofs implicitly. Their combination therefore opens up new possibilities of formal reasoning on proof-theoretic semantics.

## 2 Syntax, Reduction and Types

[Type atoms, type syntax, type theories and type assignment systems] We briefly review some basic definition from Subsection 13.1 of [5], in order to define type assignment systems. The set of atoms, intersection types, intersection type theories and intersection type assignment systems are defined as follows:

1. (Atoms). Let denote a set of symbols which we will call type atoms, and let be a special type atom denoting the universal type. In particular, we will use with being different from and .

2. (Syntax). The syntax of intersection types, parametrized by , is: .

3. (Intersection type theories ). An intersection type theory is a set of sentences of the form satisfying at least the axioms and rules of the minimal type theory defined in Figure 1. The type theories , and are the smallest type theories over satisfying the axioms and rules given in Figure 3. We write if, for all such that , we have that . In particular and . We will sometime note, for instance, instead of .

4. (Intersection type assignment systems ). We define in Figure 2444Although rules are derivable with , we add them for clarity. an infinite collection of type assignment systems parametrized by a set of atoms and a type theory . We name four particular type assignment systems in the table below, which is an excerpt from Figure 13.4 of [5]. denotes a derivable type assignment judgment in the type assignment system . Type checking is not decidable for , , , and .

### 2.1 The Δ-calculi

Intersection type assignment systems and -calculi have in common their type syntax and intersection type theories. The generic syntax of the -calculus is defined as follows. [Generic -calculus syntax]

 Δ::=uΔ∣x∣λx:σ.Δ∣Δ\andΔ∣⟨Δ,Δ⟩∣priΔ∣Δσi∈{1,2}

denotes an infinite set of constants, indexed with a particular untyped -term. denotes an explicit coercion of to type . The expression denotes a pair that, following the Lopez-Escobar jargon [30], we call “strong pair” with respective projections and . The essence function is an erasing function mapping typed -terms into pure -terms. It is defined as follows.

[Essence function]

 ≀x≀def=x≀Δσ≀def=≀Δ≀≀uΔ≀def=≀Δ≀≀λx:σ.Δ≀def=λx.≀Δ≀≀Δ1\andΔ2≀def=≀Δ1≀\and≀Δ2≀≀⟨Δ1,Δ2⟩≀def=≀Δ1≀≀priΔ≀def=≀Δ≀i∈{1,2}

One could argue that the choice of is arbitrary and could have been replaced with . However, the typing rules will ensure that, if is typable, then, for some suitable equivalence relation , we have that . Thus, strong pairs can be viewed as constrained cartesian products. The generic reduction semantics reduces terms of the -calculus as follows. [Generic reduction semantics] Syntactical equality is denoted by .

1. (Substitution) Substitution on -terms is defined as usual, with the additional rules:

 uΔ1[Δ2/x]def=u(Δ1[Δ2/x])andΔσ1[Δ2/x]def=(Δ1[Δ2/x])σ
2. (One-step reduction). We define three notions of reduction:

 (λx:σ.Δ1)\andΔ2⟶Δ1[Δ2/x](β)pri⟨Δ1,Δ2⟩⟶Δii∈{1,2}(pri)λx:σ.Δ\andx⟶Δx∉FV(Δ)(η)

Observe that is not a redex, because the -abstraction is coerced. The contextual closure is defined as usual except for reductions inside the index of that are forbidden (even though substitutions are propagated). We write for the contextual closure of the and notions of reduction, for the contextual closure of . We also define a synchronous contextual closure, which is like the usual contextual closure except for the strong pairs, as defined in point . Synchronous contextual closure of the notions of reduction generates the reduction relations and .

3. (Synchronous closure of ). Synchronous closure is defined on the strong pairs with the following constraint:

Note that we reduce in the two components of the strong pair;

4. (Multistep reduction). We write (resp. ) as the reflexive and transitive closure of (resp. );

5. (Congruence). We write as the symmetric, reflexive, transitive closure of .

We mostly consider -reductions, thus to ease the notation we omit the subscript in -reductions.

The next definition introduces a notion of synchronization inside strong pairs. [Synchronization] A -term is synchronous if and only if, for all its subterms of the shape , we have that .

It is easy to verify that preserves synchronization, while it is not the case for . The next definition introduces a generic intersection typed system for the -calculus that is parametrizable by suitable equivalence relations on pure -terms and type theories as follows.

[Generic intersection typed system] The generic intersection typed system is defined in Figure 4. We denote by a particular typed system with the type theory and under an equivalence relation and by a corresponding typing judgment. The typing rules are intuitive for a calculus à la Church except rules , and .

The typing rule for a strong pair is similar to the typing rule for a cartesian product, except for the side-condition , forcing the two parts of the strong pair to have essences compatible under , thus making a strong pair a special case of a cartesian pair. For instance, is not typable in ; is not typable in but it is in ; is not typable in nor but it is in . In the typing rule , the subscript in is not necessarily typable so can easily be any arbitrary -term. The typing rule allows to change the type of a -term from to if : the term in the conclusion must record this change with an explicit type coercion , producing the new term : explicit type coercions are important to keep the unicity of typing derivations.

The next definition introduces a partial order over equivalence relations on pure -terms and an inclusion over typed systems as follows.

[ and ]

1. Let . if, for all pure -terms such that , we have that ;

2. if and , then .

1. and ;

2. if and .

### 2.2 The Δ-chair

The next definition classifies ten typed systems for the

-calculus: some of them already appeared (sometime with a different notation) in the literature by the present authors.

[-chair]
Ten typed systems can be drawn pictorially in a -chair, where the arrows represent an inclusion relation. corresponds roughly to [27, 28] (in the expression , is the essence of ) and in its intersection part to [40]; corresponds roughly in its intersection part to [16], corresponds in its intersection part to [29], corresponds in its intersection part to [15]. The other typed systems are basically new. The main properties of these systems are: All the systems enjoys the synchronous subject reduction property, the other systems also enjoy ordinary subject reduction (Th. 4.1); All the systems strongly normalize (Th. 4.2); All the systems correspond to the to original type assignment systems except , , and (Th. 5); Type checking and type reconstruction are decidable for all the systems, except , , and (Th. 5).

## 3 Examples

This section shows examples of typed derivations and highlights the corresponding type assignment judgment in they correspond to, in the sense that we have a derivation and another derivation . The correspondence between intersection typed systems and intersection type assignment will be defined in Subsection 5.1.

[Polymorphic identity] In all of the intersection type assignment systems we can derive A corresponding -term is: that can be typed in all of the typed systems of the -chair as follows

[Auto application] In all of the intersection type assignment systems we can derive A corresponding -term is: that can be typed in all of the typed systems of the -chair as follows

[Some examples in ] In we can derive , and using this type assignment, we can derive . A corresponding -term is: that can be typed in as follows

As another example, we can also derive . A corresponding -term is: that can be typed in as follows

[An example in ] In we can prove the commutativity of intersection, i.e. A corresponding -term is: that can be typed in as follows

where is .

[Another polymorphic identity in ] In all the you can type this -term: The typing derivation is thus

[Two examples in and ] In we can can type any term, including the non-terminating term More precisely, we have: A corresponding -term whose essence is is: that can be typed in as follows

where is

In we can type A corresponding -term whose essence is is: that can be typed in as follows

Note that the condition has an interesting loophole, as it is well-known that does not enjoy -conversion property. Theorem B.1(1) will show that we can construct a -term which does not correspond to any derivation.

[Pottinger] The following examples can be typed in all the type theories of the -chair (we also display in square brackets the corresponding pure -terms typable in ). These are encodings from the examples à la Curry given by Pottinger in [36].

 [λx.λy.x\andy]⊢TRλx:(σ→τ)∩(σ→ρ).λy:σ.⟨(pr1x)\andy),(pr2x)\andy⟩:(σ→τ)∩(σ→ρ)→σ→τ∩ρ[λx.λy.x\andy]⊢TRλx:σ→τ∩ρ.⟨λy:σ.pr1(x\andy),λy:σ.pr2(x\andy)⟩:(σ→τ∩ρ)→(σ→τ)∩(σ→ρ)[λx.λy.x\andy]⊢TRλx:σ→ρ.λy:σ∩τ.x\and(pr1y):(σ→ρ)→σ∩τ→ρ[λx.λy.x]⊢TRλx:σ∩τ.λy:σ.pr2x:σ∩τ→σ→τ[λx.λy.x\andy\andy]⊢TRλx:σ→τ→ρ.λy:σ∩τ.x\and(pr1y)\and(pr2y):(σ→τ→ρ)→σ∩τ→ρ[λx.x]⊢TRλx:σ∩τ.pr1x:σ∩τ→σ[λx.x]⊢TRλx:σ.⟨x,x⟩:σ→σ∩σ[λx.x]⊢TRλx:σ∩(τ∩ρ).⟨⟨pr1x,pr1pr2x⟩,pr2pr2x⟩:σ∩(τ∩ρ)→(σ∩τ)∩ρ

In the same paper, Pottinger lists some types that cannot be inhabited by any intersection type assignment () in an empty context, namely: . It is not difficult to verify that the above types cannot be inhabited by any of the type systems of the -chair because of the failure of the essence condition in the strong pair type rule.

[Intersection is not the conjunction operator] This counter-example is from the corresponding counter-example à la Curry given by Hindley [24] and Ben-Yelles [6]. The intersection type where the left part of the intersection corresponds to the type for the combinator I and the right part for the combinator S cannot be assigned to a pure -term. Analogously, the same intersection type cannot be assigned to any -term.

### 3.1 On synchronization and subject reduction

For the typed systems , strong pairs have an intrinsic notion of synchronization: some redexes need to be reduced in a synchronous fashion unless we want to create meaningless -terms that cannot be typed. Consider the -term . If we use the reduction relation, then the following reduction paths are legal
More precisely, the first and second redexes are rewritten asynchronously, thus they cannot be typed in any typed system , because we fail to check the left and the right part of the strong pair to be the same: the reduction relation prevents this loophole and allows to type all redexes. In summary, can be thought of as the natural reduction relation for the typed systems .

## 4 Metatheory of ΔTR

### 4.1 General properties

Unless specified, all properties applies to the intersection typed systems . For lack of space all proofs are omitted: the interested reader can found more technical details in the Appendix. The Church-Rosser property is proved using the technique of Takahashi [41]. The parallel reduction semantics extends Definition 2.1 and it is inductively defined as follows. [Parallel reduction semantics]

 x⟹x\omit\span\omitanduΔ⟹uΔΔσ⟹(Δ′)σ if% Δ⟹Δ′Δ1\andΔ2⟹Δ′1\andΔ′2 if Δ1⟹Δ′1 and Δ2⟹Δ′2λx:σ.Δ⟹λx:σ.Δ′ if Δ⟹Δ′(λx:σ.Δ1)\andΔ2⟹Δ′1[Δ′2/x] if Δ1⟹Δ′1 and Δ2⟹Δ′2⟨Δ1,Δ2⟩⟹⟨Δ′1,Δ′2⟩ if Δ1⟹Δ′1 and Δ2⟹Δ′2priΔ⟹priΔ′%ifΔ⟹Δ′ and i∈{1,2}pri⟨Δ1,Δ2⟩⟹Δ′i if Δi⟹Δ′i and i∈{1,2}

Intuitively, means that is obtained from by simultaneous contraction of some -redexes possibly overlapping each other. Church-Rosser can be achieved by proving a stronger statement, namely where is a -term determined by and independent from . The statement (1) is satisfied by the term which is obtained from by contracting all the redexes existing in simultaneously.

[The map ]

 x∗def=xu∗Δdef=uΔ(Δσ)∗def=(Δ∗)σ⟨Δ1,Δ2⟩∗def=⟨Δ∗1,Δ∗2⟩(λx:σ.Δ)∗def=λx:σ.Δ∗((λx:σ.Δ1)\andΔ2)∗def=Δ∗1[Δ∗2/x](Δ1\andΔ2)∗def=Δ∗1\andΔ∗2\omit\span\omit\span\omitif Δ1\andΔ2 is not a β-redex(λx:σ.Δ\andx)∗def=Δ∗\omit\span\omit\span\omitif x∉fv(Δ)(priΔ)∗def=priΔ∗\omit\span\omit\span\omitif Δ is not a strong pair

Now we have to prove the Church-Rosser property for the parallel reduction. [Confluence property for ] If , then .

The Church-Rosser property follows. [Confluence] If and , then there exists such that and .

The next lemma says that all type derivations for have an unique type. [Unicity of typing] If , then is unique. The next theorem states that all the typed systems preserve synchronous -reduction, and all the and typed systems preserve