First-Class Refinement Types for Scala

📅 2026-05-08
📈 Citations: 0
Influential: 0
📄 PDF

career value

169K/year
🤖 AI Summary
Existing languages typically relegate refinement types to secondary annotations or separate specifications, hindering seamless integration with core language features such as subtyping, type inference, and pattern matching, thereby limiting their practical utility. This work presents the first integration of refinement types as first-class citizens in Scala 3, leveraging dependent function types, bounded polymorphism, recursion, and union/intersection types to deeply embed logical predicates into the type system. Building upon a partial correctness semantics, we develop a fuel-bounded semantic type system, formalize a core calculus, and prove its type safety. Furthermore, we implement a prototype extension of the Scala 3 compiler that combines Rocq-based verification with a lightweight e-graph-based predicate solver, enabling practical and scalable lightweight program verification.
📝 Abstract
Refinement types -- types qualified with logical predicates -- have proven effective for lightweight verification in languages like Liquid Haskell, F*, and Dafny. However, in these systems refinements are either written in a separate specification language or treated as second-class annotations, disconnected from the host language's type system. This disconnect creates usability barriers: programmers must maintain two mental models, and refinements cannot interact with features like type inference, subtyping, or overloading. We present the design of first-class refinement types for Scala 3, where refinements are ordinary types that participate in subtyping, inference, and pattern matching alongside existing language features. We prove type soundness of a core calculus mechanized in Rocq, combining dependent function types, bounded polymorphism, positive equi-recursive types, union and intersection types, and refinement types under a partial-correctness semantics using a fuel-bounded definitional interpreter and semantic typing. Finally, we implement our design as a prototype extension of the Scala 3 compiler with a lightweight e-graph-based solver for predicate entailment.
Problem

Research questions and friction points this paper is trying to address.

refinement types
type system
usability barriers
second-class annotations
language integration
Innovation

Methods, ideas, or system contributions that make the work stand out.

first-class refinement types
type soundness
e-graph solver
Scala 3
semantic typing