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

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


On 20-Sep-2000, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> 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.

Here's the relative diff.  Also I made some changes to the test
case which I forgot to include in my original post.
I'll go ahead and commit this change now.

--- check_typeclass.m.old	Wed Sep 20 22:23:12 2000
+++ check_typeclass.m	Wed Sep 20 22:38:40 2000
@@ -581,12 +581,13 @@
 		% of them, then we must combine them all into a
 		% single definition.
 		%
-		MethodToClause = (pred(Method::in, Clause::out) is semidet :-
+		MethodToClause = (pred(Method::in, Clauses::out) is semidet :-
 			Method = instance_method(_, _, Defn, _, _),
-			Defn = clauses([Clause])),
-		list__filter_map(MethodToClause, MatchingMethods, Clauses),
+			Defn = clauses(Clauses)),
+		list__filter_map(MethodToClause, MatchingMethods, ClausesList),
+		list__condense(ClausesList, FlattenedClauses),
 		CombinedMethod = instance_method(PredOrFunc,
-			MethodName, clauses(Clauses),
+			MethodName, clauses(FlattenedClauses),
 			MethodArity, FirstContext),
 		ResultList = [CombinedMethod]
 	;


tests/hard_coded/typeclasses/instance_clauses.m:
tests/hard_coded/typeclasses/instance_clauses.exp:
	Uncomment the commented-out parts of this test case,
	so that it tests the new feature.

Workspace: /home/pgrad/fjh/ws/hg
Index: tests/hard_coded/typeclasses/instance_clauses.exp
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/typeclasses/instance_clauses.exp,v
retrieving revision 1.1
diff -u -d -r1.1 instance_clauses.exp
--- tests/hard_coded/typeclasses/instance_clauses.exp	2000/09/08 06:02:21	1.1
+++ tests/hard_coded/typeclasses/instance_clauses.exp	2000/09/19 11:34:14
@@ -1,2 +1,2 @@
 [1, 2, 3]
-[101]
+[101, 102]
Index: tests/hard_coded/typeclasses/instance_clauses.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/typeclasses/instance_clauses.m,v
retrieving revision 1.1
diff -u -d -r1.1 instance_clauses.m
--- tests/hard_coded/typeclasses/instance_clauses.m	2000/09/08 06:02:22	1.1
+++ tests/hard_coded/typeclasses/instance_clauses.m	2000/09/19 11:33:23
@@ -29,9 +29,9 @@
 		; X = 1, Y = 3
 		; X = 2, Y = 4
 		)),
-	d(42, 101)
-%	d(42, 102),
-%	d(43, 102)
+	d(42, 101),
+	d(42, 102),
+	d(43, 103)
 ].
 
 :- pred mypred(T, T) <= thisclass(T).
-- 
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