Changes between Version 16 and Version 17 of Commentary/Compiler/GenericDeriving


Ignore:
Timestamp:
Apr 5, 2011 7:15:24 AM (3 years ago)
Author:
dreixel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/GenericDeriving

    v16 v17  
    44 
    55This mechanism replaces the [http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/generic-classes.html previous generic classes implementation]. The code is in a branch of GHC; you can get it with `darcs get http://darcs.haskell.org/ghc-generic-15Feb11/ghc`. 
     6 
     7== Changes from the paper == 
     8 
     9In the paper we describe the implementation in [http://www.cs.uu.nl/wiki/UHC UHC]. The implementation in GHC is slightly different: 
     10 
     11 * We are using type families, so the Representable0 and Representable1 type classes have only one type argument. So, in GHC the classes look like what we describe in "Avoiding extensions" part of Section 2.3 of the paper. This change affects only a generic function writer, and not a generic function user. 
     12 
     13 * Default definitions (Section 3.3) work differently. In GHC we don't use a `DERIVABLE` pragma; instead, a type class can declare a ''generic default method'', which is akin to a standard default method, but includes a generic type signature. For example, the `Encode` class of Section 3.1 is now: 
     14{{{ 
     15class Encode a where 
     16  encode :: a -> [Bit] 
     17  generic encode :: (Representable0 a, Encode1 (Rep a)) => a -> [Bit] 
     18  encode = encode1 . from0 
     19}}} 
     20   This removes the need for a separate default definition and a pragma. 
     21 
     22 * To derive generic functionality to a user type, the user no longer uses ``deriving instance`` (Section 4.6.1). Instead, the user gives an instance without defining the method; GHC then uses the generic default. For instance: 
     23{{{ 
     24instance Encode [a] -- works if there is an instance Representable0 [a] 
     25}}} 
     26   
    627 
    728== Main components ==