The Overloaded Record Fields family of extensions for GHC allow multiple record datatypes to share the same field names, and make it possible for type information to disambiguate fields. There is no single
OverloadedRecordFields extension, but rather a family of related extensions:
DisambiguateRecordFields: makes use of constructor names to disambiguate fields in record construction or pattern matching.
DuplicateRecordFields: permits a module to define the same field name in multiple datatypes.
#fieldsyntax for an identifier whose meaning is determined by typeclass instance resolution. Intended for use with the
HasFieldmagic type class.
NoFieldSelectors: prevents fields being in scope as selector functions. (Not yet released as of January 2020.)
expression.fieldsyntax for record projection. (Not yet released as of January 2020.)
For user-facing documentation, see the GHC user's guide:
- DisambiguateRecordFields extension
- DuplicateRecordFields extension
- OverloadedLabels extension
- Record field selector polymorphism (HasField class)
For design discussion, see the GHC proposals:
Adding HasField class, changes to OverloadedLabels (Implemented in GHC 8.2 without
IsLabel x (r -> a)instance)
- Adding setField to HasField (Being implemented, see !3257)
- NoFieldSelectors (Being implemented for GHC 9.2, see !4743 (closed))
- DuplicateRecordFields without ambiguous field access
Content previously on this page has been moved to the SORF page.
- Prototype implementation of the magic typeclasses
Phab:D761, Phab:D1391, Phab:D1486, Phab:D1586, Phab:D1600:
- Phab:D1687, Phab:D2708: magic classes
!3257: extension of
HasFieldclass to support updates
NoFieldSelectorsand liberalisation of
The extension was initially implemented in 2013 as a Google Summer of Code project, by Adam Gundry under the mentorship of Simon Peyton Jones.
- Simple Overloaded Record Fields (SORF), Simon PJ's original proposal
- Declared Overloaded Record Fields (DORF), a counterpoint proposal by Anthony Clayden
- Discussion of the problem and possible solutions
- Original design of the extension (2013)
- Redesigned variant involving three extensions (2015)