Olaf
Noel Winstanley has a Haskell preprocessor that does more or less what
you want.
[EMAIL PROTECTED]
Simon
| From: Olaf Chitil <[EMAIL PROTECTED]>
| Date: Wed, 14 May 1997 16:24:59 +0200
| Why is the automatic derivation of instances for some standard classes
| linked to data and newtype declarations?
| It happened already several times to me that I needed a standard
| instance of a data type that I imported from a module that did not
| provide that instance and which I did not want to change (a library;
| GHC, which I mainly want to extend by further modules, not spread
| changes over 250 modules).
| When declaring a new data type one normally avoids deriving (currently)
| unneeded instances, because it costs program code (and maybe one even
| wants to enable the user of the module to define his own instances).
|
|
| Hence I suggest to introduce a new top level declaration like
|
| deriving <typeconstructor> (<class1>, ..., <classn>)
|
| e.g.
|
| data Tree a = Leaf a | (Tree a) :^: (Tree a)
| ...
| deriving Tree (Eq, Ord, Show)
| deriving Tree (Read)
|
|
| The current syntax would just be an abbreviation.
| I'm not quite sure if the syntax shouldn't be
|
| deriving (Tree a) (Eq, Ord, Show)
|
| because it is an instance for the type, not the type constructor.
| The type variable is, however, superfluous.
|
|
| Naturally all data constructors of a data type need to be in scope to
| permit derivation of instances.
| For separate compilation a module's interface file needs to include
| information about the order of constructors in the type declaration.
| GHC already does that.
|
|
| I know that attaching the order of data constructors to data types is
| not purely declarative. However, this is already the case for the
| current deriving construct, and attaching it to `data' and `newtype'
| just makes the construct less useful.
|
| Olaf
|
| --
| OLAF CHITIL, Lehrstuhl fuer Informatik II, RWTH Aachen, 52056 Aachen,
| Germany
| Tel: (+49/0)241/80-21212; Fax: (+49/0)241/8888-217
| URL: http://www-i2.informatik.rwth-aachen.de/~chitil/
|