Changes between Initial Version and Version 3 of Ticket #7346


Ignore:
Timestamp:
Oct 27, 2012 2:06:19 PM (3 years ago)
Author:
simonpj
Comment:

Some examples of what you have in mind would be useful. Perhaps update and elaborate the Wiki page about generic programming features in GHC?

But it sounds plausible.

Simon

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #7346

    • Property Owner set to dreixel
    • Property Cc leather@… added
    • Property Version changed from 7.6.1 to 7.7
    • Property Difficulty changed from to Unknown
  • Ticket #7346 – Description

    initial v3  
    33I propose to allow the use of `deriving` as well:
    44
    5 (1) Standalone deriving should be usable for a class not only for the specific set of classes supported by GHC now, but in addition for any class, if (A) there's at least one generic default given for a method of the class, and (B) there are generic or normal default implementations for *all* methods of the class.
     5 1. Standalone deriving should be usable for a class not only for the specific set of classes supported by GHC now, but in addition for any class, if (
     6    * there's at least one generic default given for a method of the class, and
     7    * there are generic or normal default implementations for *all* methods of the class.
    68
    7 There are a number of advantages of this solution over the empty instance declaration: we make it explicit that something generic is going on here; we ensure at compile time that we're not missing an implementation of a method; and we come syntactically closer to built-in derivable classes.
     9 There are a number of advantages of this solution over the empty instance declaration: we make it explicit that something generic is going on here; we ensure at compile time that we're not missing an implementation of a method; and we come syntactically closer to built-in derivable classes.
    810
    9 In cases where a conflict arises between current GHC semantics and the proposed semantics (for example, when newtype-deriving is involved, I guess), I propose to stick with current GHC semantics, but I'm open for other suggestions.
     11 In cases where a conflict arises between current GHC semantics and the proposed semantics (for example, when newtype-deriving is involved, I guess), I propose to stick with current GHC semantics, but I'm open for other suggestions.
    1012
    11 (2) I'd also like for normal `deriving` to be useful under the same conditions as above. For normal `deriving` GHC has to figure out the class context automatically. I propose that if normal `deriving` is used, GHC uses the same heuristic for figuring out the class context that it uses for `Eq` in the case of `*`-kinded classes, and for `Functor` in the case of `* -> *`-kinded classes. That may not be optimal or even wrong. But in such cases, standalone deriving can still be used.
     13 2. I'd also like for normal `deriving` to be useful under the same conditions as above. For normal `deriving` GHC has to figure out the class context automatically. I propose that if normal `deriving` is used, GHC uses the same heuristic for figuring out the class context that it uses for `Eq` in the case of `*`-kinded classes, and for `Functor` in the case of `* -> *`-kinded classes. That may not be optimal or even wrong. But in such cases, standalone deriving can still be used.