Set-theoretic Types for Erlang

Albert Schimpf,Stefan Wehr,Annette Bieniusa
2023-06-13
Abstract:Erlang is a functional programming language with dynamic typing. The language offers great flexibility for destructing values through pattern matching and dynamic type tests. Erlang also comes with a type language supporting parametric polymorphism, equi-recursive types, as well as union and a limited form of intersection types. However, type signatures only serve as documentation, there is no check that a function body conforms to its signature. Set-theoretic types and semantic subtyping fit Erlang's feature set very well. They allow expressing nearly all constructs of its type language and provide means for statically checking type signatures. This article brings set-theoretic types to Erlang and demonstrates how existing Erlang code can be statically typechecked without or with only minor modifications to the code. Further, the article formalizes the main ingredients of the type system in a small core calculus, reports on an implementation of the system, and compares it with other static typecheckers for Erlang.
Programming Languages
What problem does this paper attempt to address?
### Problems the Paper Aims to Solve This paper aims to design a static type system for Erlang to improve code safety and quality. Specifically: 1. **Background**: - Erlang is a dynamically typed functional programming language widely used in the industry. - In dynamically typed languages, type errors can only be detected at runtime, which may lead to program crashes. 2. **Existing Problems**: - Although Erlang supports type definitions and type signatures, the compiler does not check if these signatures conform to the actual implementation, so type signatures serve only as documentation. - Existing static type checking tools (such as Dialyzer) can detect some errors but cannot completely eliminate errors caused by data format mismatches. 3. **Goals**: - Design a static type system such that programs that pass type checking will not encounter certain categories of errors at runtime, such as parameter type mismatches and incomplete pattern matching. - The type system should be able to perform static type checking on existing Erlang code with minimal or no modifications to the code. 4. **Methods**: - Use set-theoretic types and semantic subtyping, both of which are well-suited to Erlang's characteristics. - Propose a new static type checking tool, etylizer, for type checking Erlang code. Through these methods, the paper hopes to improve the software quality and development efficiency of Erlang projects.