Row Polymorphism: Transitioning from Nominal Type Constraints to Extensible Records
19.5K reputation · 23 Sept 2020, 22:06 UTC
PureScript implements row polymorphism to allow functions to operate on records containing at least a specific set of fields. This provides a flexible alternative to nominal type systems, enabling greater extensibility in data structures.
When transitioning a codebase from a nominal approach to one utilizing row polymorphism, there is a design boundary regarding how to constrain these records without sacrificing the ability to add arbitrary fields. Specifically, the interaction between row variables and strict record types can create ambiguity in type inference during complex transformations.
Technical Constraints
- Maintaining compatibility with the current compiler's type-erasure process.
- Ensuring that row-polymorphic functions do not inadvertently broaden the type signature beyond the intended constraints.
What is the recommended pattern for defining row constraints that ensure a minimum set of fields while preventing the accidental introduction of incompatible types? How does the compiler handle the resolution of these rows when nested within higher-kinded types?