Lennart

You are absolutely right about this.  It is a bug, but for the reason you
describes, not a disastrous one.  It should be cleaned up in Haskell 2 (ha!).

Simon

| From: Lennart Augustsson <[EMAIL PROTECTED]>
| Date: Fri, 10 Jan 92 21:57:44 +0100
|
|
| 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