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,249
    • Issues 4,249
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 391
    • Merge Requests 391
  • 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
  • explicit classy records

Last edited by Tobias Dammers Mar 29, 2019
Page history New page

explicit classy records

Simple record system with selectors overloaded in explicitly-user-declared type classes. Thus one can control the scope as of any other type class.

To declare a record type, first declare classes of its selectors. Selectors can be grouped in classes by user's wish. For example:

class Xive a where x :: a -> X;

For each class C ... a, every selector must be of type a -> x, where x is member type.

Then the semantics of a record type declaration

data R = R { x :: X };

are these:

If x is in scope, part of some class C ... a, and of type C ... a => a -> X; then automatic instance C R where x (R { x = x }) = x; else type error.

If the member is polymorphic, then the semantics of a record type declaration

data R x = R { x :: x };

are these:

If x is in scope, part of some class C ... x ... a, and of type C ... x ... a => a -> x;

then automatic instance C ... x ... (R x) where x (R { x = x }) = x; else type error.

The semantics of the record mutation

(r :: R) { x = x' }

are these:

If x is in scope, part of some class C ... x ... a, and of type C ... x ... a => a -> x, and an instance C ... x ... R is in scope, and types of x and x' can be unified, i.e. x=x' would be valid in instance declaration of C ... x ... a; then its value is s such that

x s = x', y s = y r

where y is any other selector.

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