Mutually recursive modules and derived instances of Data
simonpj at microsoft.com
Wed Oct 13 08:21:26 EDT 2004
| 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.
More information about the Glasgow-haskell-users