Table of Contents
Fetching ...

Programming with union, intersection, and negation types

Giuseppe Castagna

TL;DR

This essay presents the advantages and the beauty of programming in a language with set-theoretic types, that is, types that include union, intersection, and negation type connectives, and discusses the design of languages that use these types.

Abstract

In this essay, I present the advantages and, I dare say, the beauty of programming in a language with set-theoretic types, that is, types that include union, intersection, and negation type connectives. I show by several examples how set-theoretic types are necessary to type some common programming patterns, but also how they play a key role in typing several language constructs-from branching and pattern matching to function overloading and type-cases-very precisely. I start by presenting the theory of types known as semantic subtyping and extend it to include polymorphic types. Next, I discuss the design of languages that use these types. I start by defining a theoretical framework that covers all the examples given in the first part of the presentation. Since the system of the framework cannot be effectively implemented, I then describe three effective restrictions of this system: (i) a polymorphic language with explicitly-typed functions, (ii) an implicitly-typed polymorphic language à la Hindley-Milner, and (iii) a monomorphic language that, by implementing classic union-elimination, precisely reconstructs intersection types for functions and implements a very general form of occurrence typing. I conclude the presentation with a short overview of other aspects of these languages, such as pattern matching, gradual typing, and denotational semantics.

Programming with union, intersection, and negation types

TL;DR

This essay presents the advantages and the beauty of programming in a language with set-theoretic types, that is, types that include union, intersection, and negation type connectives, and discusses the design of languages that use these types.

Abstract

In this essay, I present the advantages and, I dare say, the beauty of programming in a language with set-theoretic types, that is, types that include union, intersection, and negation type connectives. I show by several examples how set-theoretic types are necessary to type some common programming patterns, but also how they play a key role in typing several language constructs-from branching and pattern matching to function overloading and type-cases-very precisely. I start by presenting the theory of types known as semantic subtyping and extend it to include polymorphic types. Next, I discuss the design of languages that use these types. I start by defining a theoretical framework that covers all the examples given in the first part of the presentation. Since the system of the framework cannot be effectively implemented, I then describe three effective restrictions of this system: (i) a polymorphic language with explicitly-typed functions, (ii) an implicitly-typed polymorphic language à la Hindley-Milner, and (iii) a monomorphic language that, by implementing classic union-elimination, precisely reconstructs intersection types for functions and implements a very general form of occurrence typing. I conclude the presentation with a short overview of other aspects of these languages, such as pattern matching, gradual typing, and denotational semantics.

Paper Structure

This paper contains 39 sections, 53 equations, 9 figures, 2 tables.

Figures (9)

  • Figure 1: Declarative type system
  • Figure 2: Canonical typing rules
  • Figure 3: Algorithmic system for the core calculus of CDuce
  • Figure 4: Typing rule for let-polymorphism
  • Figure 5: Constraint generation
  • ...and 4 more figures

Theorems & Definitions (5)

  • definition 1: Types
  • definition 2: Interpretation domain
  • definition 3: Set-theoretic interpretation of types
  • definition 4: Subtyping
  • definition 5: MSC Forms