On 17-Feb-2000, Brian Boutel <[EMAIL PROTECTED]> wrote:
> On Thursday, February 17, 2000 3:03 PM, Fergus Henderson 
> [SMTP:[EMAIL PROTECTED]] wrote:
> >>
> > If Haskell had explicit imports and exports of instance declarations,
> > then I could perhaps buy this argument.  But it doesn't.  In Haskell,
> > all instance declarations defined in a module are always exported;
> > there's no way to hide instance declarations that are intended to
> > be private to the module:
> >
> 
> This comes up occasionally. There really should be a FAQ for this sort of 
> thing.
> It is worth reminding people that there is a good reason for this rule - 
> not the original 1988 reason, but good enough.

Well, I remain unconvinced.  In Mercury, we give the user control
over whether instance declarations are exported or not, and it
works quite nicely, IMHO.  I think the problems that you are referring
to below are only problems if in addition to allowing private instance
declarations you also allow multiple or overlapping instance declarations.
But I would assign the blame for these problems to multiple/overlapping
instance declarations, not to having control of when instance
declarations are exported.

> Consider a function, which is exported, and which uses a local "private" 
> instance decl. What happens in the importing module?
> There are several possibilities:
> 1. The "private" instance decl from the other module is used.

That is what happens in Mercury.

> Then referential transparency is lost,

No necessarily...

> because if the name of the imported 
> function is replaced by its definition, any need for the instance will not 
> see the "private" instance declaration,

Yes, but the result in Mercury will be a compile (or link) error.

> and if it finds another instance 
> decl in scope, will use that, and the semantics of the function will be 
> changed.

In Mercury there can't be another matching instance declaration
in scope, since Mercury does not allow multiple or overlapping
instance declarations.  Thus we preserve referential transparency.

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]        |     -- the last words of T. S. Garp.

Reply via email to