Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,829
    • Issues 4,829
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 445
    • Merge requests 445
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Wiki
  • Records
  • overloaded record fields

Last edited by Hécate Moonlight Mar 02, 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 #field 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 (closed))
  • 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 (closed): RecordDotSyntax
  • !4743 (closed): 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 Edit sidebar

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