Intersection type discipline explained

In mathematical logic, the intersection type discipline is a branch of type theory encompassing type systems that use the intersection type constructor

(\cap)

to assign multiple types to a single term.In particular, if a term

M

can be assigned both the type

\varphi1

and the type

\varphi2

, then

M

can be assigned the intersection type

\varphi1\cap\varphi2

(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.(xx)

can be assigned the type

((\alpha\to\beta)\cap\alpha)\to\beta

in most intersection type systems, assuming for the term variable

x

both the function type

\alpha\to\beta

and the corresponding argument type

\alpha

.

Prominent intersection type systems include the Coppo–Dezani type assignment system, the Barendregt-Coppo–Dezani type assignment system, and the essential intersection type assignment system.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[1] and Scala,[2] intersection types are used to express ad hoc polymorphism.

History

The intersection type discipline was pioneered by Mario Coppo, Mariangiola Dezani-Ciancaglini, Patrick Sallé, and Garrel Pottinger.The underlying motivation was to study semantic properties (such as normalization) of the λ-calculus by means of type theory.While the initial work by Coppo and Dezani established a type theoretic characterization of strong normalization for the λI-calculus, Pottinger extended this characterization to the λK-calculus.In addition, Sallé contributed the notion of the universal type

\omega

that can be assigned to any λ-term, thereby corresponding to the empty intersection.Using the universal type

\omega

allowed for a fine-grained analysis of head normalization, normalization, and strong normalization.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.Later, this result was refined showing exponential space completeness of rank 2 intersection type inhabitation and undecidability of rank 3 intersection type inhabitation.Remarkably, principal type inhabitation is decidable in polynomial time.

Coppo–Dezani type assignment system

The Coppo–Dezani type assignment system

(\vdashCD)

extends the simply typed λ-calculus by allowing multiple types to be assumed for a term variable.

Term language

The term language of

(\vdashCD)

is given by λ-terms (or, lambda expressions):

\begin{align} M,N&::=x\mid(λx.M)\mid(MN)&&wherexrangesovertermvariables\\ \end{align}

Type language

The type language of

(\vdashCD)

is inductively defined by the following grammar:

\begin{align} \varphi&::=\alpha\mid\sigma\to\varphi&&where\alpharangesovertypevariables\\ \sigma&::=\varphi1\cap\cap\varphin&&wheren\geq1 \end{align}

The intersection type constructor (

\cap

) is taken modulo associativity, commutativity and idempotence.

Typing rules

The typing rules

(\toI)

,

(\toE)

,

(\capI)

, and

(\capE)

of

(\vdashCD)

are:

\begin{array}{cc} \dfrac{\Gamma,x:\sigma\vdashCDM:\varphi}{\Gamma\vdashCDλx.M:\sigma\to\varphi}(\toI) &\dfrac{\Gamma\vdashCDM:\sigma\to\varphi\Gamma\vdashCDN:\sigma}{\Gamma\vdashCDMN:\varphi}(\toE)\\\\ \dfrac{\Gamma\vdashCDM:\varphi1\ldots\Gamma\vdashCDM:\varphin}{\Gamma\vdashCDM:\varphi1\cap\cap\varphin}(\capI) &\dfrac{(1\leqi\leqn)}{\Gamma,x:\varphi1\cap\cap\varphin\vdashCDx:\varphii}(\capE) \end{array}

Properties

Typability and normalization are closely related in

(\vdashCD)

by the following properties:

\Gamma\vdashCDM:\sigma

and

M\to\betaN

, then

\Gamma\vdashCDN:\sigma

.

\Gamma\vdashCDM:\sigma

, then

M

has a β-normal form.

M

is strongly normalizing, then

\Gamma\vdashCDM:\sigma

for some

\Gamma

and

\sigma

.

M

has a normal form in the λI-calculus, if and only if

\Gamma\vdashCDM:\sigma

for some

\Gamma

and

\sigma

.If the type language is extended to contain the empty intersection, i.e.

\sigma=\varphi1\cap\cap\varphinwheren=0

, then

(\vdashCD)

is closed under β-equality and is sound and complete for inference semantics.

Barendregt–Coppo–Dezani type assignment system

The Barendregt–Coppo–Dezani type assignment system

(\vdashBCD)

extends the Coppo–Dezani type assignment system in the following three aspects:

(\vdashBCD)

introduces the universal type constant

\omega

(akin to the empty intersection) that can be assigned to any λ-term.

(\vdashBCD)

allows the intersection type constructor

(\cap)

to appear on the right-hand side of the arrow type constructor

(\to)

.

(\vdashBCD)

introduces the intersection type subtyping

(\leq)

partial order on types together with a corresponding typing rule.

Term language

The term language of

(\vdashBCD)

is given by λ-terms (or, lambda expressions):

\begin{align} M,N&::=x\mid(λx.M)\mid(MN)&&wherexrangesovertermvariables\\ \end{align}

Type language

The type language of

(\vdashBCD)

is inductively defined by the following grammar:

\begin{align} \sigma,\tau&::=\alpha\mid\omega\mid\sigma\to\tau\mid\sigma\cap\tau&&where\alpharangesovertypevariables \end{align}

Intersection type subtyping

(\leq)

is defined as the smallest preorder (reflexive and transitive relation) over intersection types satisfying the following properties:

\begin{align} &\sigma\leq\omega,\omega\leq\omega\to\omega,\sigma\cap\tau\leq\sigma,\sigma\cap\tau\leq\tau,\\ &(\sigma\to\tau1)\cap(\sigma\to\tau2)\leq\sigma\to\tau1\cap\tau2,\\ &if\sigma\leq\tau1and\sigma\leq\tau2,then\sigma\leq\tau1\cap\tau2,\\ &if\sigma2\leq\sigma1and\tau1\leq\tau2,then\sigma1\to\tau1\leq\sigma2\to\tau2 \end{align}

Intersection type subtyping is decidable in quadratic time.

Typing rules

The typing rules

(\toI)

,

(\toE)

,

(\capI)

,

(\leq)

,

(A)

, and

(\omega)

of

(\vdashBCD)

are:

\begin{array}{cc} \dfrac{\Gamma,x:\sigma\vdashBCDM:\tau}{\Gamma\vdashBCDλx.M:\sigma\to\tau}(\toI) &\dfrac{\Gamma\vdashBCDM:\sigma\to\tau\Gamma\vdashBCDN:\sigma}{\Gamma\vdashBCDMN:\tau}(\toE)\\\\ \dfrac{\Gamma\vdashBCDM:\sigma\Gamma\vdashBCDM:\tau}{\Gamma\vdashBCDM:\sigma\cap\tau}(\capI) &\dfrac{\Gamma\vdashBCDM:\sigma(\sigma\leq\tau)}{\Gamma\vdashBCDM:\tau}(\leq)\\\\ \dfrac{}{\Gamma,x:\sigma\vdashBCDx:\sigma}(A) &\dfrac{}{\Gamma\vdashBCDM:\omega}(\omega) \end{array}

Properties

(\vdashBCD)

is sound and complete wrt. a filter λ-model, in which the interpretation of a λ-term coincides with the set of types that can be assigned to it.

\Gamma\vdashBCDM:\sigma

and

M\to\betaN

, then

\Gamma\vdashBCDN:\sigma

.

\Gamma\vdashBCDN:\sigma

and

M\to\betaN

, then

\Gamma\vdashBCDM:\sigma

.

M

is strongly normalizing wrt. β-reduction, if and only if

\Gamma\vdashBCDM:\sigma

is derivable without rule

(\omega)

for some

\Gamma

and

\sigma

.

M

is strongly normalizing, then there exists a principal pair

(\Gamma,\sigma)

such that for any typing

\Gamma'\vdashBCDM:\sigma'

the pair

(\Gamma',\sigma')

can be obtained from the principal pair

(\Gamma,\sigma)

by means of type expansions, liftings, and substitutions.

Notes and References

  1. Web site: Intersection Types in TypeScript . 2019-08-01.
  2. Web site: Compound Types in Scala . 2019-08-01.