In mathematical logic, the intersection type discipline is a branch of type theory encompassing type systems that use the intersection type constructor ( ∩ ) {\displaystyle (\cap )} to assign multiple types to a single term.[1] In particular, if a term M {\displaystyle M} can be assigned both the type φ 1 {\displaystyle \varphi _{1}} and the type φ 2 {\displaystyle \varphi _{2}} , then M {\displaystyle M} can be assigned the intersection type φ 1 ∩ φ 2 {\displaystyle \varphi _{1}\cap \varphi _{2}} (and vice versa). Therefore, the intersection type constructor can be used to express finite heterogeneous ad hoc polymorphism (as opposed to parametric polymorphism). For example, the λ-term λ x . ( x x ) {\displaystyle \lambda x.\!(x\;x)} can be assigned the type ( ( α → β ) ∩ α ) → β {\displaystyle ((\alpha \to \beta )\cap \alpha )\to \beta } in most intersection type systems, assuming for the term variable x {\displaystyle x} both the function type α → β {\displaystyle \alpha \to \beta } and the corresponding argument type α {\displaystyle \alpha } .
Prominent intersection type systems include the Coppo–Dezani type assignment system,[2] the Barendregt-Coppo–Dezani type assignment system,[3] and the essential intersection type assignment system.[4] Most strikingly, intersection type systems are closely related to (and often exactly characterize) normalization properties of λ-terms under β-reduction.
In programming languages, such as TypeScript[5] and Scala,[6] intersection types are used to express ad hoc polymorphism.
The intersection type discipline was pioneered by Mario Coppo, Mariangiola Dezani-Ciancaglini, Patrick Sallé, and Garrel Pottinger.[2][7][8] The underlying motivation was to study semantic properties (such as normalization) of the λ-calculus by means of type theory.[9] While the initial work by Coppo and Dezani established a type theoretic characterization of strong normalization for the λI-calculus,[2] Pottinger extended this characterization to the λK-calculus.[7] In addition, Sallé contributed the notion of the universal type ω {\displaystyle \omega } that can be assigned to any λ-term, thereby corresponding to the empty intersection.[8] Using the universal type ω {\displaystyle \omega } allowed for a fine-grained analysis of head normalization, normalization, and strong normalization.[10] In collaboration with Henk Barendregt, a filter λ-model for an intersection type system was given, tying intersection types ever more closely to λ-calculus semantics.
Due to the correspondence with normalization, typability in prominent intersection type systems (excluding the universal type) is undecidable. Complementarily, undecidability of the dual problem of type inhabitation in prominent intersection type systems was proven by Paweł Urzyczyn.[11] Later, this result was refined showing exponential space completeness of rank 2 intersection type inhabitation and undecidability of rank 3 intersection type inhabitation.[12] Remarkably, principal type inhabitation is decidable in polynomial time.[13]
The Coppo–Dezani type assignment system ( ⊢ CD ) {\displaystyle (\vdash _{\text{CD}})} extends the simply typed λ-calculus by allowing multiple types to be assumed for a term variable.[2]
The term language of ( ⊢ CD ) {\displaystyle (\vdash _{\text{CD}})} is given by λ-terms (or, lambda expressions):
The type language of ( ⊢ CD ) {\displaystyle (\vdash _{\text{CD}})} is inductively defined by the following grammar:
The intersection type constructor ( ∩ {\displaystyle \cap } ) is taken modulo associativity, commutativity and idempotence.
The typing rules ( → I ) {\displaystyle (\to \!\!{\text{I}})} , ( → E ) {\displaystyle (\to \!\!{\text{E}})} , ( ∩ I ) {\displaystyle (\cap {\text{I}})} , and ( ∩ E ) {\displaystyle (\cap {\text{E}})} of ( ⊢ CD ) {\displaystyle (\vdash _{\text{CD}})} are:
Typability and normalization are closely related in ( ⊢ CD ) {\displaystyle (\vdash _{\text{CD}})} by the following properties:[2]
If the type language is extended to contain the empty intersection, i.e. σ = φ 1 ∩ ⋯ ∩ φ n where n = 0 {\displaystyle \sigma =\varphi _{1}\cap \cdots \cap \varphi _{n}{\text{ where }}n=0} , then ( ⊢ CD ) {\displaystyle (\vdash _{\text{CD}})} is closed under β-equality and is sound and complete for inference semantics.[14]
The Barendregt–Coppo–Dezani type assignment system ( ⊢ BCD ) {\displaystyle (\vdash _{\text{BCD}})} extends the Coppo–Dezani type assignment system in the following three aspects:[3]
The term language of ( ⊢ BCD ) {\displaystyle (\vdash _{\text{BCD}})} is given by λ-terms (or, lambda expressions):
The type language of ( ⊢ BCD ) {\displaystyle (\vdash _{\text{BCD}})} is inductively defined by the following grammar:
Intersection type subtyping ( ≤ ) {\displaystyle (\leq )} is defined as the smallest preorder (reflexive and transitive relation) over intersection types satisfying the following properties:
Intersection type subtyping is decidable in quadratic time.[15]
The typing rules ( → I ) {\displaystyle (\to \!\!{\text{I}})} , ( → E ) {\displaystyle (\to \!\!{\text{E}})} , ( ∩ I ) {\displaystyle (\cap {\text{I}})} , ( ≤ ) {\displaystyle (\leq )} , ( A ) {\displaystyle ({\text{A}})} , and ( ω ) {\displaystyle (\omega )} of ( ⊢ BCD ) {\displaystyle (\vdash _{\text{BCD}})} are: