Changes between Version 33 and Version 34 of Records/OverloadedRecordFields/Redesign


Ignore:
Timestamp:
Oct 22, 2015 8:11:03 PM (4 years ago)
Author:
adamgundry
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Records/OverloadedRecordFields/Redesign

    v33 v34  
    1 = Overloaded record fields: a modest proposal =
     1= `OverloadedRecordFields`: design overview =
    22
    33[[PageOutline]]
    44
    55This is an attempt to redesign and clarify the design of the OverloadedRecordFields extension, in order to develop a plan for implementation.  It has benefited from the extensive discussion surrounding [wiki:Records/Volkov Nikita Volkov's record library].  The following design choices are not set in stone, but are intended as a concrete proposal for further discussion.  For reference, here is the [wiki:Records/OverloadedRecordFields/Design previous design].
    6 
    7 [wiki:Records/OverloadedRecordFields/Implementation Implementation notes here].
    86
    97See also the [http://www.well-typed.com/blog/2015/03/overloadedrecordfields-revived/ high-level summary of the current plan on the Well-Typed blog].
     
    3230
    3331
    34 == Anonymous records ==
     32== Summary ==
     33
     34We propose three essentially orthogonal additions to GHC:
     35
     36 1. an extension `DuplicateRecordFields` to permit the same field name to be used multiple times in the same module;
     37 2. an extension `OverloadedLabels` to enable the `#x` syntax, interpreted with the `IsLabel` typeclass;
     38 3. typeclasses with special-purpose constraint solving behaviour to enable polymorphism over record fields.
     39
     40The `OverloadedRecordFields` extension is then defined as the combination of `OverloadedLabels` and `DuplicateRecordFields`.
     41
     42These are all useful independently, but complement each other:
     43
     44 * `DuplicateRecordFields` is perfectly sensible without `OverloadedLabels`: it allows duplicate field names provided they are not used ambiguously.
     45 * `OverloadedLabels` uses the special typeclasses through the instance for `IsLabel x (r -> a)`, but is also useful when used at other types (e.g. we could give an instance `IsLabel x (Proxy x)` to allow implicit values to represent Symbol proxies).
     46 * Without either of the extensions, the special typeclasses allow users to write code that works for all datatypes with particular fields (albeit without a nice built-in syntax).
     47
     48
     49=== Anonymous records ===
    3550
    3651While we might choose to add anonymous records later, they are not central to the design.  In particular, this means that
     
    4358
    4459 * no new declaration syntax is added.
    45 
    46 
    47 == Summary ==
    48 
    49 We propose three essentially orthogonal additions to GHC:
    50 
    51  1. `HasField` and `FieldUpdate` typeclasses, with special-purpose constraint solving behaviour (just like `Coercible`, we do not require a special extension to enable this, as its effect is limited to code that imports the relevant module);
    52  2. an extension `OverloadedLabels` to enable the `#x` syntax, interpreted with the `IsLabel` typeclass;
    53  3. an extension `DuplicateRecordFields` to permit the same field name to be used multiple times in the same module.
    54 
    55 The `OverloadedRecordFields` extension is then defined as the combination of `OverloadedLabels` and `DuplicateRecordFields`.
    56 
    57 These are all useful independently, but complement each other:
    58 
    59  * Without either of the extensions, the special typeclasses allow users to write code that works for all datatypes with particular fields (albeit without a nice built-in syntax).
    60  * `OverloadedLabels` uses the special typeclasses through the instance for `IsLabel x (r -> a)`, but is also useful when used at other types (e.g. we could give an instance `IsLabel x (Proxy x)` to allow implicit values to represent Symbol proxies).
    61  * `DuplicateRecordFields` is perfectly sensible without `OverloadedLabels`: it allows duplicate field names provided they are not used ambiguously.