Primitive types often don’t convey enough constraints to call functions safely. Scala 3 features enable additional constraint specification on data types in a composable way, without needing to change data types as previously experimentally with in systems based on smart constructors or tagging.
Under-constrained data specification leads to runtime errors that bypass the static type checker. Refinement types attempt to fill this gap, but common implementation approaches to refinement types in Scala haven’t been entirely satisfying. Smart constructors and tagging types both require separate data types. This leads to inelegant solutions for mutually dependent constraints and type class interoperability.
Scala 3’s new features, such as union and match types, enable a composable constraint system supporting the full breadth of Boolean algebra. These constraints can be user-defined and are evaluated either at runtime or compile time through inlining as specified by the caller.
I’m a software engineer at Lucid Software interested in how programming
techniques affect our ability to design correct programs.
Join our conference
Subscribe and follow @ScalaDays on Twitter for the latest conference updates.