Changes between Version 33 and Version 34 of Commentary/Compiler/GenericDeriving


Ignore:
Timestamp:
May 9, 2011 7:36:18 AM (3 years ago)
Author:
dreixel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/GenericDeriving

    v33 v34  
    11= The new Generic Deriving mechanism (ongoing work) = 
    22 
    3 GHC includes a new (in 2010) mechanism to let you write generic functions.  It is described in [http://www.dreixel.net/research/pdf/gdmh_nocolor.pdf A generic deriving mechanism for Haskell], by Magalhães, Dijkstra, Jeuring and Löh.  This page sketches the specifics of the implementation; we assume you have read the paper. 
     3GHC includes a new (in 2010) mechanism to let you write generic functions.  It is described in [http://www.dreixel.net/research/pdf/gdmh_nocolor.pdf A generic deriving mechanism for Haskell], by Magalhães, Dijkstra, Jeuring and Löh.  This page sketches the specifics of the implementation; we assume you have read the paper. The [http://www.haskell.org/haskellwiki/Generics HaskellWiki page] gives a more general overview. 
    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 the `ghc-generics` branch of the [https://github.com/ghc/ghc/commits/ghc-generics ghc], [https://github.com/ghc/packages-base/commits/ghc-generics base], [https://github.com/ghc/packages-ghc-prim/commits/ghc-generics ghc-prim], and [https://github.com/ghc/testsuite/commits/ghc-generics testsuite] repos. 
    6  
    7 == Changes from the paper == 
    8  
    9 In 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 {{{ 
    15 class Encode a where 
    16   encode :: a -> [Bit] 
    17   default 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 {{{ 
    24 instance Encode [a] -- works if there is an instance Representable0 [a] 
    25 }}} 
    26    
    276 
    287== Main components ==