Changes between Version 41 and Version 42 of Records/OverloadedRecordFields/Implementation


Ignore:
Timestamp:
Aug 15, 2013 3:49:54 PM (2 years ago)
Author:
adamgundry
Comment:

instance generation

Legend:

Unmodified
Added
Removed
Modified
  • Records/OverloadedRecordFields/Implementation

    v41 v42  
    9393== Automatic instance generation ==
    9494
    95 `Has` instances are generated, provided the extension is enabled, in `tcInstDecls1` (the same time as derived instances (from '''deriving''' clauses) are generated). Every record field `GRE` in scope gives rise to an instance. Such instances are available when typechecking the current module (in `tcg_inst_env`) but not exported to other modules (via `tcg_insts`). At the moment, fresh `DFunId`s are generated for all instances in scope for each module, even though they are exported in interface files. Perhaps this should change.
     95Typeclass and family instances are generated, provided the extension is enabled, by `makeRecFldInsts` in `TcInstDecls`. This function is called in two places:
     96
     97* `tcInstDecls1` generates instances for fields from datatypes in the current group (at the same time as derived instances, from '''deriving''' clauses, are generated)
     98
     99* `tcRnImports` in `TcRnDriver` generates instances for imported fields, by looking at the `GlobalRdrEnv`
     100
     101The typeclass instances must be subsequently typechecked (by `tcInstDecls2`). Such instances are "private" in that they are available when typechecking the current module (in `tcg_inst_env`) but not exported to other modules (via `tcg_insts`).
     102
     103'''AMG''' This means instances are not visible in GHCi, because it tracks only `tcg_insts` (via the `InteractiveContext`). What to do here? Perhaps a new field in `TcGblEnv` could track the private instances?
    96104
    97105'''AMG''' I wanted to generate each `DFunId` for `Has` once, at the field's definition site, but this causes problems for the fields defined in `base`, as the `Has` class may not be available. I've reverted to generating fresh `DFunId`s locally to each module for which `-XOverloadedRecordFields` is used. Is there a better way to do this?
    98 
    99 As well as `Has` instances, instances of the type family `GetResult` are generated, and exactly the same question about dfun names applies to their axiom names.
    100106
    101107
     
    255261== To do ==
    256262
    257 * Improve error messages from typechecker:
    258   * Unsolved `Accessor p f` where `p` is something silly
     263* Improve unsolved `Accessor p f` error message where `p` is something silly?
    259264* Consider defaulting `Accessor p` to `p = (->)`, and defaulting `Has r "f" t` constraints where there is only one datatype with a field `f` in scope.
    260265* Sort out reporting of unused imports.
    261266* How should dfunids/axioms and instances be propagated?
    262 * Where should automatic instances be generated for GHCi?
     267* How should instances be made available to GHCi?
    263268* Document the extension, including new warnings.