[m-dev.] for review: allow multiple clauses in instance decls

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Sep 20 22:14:30 AEDT 2000


On 20-Sep-2000, David Glen Jeffery <dgj at students.cs.mu.oz.au> wrote:
> > +++ compiler/check_typeclass.m	2000/09/19 13:41:29
> 
> > +		%
> > +		% If all of the instance method definitions for this
> > +		% pred/func are clauses, and there are more than one
> > +		% of them, then we must combine them all into a
> > +		% single definition.
> > +		%
> > +		MethodToClause = (pred(Method::in, Clause::out) is semidet :-
> > +			Method = instance_method(_, _, Defn, _, _),
> > +			Defn = clauses([Clause])),
> > +		list__filter_map(MethodToClause, MatchingMethods, Clauses),
> > +		CombinedMethod = instance_method(PredOrFunc,
> > +			MethodName, clauses(Clauses),
> > +			MethodArity, FirstContext),
> > +		ResultList = [CombinedMethod]
> 
> This piece of code would throw away clauses that have already been bunched
> together. ie. it relies on there being only one clause in each 
> `instance_method'. I guess this would mean that you couldn't run this pass
> twice.
> 
> It is probably OK to just add a comment to this effect at the top of the
> module. Alternatively, you could list__condense the (probably singleton)
> lists of clauses... 

Good point.  I'll use list__condense.

> > Index: doc/reference_manual.texi
> > ===================================================================
> > RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
> > retrieving revision 1.187
> > diff -u -d -r1.187 reference_manual.texi
> > --- doc/reference_manual.texi	2000/09/18 11:52:09	1.187
> > +++ doc/reference_manual.texi	2000/09/19 14:15:52
> 
> > @@ -3479,7 +3486,11 @@
> >  	(method3(X, Y) :- Y = X + 2),
> >  
> >  	% method defined by a DCG rule
> > -	(method4(X) --> io__print(X), io__nl)
> > +	(method4(X) --> io__print(X), io__nl),
> > +
> > +	% method defined by multiple clauses
> > +	method5(no, _) = 0,
> > +	method5(yes, X) = Y :- X + Y = 0
> 
> Do you need parentheses around the second clause (ie. the non-fact clause)
> for method5?

Yes, thanks for spotting that.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list