RE: Mutually recursive modules and derived instances of Data

| If I have two modules which are mutually recursive; | | module A where | import B | data TA = TA TB deriving (Data, Typeable) | | module B where | import A | data TB = TB TA deriving (Data, Typeable) | | How do I go about writing a hi-boot that will work in GHC? Good question. At the moment, GHC does not let you put instance declarations in hi-boot files, mainly because instances (being anonymous) are a bit weird. Usually this is OK -- just put the instances outside the loop. But if you want to derive the instances (which is Jolly Convenient) you can't do that. At the moment all you can do is write the instances by hand; sorry. (-ddump-deriv will show you the code GHC itself generates, which you can more or less cut and paste) Two fixes suggest themselves 1. Separate 'deriving' from the data type decl, so you can say derive( Data TA, Typeable TA ) anywhere. People sometimes ask for this for other reasons. 2. Allow instances in hi-boot files You might say "both would be useful", but I'd be interested in people's opinions about which of (1) or (2) would be preferable if you could only have one or t'other. Simon

On Wed, 13 Oct 2004 13:21:26 +0100, Simon Peyton-Jones
1. Separate 'deriving' from the data type decl, so you can say derive( Data TA, Typeable TA ) anywhere. People sometimes ask for this for other reasons.
2. Allow instances in hi-boot files
You might say "both would be useful", but I'd be interested in people's opinions about which of (1) or (2) would be preferable if you could only have one or t'other.
1! As you say, people sometimes ask for this for other reasons. I'm one of them, though I'm not sure if I've actually asked about it on the list. Separating deriving from the declaration would be incredibly useful. /Martin

Hi Simon! On Wed, Oct 13, 2004 at 01:21:26PM +0100, Simon Peyton-Jones wrote:
Two fixes suggest themselves
1. Separate 'deriving' from the data type decl, so you can say derive( Data TA, Typeable TA ) anywhere. People sometimes ask for this for other reasons.
Good thing. Plus, allow to hook in Template Haskell at some point, so that import DeriveMyClass derive(MyClass TA) is equivalent to import DeriveMyClass $( deriveMyClass (reifyDecl TA) ) (or whatever the TH-syntax will be at that point :-) Then data TA = ... deriving (MyClass) should also be possible. The advantage would be that only the module defining the deriving would have to know about TH, not the one using it. On other systems, the deriving could then be realized via a pre-processor or similar means. Greetings, Carsten -- Carsten Schultz (2:38, 33:47), FB Mathematik, FU Berlin http://carsten.codimi.de/ PGP/GPG key on the pgp.net key servers, fingerprint on my home page.
participants (3)
-
Carsten Schultz
-
Martin Sjögren
-
Simon Peyton-Jones