| | 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 | 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 | {{{ |
| | 24 | instance Encode [a] -- works if there is an instance Representable0 [a] |
| | 25 | }}} |
| | 26 | |