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,827
    • Issues 4,827
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 450
    • Merge requests 450
  • 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
  • type indexed records

Last edited by strake888 Mar 03, 2012
Page history New page

type indexed records

Type-Indexed Records

Proposal for new Haskell record system. Record selection is simple operator. Keys are arbitrary types. Scope is controlled as scope of key types.

Basics

Type classes for types with member at 'k'

class Has k v r where (.) :: r -> k -> v;

which means that r has member of type v with key type k, and for types with mutable member at 'k'

class (Has k u r, Has k v s) => Quasifunctor k u v r s where qfmap :: k -> (u -> v) -> r -> s;

which means that r and s have members of types u and v, in turn, both with selector k; thus, one can mutate the member at 'k' with an arbitrary function of type u -> v, and the overall function is of type r -> s; i.e. one can lift a function of type u -> v to a function of type r -> s.

A record type is of the form

type R a b c ... = { X ::. a, Y ::. b, Z ::. c, ... };

which automatically generates

instance Has X a (R a b c ...);
instance Has Y b (R a b c ...);
instance Has Z c (R a b c ...);
...
instance Quasifunctor X a a' (R a b c ...) (R a' b c ...);
instance Quasifunctor Y b b' (R a b c ...) (R a b' c ...);
instance Quasifunctor Z c c' (R a b c ...) (R a b c' ...);
...

Record selection and mutation

Let

type R a b c = { X ::. a, Y ::. b, Z ::. c, ... };

-- keys
data X = X;
data Y = Y;
data Z = Z;

Then r.X :: a is the member of r at X, and qfmap X f r is r mutated by f at X; thus also for other keys Y, Z, .... We might define some sugar for qfmap.

We can define

x = X;
y = Y;
z = Z;

to allow r.x, r.y, r.z, ....

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