| ... | ... | @@ -49,3 +49,14 @@ The only real change is that some of the default declarations are provided gener |
|
|
|
[ http://www.haskell.org/ghc/dist/current/docs/users_guide/type-extensions.html\#stand-alone-deriving](http://www.haskell.org/ghc/dist/current/docs/users_guide/type-extensions.html#stand-alone-deriving) describes an implementation of something very like this in GHC.
|
|
|
|
|
|
|
|
[ http://haskell.org/haskellwiki/GHC/Stand-alone_deriving_declarations](http://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).
|
|
|
|
|
|
|
|
|
|
|
|
As there are only a few fixed methods/classes that can be derived, we may choose not to have any special syntax for the few derived methods, but just put a comment in the code:
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
class Eq a where
|
|
|
|
(==) :: a -> a -> Bool
|
|
|
|
(/=) :: a -> a -> Bool
|
|
|
|
-- (==) has a magic way of be derived for datatypes
|
|
|
|
x /= y = not (x == y)
|
|
|
|
``` |
|
|
\ No newline at end of file |