[m-rev.] for review; typeclass decl introduces namespace

Peter Ross peter.ross at miscrit.be
Thu Nov 1 00:48:01 AEDT 2001


On Wed, Oct 31, 2001 at 09:01:44PM +1100, Fergus Henderson wrote:
> On 30-Oct-2001, Peter Ross <peter.ross at miscrit.be> wrote:
> > 
> > Typeclass declarations now introduce a new namespace.  For example the
> > method, f, in typeclass, tc, in module, mod, has the fully qualified
> > name mod__tc__f instead of mod__f.  This allows typeclasses defined
> > at the same scope to have methods with the same name.
> ...
> > Index: compiler/prog_io_typeclass.m
> > @@ -625,12 +625,13 @@
> >  		% instance declaration for, but we don't necessarily
> >  		% know what module that is at this point, since the
> >  		% class name hasn't been fully qualified yet.
> > -		% So here we give the special module name ""
> > -		% as the default, which means that there is no default.
> > +		% So here we give the only part of the module name that
> > +		% we do know which is the unqualified instance name.
> >  		% (If the module qualifiers in the clauses don't match
> >  		% the module name of the class, we will pick that up later,
> >  		% in check_typeclass.m.)
> > -		DefaultModuleName = unqualified(""),
> > +		unqualify_name(InstanceName, UnqualifiedInstanceName),
> > +		DefaultModuleName = unqualified(UnqualifiedInstanceName),
> >  		parse_item(DefaultModuleName, VarSet, MethodTerm, Result0),
> 
> I don't think that is correct.
> 
> In particular, I think that will lead to an error for
> 
> 	:- module foo.
> 	:- interface.
> 	:- typeclass tc(T) where [
> 		func foo__tc__bar(T) = int
> 	].
> 
> since `foo__tc' won't match `tc'.
> 
The above piece of code is only for handling instance methods (not
typeclass) methods where the code is defined inline.  The comment above
the code talks about the following case (I think).

:- module foo.
:- interface.
:- import_module tc.  % which contains the tc declaration
:- instance tc(T) where [
    bar(_) = 5
].

Anyway I am starting to lean towards just implementing Simons or your
proposal.  I believe the current proposal can cause problems when you
want to use submodules with the same name (which in my case is
guaranteed) as then you can end up with duplicate names.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list