[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Two problems



Original-Via: uk.ac.nsf; Wed, 30 Jan 91 04:18:25 GMT
To: Lennart Augustsson <augustss>
Cc: simonpj@cs.glasgow.ac.uk, haskell@cs.glasgow.ac.uk,
        s.blott@cs.glasgow.ac.uk, brian@comp.vuw.ac.nz
Subject: Re: Two problems
In-Reply-To: Your message of "Tue, 29 Jan 91 21:58:09 BST." <9101292057.AA23308@birk.cs.chalmers.se>
Date: Wed, 30 Jan 91 17:17:22 +1300
From: brian@comp.vuw.ac.nz
Sender: haskell-request@cs.glasgow.ac.uk

Lennart,

	I did not want my local instance declarations to be exported, I
would be quite
	satisfied (for the moment) if I could make an instance
declaration in a module
	(not containing the class&type declaration) and use it just in that module.
	I.e. I would like to change the visibility rules to say that an
instance declaration
	is exported only if it is the same module as the class and/or
type declaration.

There are problems with this too. Suppose an instance
declaration for the class C and type T occurs in another module, then
it will always be imported into your module along with the class and type.
If you shadow it with your local instance declaration, and export either
the class or the type, then the instance declaration (which one?)
is automatically exported as well. The interface for your module will say
that type T is an instance of class C, the implementation part of your
module will give a full instance declaration, but it will not be the
declaration  referred to in the interface. You will only be able to tell
this because both the class C and type T are imported, and the interface will
contain import declarations for them both (to show their original names).
Now this will actually work, but it's dreadfully confusing. 

This problem is avoided by not exporting either C or T, in
which case the instance declaration will not appear in the interface, but
this may mean that another module which imports your module now has to
import another module as well, just to get the class and type declarations.

Another, nastier, problem is that you introduce a form of dynamic scoping.
If you can have different C-T instance declarations local to different 
modules, a function which uses the operators of the class C at
type T can have different semantics depending on where it is used. In the 
usual description of how this is implemented, when the function is called
with arguments of type T, the appropriate method dictionary is also passed 
to it, and this will be derived from the C-T instance declaration in scope
at the point of use.


--brian