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

David Glen JEFFERY dgj at students.cs.mu.oz.au
Wed Sep 20 12:06:53 AEDT 2000


On 20-Sep-2000, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> 
> Estimated hours taken: 5
> 
> Allow typeclass instance declarations to contain more than one clause
> for each method.
> 
> Also improve some error messages.

> Workspace: /home/pgrad/fjh/ws/hg
> Index: compiler/check_typeclass.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/check_typeclass.m,v
> retrieving revision 1.32
> diff -u -d -r1.32 check_typeclass.m
> --- compiler/check_typeclass.m	2000/09/08 06:01:53	1.32
> +++ 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... 

> 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?

Otherwise this diff is fine... commit away.


dgj
-- 
David Jeffery (dgj at cs.mu.oz.au) | If your thesis is utterly vacuous
PhD student,                    | Use first-order predicate calculus.
Dept. of Comp. Sci. & Soft. Eng.|     With sufficient formality
The University of Melbourne     |     The sheerist banality
Australia                       | Will be hailed by the critics: "Miraculous!"
                                |     -- Anon.
--------------------------------------------------------------------------
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