Lazier Binary Decision Diagrams for set-theoretic types

https://news.ycombinator.com/rss Hits: 5
Summary

The Elixir team and the CNRS are working on a set-theoretic type system for Elixir which, simply put, is a type-system powered by unions, intersections, and negations. As part of the implementation of said type systems, we need an efficient way of representing said operations. This article discusses the existing approaches found in theory and practice, as well as the improvements we have introduced as part of Elixir v1.19. This article covers the implementation details of the type system. You don鈥檛 need to understand these internals to use the type system, just as you don鈥檛 need to know virtual machine bytecodes or compiler passes to use a programming language. Our goal is to document our progress and provide guidance for future maintainers and implementers. Let鈥檚 get started. DNFs - Disjunctive Normal Forms A Disjunctive Normal Form (DNF) is a standardized way of expressing logical formulas using only disjunctions (unions) of conjunctions (intersections). In the context of set-theoretic type systems, DNFs provide a canonical representation for union and intersection types, represented respectively as or and and in Elixir. In Elixir, we would represent those as lists of lists. Consider a type expression like (A and B) or (C and D). This is already in DNF, it鈥檚 a union of intersections, and it would be represented as: [[A, B], [C, D]]. This means performing unions between two DNFs is a simple list concatenation: def union(dnf1, dnf2), do: dnf1 ++ dnf2 However, more complex expressions like A and (B or C) need to be converted. Using distributive laws, this becomes (A and B) or (A and C), which is now in DNF. In other words, the intersection of DNFs is a Cartesian product: def intersection(dnf1, dnf2) do for intersections1 <- dnf1, intersections2 <- dnf2 do intersections1 ++ intersections2 end end The advantage of DNFs is their simple structure. Every type can be represented as unions of intersecting terms, making operations like checking if a type is empty simply a ma...

First seen: 2025-12-02 14:54

Last seen: 2025-12-02 18:54