Original-Via: uk.ac.nsf; Sat, 11 Jan 92 00:42:09 GMT
Original-Sender: [EMAIL PROTECTED]

I have some problems with modules again.  This time with instance
declarations.  Consider the following two modules:

  module M(C(..),T(..)) where           module N(C(..),T(..)) where
  import N                              import M
  class C a where                       type T = A | B
      c :: a

The interface files for these should be (whereever they come from):

  interface M where                     interface N where
  import N(T(..))                       import M(C(..))
  class C a                             class C a
      c :: a                                c :: a
  data T = A | B                        data T A | B

So far so good, now for the interesting part.  We add an instance declaration 
to M.
  instance C T where
      c = A

Now the interface files must be

  interface M where                     interface N where
  import N(T(..))                       import M(C(..))
  class C a                             class C a
      c :: a                                c :: a
  data T = A | B                        data T A | B
  instance C T                          instance C T

The instance declaration must appear in M's interface since C (and T)
is exported and the same is true for N.

If we instead add the instance declaration to N we get exactly the
same interface files.  This is a problem!

Let's assume that we have added the instance declaration to M, and now
we add one to N as well

  instance C T where
      c = B

and we then try to recompile N.  The program is now erroneous since there
are two (conflicting) instance declarations for 'C T', but there is no
way for the compiler to know that by just examining the text of the
module N and the interface of M.  (Why not?  Because the instance
declaration could as well have been in N to start with and then
everything would have been all right.)

This problem doesn't worry me to much since it will be caught at link
time (or whatever you call it when the program is finally stiched together).
But it does contradict the statement in the report that only the module
source and the imported interface files have to be examined to correctly
compile a module.

        -- Lennart



Reply via email to