Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,273
    • Issues 4,273
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 413
    • Merge Requests 413
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Wiki
    • Records
  • overloaded record fields

Last edited by Adam Gundry Jan 07, 2021
Page history New page

overloaded record fields

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.
  • OverloadedLabels: provides #foo syntax for an identifier whose meaning is determined by typeclass instance resolution. Intended for use with the HasField magic type class.
  • NoFieldSelectors: prevents fields being in scope as selector functions. (Not yet released as of January 2020.)
  • RecordDotSyntax: permits expression.field syntax 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 implementation status, see #18598, the tracking ticket for most recent work related to overloaded record fields, and the OverloadedRecordFields label.

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)
  • RecordDotSyntax
  • DuplicateRecordFields without ambiguous field access

Content previously on this page has been moved to the SORF page.

Code

  • Prototype implementation of the magic typeclasses
  • Phab:D761, Phab:D1391, Phab:D1486, Phab:D1586, Phab:D1600: DuplicateRecordFields extension
  • Phab:D1331, Phab:D1623: OverloadedLabels extension
  • Phab:D1687, Phab:D2708: magic classes
  • !3257: extension of HasField class to support updates
  • !4532: RecordDotSyntax
  • !4743: NoFieldSelectors and liberalisation of DuplicateRecordFields

History

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)
    • Part 1: DuplicateRecordFields (in GHC 8.0)
    • Part 2: OverloadedLabels (in GHC 8.0)
    • Part 3: Magic type classes (partly in GHC 8.2)
    • Adam Gundry's blog post
Clone repository

GHC Home
GHC User's Guide

Joining In

Newcomers info
Mailing Lists & IRC
The GHC Team

Documentation

GHC Status Info
Working conventions
Building Guide
Debugging
Commentary

Wiki

Title Index
Recent Changes