[Paper Review] Finite Combinatory Logic with Predicates
This paper presents a theoretical and practical framework for programming with set-theoretic types—union, intersection, and negation—demonstrating their necessity and expressiveness in typing complex programming patterns. By extending semantic subtyping to include polymorphism and designing three effective language restrictions (explicitly-typed, Hindley-Milner-style, and monomorphic with occurrence typing), the authors show how these types enable precise, polymorphic typing of functions like flatten, even in the absence of explicit annotations in some cases, and reveal their foundational role in pattern matching, overloading, and gradual typing.
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.
Motivation & Objective
- To demonstrate that set-theoretic types—union, intersection, and negation—are essential for typing common programming patterns such as pattern matching, function overloading, and type-cases.
- To extend the theory of semantic subtyping to include polymorphic types, enabling a formal foundation for advanced type systems.
- To design and implement three effective, practical restrictions of a full set-theoretic type system: explicitly-typed, implicitly-typed (Hindley-Milner), and monomorphic with occurrence typing.
- To show that even in the absence of explicit annotations, occurrence typing and type reconstruction can recover intersection types for functions.
- To argue that set-theoretic types are not only useful for static typing but also underlie meta-level type constructions in dynamic languages and gradual typing.
Proposed method
- Extends semantic subtyping to include polymorphic types, using set-theoretic interpretations of types as sets of values.
- Introduces a theoretical framework based on set-theoretic types, where union (t1 ∪ t2), intersection (t1 ∩ t2), and negation (¬t) are interpreted as set unions, intersections, and complements.
- Proposes three practical restrictions: (i) explicitly-typed polymorphic language, (ii) implicitly-typed Hindley-Milner-style language, and (iii) monomorphic language with union-elimination and occurrence typing.
- Uses occurrence typing to reconstruct intersection types for functions by analyzing control flow and type guards.
- Applies the framework to type-check complex functions like flatten, which requires recursive, polymorphic types with union and negation to express the type of nested lists.
- Employs denotational semantics and constraint-based type inference to formalize type reconstruction and error reporting.
Experimental results
Research questions
- RQ1Can set-theoretic types (union, intersection, negation) be used to type common programming patterns such as pattern matching and function overloading in a precise and general way?
- RQ2Why do current type systems fail to infer intersection types for functions like 'not' or 'flatten' without explicit annotations?
- RQ3How can a practical type system be designed that supports set-theoretic types while remaining efficient and amenable to implementation?
- RQ4To what extent can occurrence typing and type-case analysis reconstruct intersection types in the absence of explicit type annotations?
- RQ5How do set-theoretic types support the formalization of gradual typing and other advanced type disciplines?
Key findings
- The flatten function, which flattens arbitrarily nested lists, can be given the polymorphic type ∀α.Tree(α) → List(α) in a language with full set-theoretic types, such as CDuce, but cannot be inferred in standard ML-like systems without explicit annotations.
- Set-theoretic types are necessary to express the precise type of the flatten function: for an input with leaves of types Int, Bool, and String, the output type is List(Int ∪ Bool ∪ String).
- Even in the absence of explicit annotations, a monomorphic language with occurrence typing can reconstruct intersection types for functions by analyzing control flow and type guards.
- The constraint-based type inference system for set-theoretic types is powerful but computationally expensive, leading to potential performance and error message challenges.
- Set-theoretic types provide a foundational framework for understanding and formalizing advanced type features such as type-cases, pattern matching, and gradual typing.
- Despite the theoretical expressiveness, no current system fully supports the integration of implicit and explicit typing, intersection type reconstruction, and advanced occurrence typing in a single coherent framework.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.