Changes between Version 1 and Version 2 of DerivingInstances


Ignore:
Timestamp:
Apr 15, 2008 1:10:23 AM (6 years ago)
Author:
john@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DerivingInstances

    v1 v2  
    33== Brief Explanation == 
    44 
    5 In Haskell 98, the methods of some classes can be created using a deriving clause immediately after a datatype. e.g. 
     5In Haskell 98, the methods of some basic classes can be created using a deriving clause immediately after a datatype. e.g. 
    66{{{ 
    77data Color = Red | Yellow | Blue 
    88   deriving (Eq, Ord) 
    99}}} 
    10 Tying the '''deriving''' declaration to the datatype: 
     10There are some downsides to this. For example, tying the '''deriving''' declaration to the datatype: 
    1111 * mixes the class system into datatypes (making the report hard to sequentialize), and 
    1212 * means that programmers have to decide which classes they are interested in at the point of defining the datatype. 
     
    1414 
    1515This proposal calls for the point of the deriving declaration to be moved into the class system itself: 
    16  * Derived methods are provided as such in the class declaration, as a kind of default; 
    17  * Instances are declared as empty (or partial) instance declarations in a way that is already used for default mechanisms. 
     16 * Derived methods are declared in the class declaration, as a kind of default; 
     17 * Instances are declared using empty (or partial) instance declarations in a way that is already used for default mechanisms. 
    1818 
    1919For example: 
     
    3131The only real change is that some of the default declarations are provided generically, rather than polymorphically. This shift makes Haskell a little more regular, but it also sets us up nicely for the future if we ever add a mechanism to allow programmers to define generic definitions for their own classes. In H', we would limit ourselves to the existing set of generic definitions that currently can occur in deriving clauses. In a future version of Haskell we may choose to provide a generic programming mechanism whose use would appear in this same place. The design is trying to be relatively future-proof. 
    3232 
     33== Discussion == 
     34 
     35http://haskell.org/haskellwiki/GHC/Stand-alone_deriving_declarations contains a great discussion of some of these ideas. (NB. Section 3 is misleading: leaving the clauses out of an instance declaration ''does not'' leave all the methods undefined; rather it gives the default methods of the class). 
    3336 
    3437