Skip to main content
QUICK REVIEW

[Paper Review] Revisiting Occurrence Typing

Giuseppe Castagna, Victor Lanvin|arXiv (Cornell University)|Jul 12, 2019
Logic, programming, and type systemsComputer Science33 references1 citations
TL;DR

This paper proposes a generalized occurrence typing framework using full set-theoretic types—unions, intersections, and negations—to refine variable types in arbitrary expression contexts, not just top-level or simple positions. By leveraging semantic subtyping, it enables precise type inference for functions, including overloaded and polymorphic ones, surpassing current systems that require manual annotations or fail on complex cases.

ABSTRACT

We revisit occurrence typing, a technique to refine the type of variables occurring in type-cases and, thus, capturesome programming patterns used in untyped languages. Although occurrence typing was tied from its inceptionto set-theoretic types-union types, in particular-it never fully exploited the capabilities of these types. Here weshow how, by using set-theoretic types, it is possible to develop a general typing framework that encompasses andgeneralizes several aspects of current occurrence typing proposals and that can be applied to tackle other problemssuch as the reconstruction of intersection types for unannotated or partially annotated functions and the optimizationof the compilation of gradually typed languages.

Motivation & Objective

  • To overcome the limitation of existing occurrence typing systems that only refine types in restricted syntactic contexts, such as top-level variables or simple selectors.
  • To develop a formal, general-purpose typing framework that uses full set-theoretic type connectives (unions, intersections, negations) to refine types in any expression context.
  • To enable automatic reconstruction of precise (e.g., overloaded) function types without programmer annotations.
  • To extend the applicability of occurrence typing to complex patterns such as nested or higher-order function applications.

Proposed method

  • Uses semantic subtyping to formally define type refinements based on type tests, allowing type refinement in arbitrary expression contexts.
  • Applies intersection types to capture the precise return behavior of functions across different branches, enabling overloaded function typing.
  • Introduces a type refinement mechanism that removes from an expression’s type any values that would make a type test fail, using negation and intersection.
  • Employs a recursive type inference process that refines both variable and expression types simultaneously, bypassing standard type inference.
  • Extends the framework to handle polymorphic types by applying type substitutions that reflect test success/failure conditions.
  • Proposes a foundation for integrating with gradual typing and effect analysis, though these are left for future work.

Experimental results

Research questions

  • RQ1Can occurrence typing be generalized beyond top-level or simple selector contexts to arbitrary expression positions?
  • RQ2How can set-theoretic types (unions, intersections, negations) be systematically used to refine types in complex expression contexts?
  • RQ3Can this framework automatically infer precise overloaded function types without programmer annotations?
  • RQ4What is the role of intersection types in capturing the behavior of functions across multiple control flows?
  • RQ5How can this approach be extended to handle polymorphic types and side effects?

Key findings

  • The framework successfully generalizes occurrence typing to arbitrary expression contexts, including nested applications and complex selector paths.
  • It enables automatic inference of overloaded function types such as (number → number) & (string → string), which current systems require manual annotation for.
  • The system can deduce precise types for functions like `foo` in the introduction without requiring explicit type annotations.
  • It provides a formal foundation for type refinement that simultaneously refines both variable and expression types, improving precision.
  • The approach can be extended to polymorphic types by using type substitutions that reflect test outcomes, though convergence and practicality remain open.
  • The framework lays the groundwork for optimizing gradual typing compilation and reconstructing intersection types in unannotated code.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.