Английская Википедия:Intersection type discipline

Материал из Онлайн справочника
Перейти к навигацииПерейти к поиску

Шаблон:Short description

In mathematical logic, the intersection type discipline is a branch of type theory encompassing type systems that use the intersection type constructor <math>(\cap)</math> to assign multiple types to a single term.[1] In particular, if a term <math>M</math> can be assigned both the type <math>\varphi_1</math> and the type <math>\varphi_2</math>, then <math>M</math> can be assigned the intersection type <math>\varphi_1 \cap \varphi_2</math> (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 <math>\lambda x.\!(x\;x)</math> can be assigned the type <math>((\alpha \to \beta) \cap \alpha) \to \beta</math> in most intersection type systems, assuming for the term variable <math>x</math> both the function type <math>\alpha \to \beta</math> and the corresponding argument type <math>\alpha</math>.

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.

History

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 <math>\omega</math> that can be assigned to any λ-term, thereby corresponding to the empty intersection.[8] Using the universal type <math>\omega</math> 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]

Coppo–Dezani type assignment system

The Coppo–Dezani type assignment system <math>(\vdash_{\text{CD}})</math> extends the simply typed λ-calculus by allowing multiple types to be assumed for a term variable.[2]

Term language

The term language of <math>(\vdash_\text{CD})</math> is given by λ-terms (or, lambda expressions):

<math>

\begin{align} M, N & ::= x \mid (\lambda x.\!M) \mid (M\;N) && \text{ where } x \text{ ranges over term variables}\\ \end{align} </math>

Type language

The type language of <math>(\vdash_\text{CD})</math> is inductively defined by the following grammar:

<math>

\begin{align} \varphi & ::= \alpha \mid \sigma \to \varphi && \text{ where } \alpha \text{ ranges over type variables}\\ \sigma & ::= \varphi_1 \cap \cdots \cap \varphi_n && \text{ where } n \geq 1 \end{align} </math> The intersection type constructor (<math>\cap</math>) is taken modulo associativity, commutativity and idempotence.

Typing rules

The typing rules <math>(\to\!\!\text{I})</math>, <math>(\to\!\!\text{E})</math>, <math>(\cap\text{I})</math>, and <math>(\cap\text{E})</math> of <math>(\vdash_\text{CD})</math> are:

<math>

\begin{array}{cc} \dfrac{\Gamma, x : \sigma \vdash_\text{CD} M : \varphi}{\Gamma \vdash_\text{CD} \lambda x.\!M : \sigma \to \varphi}(\to\!\!\text{I}) &\dfrac{\Gamma \vdash_\text{CD} M : \sigma \to \varphi \quad \Gamma \vdash_\text{CD} N : \sigma}{\Gamma \vdash_\text{CD} M\;N : \varphi}(\to\!\!\text{E})\\\\ \dfrac{\Gamma \vdash_\text{CD} M : \varphi_1 \quad \ldots \quad \Gamma \vdash_\text{CD} M : \varphi_n}{\Gamma \vdash_\text{CD} M : \varphi_1 \cap \cdots \cap \varphi_n}(\cap\text{I}) &\dfrac{(1 \leq i \leq n)}{\Gamma, x : \varphi_1 \cap \cdots \cap \varphi_n \vdash_\text{CD} x : \varphi_i}(\cap\text{E}) \end{array} </math>

Properties

Typability and normalization are closely related in <math>(\vdash_{\text{CD}})</math> by the following properties:[2]

  • Subject reduction: If <math>\Gamma \vdash_{\text{CD}} M : \sigma</math> and <math>M \to_\beta N</math>, then <math>\Gamma \vdash_{\text{CD}} N : \sigma</math>.
  • Normalization: If <math>\Gamma \vdash_{\text{CD}} M : \sigma</math>, then <math>M</math> has a β-normal form.
  • Typability of strongly normalizing λ-terms: If <math>M</math> is strongly normalizing, then <math>\Gamma \vdash_{\text{CD}} M : \sigma</math> for some <math>\Gamma</math> and <math>\sigma</math>.
  • Characterization of λI-normalization: <math>M</math> has a normal form in the λI-calculus, if and only if <math>\Gamma \vdash_{\text{CD}} M : \sigma</math> for some <math>\Gamma</math> and <math>\sigma</math>.

If the type language is extended to contain the empty intersection, i.e. <math>\sigma = \varphi_1 \cap \cdots \cap \varphi_n \text{ where } n = 0</math>, then <math>(\vdash_{\text{CD}})</math> is closed under β-equality and is sound and complete for inference semantics.[14]

Barendregt–Coppo–Dezani type assignment system

The Barendregt–Coppo–Dezani type assignment system <math>(\vdash_{\text{BCD}})</math> extends the Coppo–Dezani type assignment system in the following three aspects:[3]

  • <math>(\vdash_\text{BCD})</math> introduces the universal type constant <math>\omega</math> (akin to the empty intersection) that can be assigned to any λ-term.
  • <math>(\vdash_{\text{BCD}})</math> allows the intersection type constructor <math>(\cap)</math> to appear on the right-hand side of the arrow type constructor <math>(\to)</math>.
  • <math>(\vdash_\text{BCD})</math> introduces the intersection type subtyping <math>(\leq)</math> partial order on types together with a corresponding typing rule.

Term language

The term language of <math>(\vdash_{\text{BCD}})</math> is given by λ-terms (or, lambda expressions):

<math>

\begin{align} M, N & ::= x \mid (\lambda x.\!M) \mid (M\;N) && \text{ where } x \text{ ranges over term variables}\\ \end{align} </math>

Type language

The type language of <math>(\vdash_{\text{BCD}})</math> is inductively defined by the following grammar:

<math>

\begin{align} \sigma, \tau & ::= \alpha \mid \omega \mid \sigma \to \tau \mid \sigma \cap \tau && \text{ where } \alpha \text{ ranges over type variables} \end{align} </math>

Intersection type subtyping

Intersection type subtyping <math>(\leq)</math> is defined as the smallest preorder (reflexive and transitive relation) over intersection types satisfying the following properties:

<math>

\begin{align} &\sigma \leq \omega, \quad \omega \leq \omega\to\omega, \quad \sigma \cap \tau \leq \sigma, \quad \sigma \cap \tau \leq \tau, \\ & (\sigma\to\tau_1) \cap (\sigma\to\tau_2) \leq \sigma \to \tau_1 \cap \tau_2,\\ &\text{if }\sigma \leq \tau_1 \text{ and } \sigma\leq \tau_2 \text{, then } \sigma \leq \tau_1 \cap \tau_2, \\ &\text{if } \sigma_2 \leq \sigma_1 \text{ and } \tau_1 \leq \tau_2 \text{, then } \sigma_1\to\tau_1 \leq \sigma_2\to\tau_2 \end{align} </math> Intersection type subtyping is decidable in quadratic time.[15]

Typing rules

The typing rules <math>(\to\!\!\text{I})</math>, <math>(\to\!\!\text{E})</math>, <math>(\cap\text{I})</math>, <math>(\leq)</math>, <math>(\text{A})</math>, and <math>(\omega)</math> of <math>(\vdash_{\text{BCD}})</math> are:

<math>

\begin{array}{cc} \dfrac{\Gamma, x : \sigma \vdash_{\text{BCD}} M : \tau}{\Gamma \vdash_{\text{BCD}} \lambda x.\!M : \sigma \to \tau}(\to\!\!\text{I}) &\dfrac{\Gamma \vdash_{\text{BCD}} M : \sigma \to \tau \quad \Gamma \vdash_{\text{BCD}} N : \sigma}{\Gamma \vdash_{\text{BCD}} M\;N : \tau}(\to\!\!\text{E})\\\\ \dfrac{\Gamma \vdash_{\text{BCD}} M : \sigma \quad \Gamma \vdash_{\text{BCD}} M : \tau}{\Gamma \vdash_{\text{BCD}} M : \sigma \cap \tau}(\cap\text{I}) &\dfrac{\Gamma \vdash_{\text{BCD}} M : \sigma \quad (\sigma \leq \tau)}{\Gamma \vdash_{\text{BCD}} M : \tau}(\leq)\\\\ \dfrac{}{\Gamma, x : \sigma \vdash_{\text{BCD}} x : \sigma}(\text{A}) &\dfrac{}{\Gamma \vdash_{\text{BCD}} M : \omega}(\omega) \end{array} </math>

Properties

  • Semantics: <math>(\vdash_{\text{BCD}})</math> 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.[3]
  • Subject reduction: If <math>\Gamma \vdash_{\text{BCD}} M : \sigma</math> and <math>M \to_{\beta} N</math>, then <math>\Gamma \vdash_{\text{BCD}} N : \sigma</math>.[3]
  • Subject expansion: If <math>\Gamma \vdash_{\text{BCD}} N : \sigma</math> and <math>M \to_{\beta} N</math>, then <math>\Gamma \vdash_{\text{BCD}} M : \sigma</math>.[3]
  • Characterization of strong normalization: <math>M</math> is strongly normalizing wrt. β-reduction, if and only if <math>\Gamma \vdash_{\text{BCD}} M : \sigma</math> is derivable without rule <math>(\omega)</math> for some <math>\Gamma</math> and <math>\sigma</math>.[16]
  • Principal pairs: If <math>M</math> is strongly normalizing, then there exists a principal pair <math>(\Gamma, \sigma)</math> such that for any typing <math>\Gamma' \vdash_{\text{BCD}} M : \sigma'</math> the pair <math>(\Gamma', \sigma')</math> can be obtained from the principal pair <math>(\Gamma, \sigma)</math> by means of type expansions, liftings, and substitutions.[17]

References

Шаблон:Reflist

  1. Ошибка цитирования Неверный тег <ref>; для сносок BDS13 не указан текст
  2. 2,0 2,1 2,2 2,3 2,4 Ошибка цитирования Неверный тег <ref>; для сносок CD80 не указан текст
  3. 3,0 3,1 3,2 3,3 3,4 Ошибка цитирования Неверный тег <ref>; для сносок BCD83 не указан текст
  4. Ошибка цитирования Неверный тег <ref>; для сносок B11 не указан текст
  5. Шаблон:Cite web
  6. Шаблон:Cite web
  7. 7,0 7,1 Ошибка цитирования Неверный тег <ref>; для сносок P80 не указан текст
  8. 8,0 8,1 Ошибка цитирования Неверный тег <ref>; для сносок CDS79 не указан текст
  9. Ошибка цитирования Неверный тег <ref>; для сносок CD78 не указан текст
  10. Ошибка цитирования Неверный тег <ref>; для сносок CDV81 не указан текст
  11. Ошибка цитирования Неверный тег <ref>; для сносок U99 не указан текст
  12. Ошибка цитирования Неверный тег <ref>; для сносок U09 не указан текст
  13. Ошибка цитирования Неверный тег <ref>; для сносок DR19 не указан текст
  14. Ошибка цитирования Неверный тег <ref>; для сносок VB92 не указан текст
  15. Ошибка цитирования Неверный тег <ref>; для сносок DMR17 не указан текст
  16. Ошибка цитирования Неверный тег <ref>; для сносок G96 не указан текст
  17. Ошибка цитирования Неверный тег <ref>; для сносок RDRV83 не указан текст