[m-rev.] for review: module qualification of equality preds

Simon Taylor stayl at cs.mu.OZ.AU
Tue May 20 00:00:08 AEST 2003


On 19-May-2003, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 19-May-2003, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > +++ doc/reference_manual.texi	19 May 2003 03:03:21 -0000
> > @@ -3466,6 +3466,9 @@
> >  The equality predicate must be ``pure'' (@pxref{Impurity}).
> >  
> >  @item
> > +The equality predicate must be defined in the same module as the type.
> > +
> > + at item
> >  @var{equalitypred} should be an equivalence relation; that is, it must be
> >  symmetric, reflexive, and transitive.  However, the compiler is not required
> >  to check this at footnote{If @var{equalitypred} is not an equivalence relation,
> > @@ -3534,6 +3537,9 @@
> >  
> >  @item
> >  The comparison predicate must also be ``pure'' (@pxref{Impurity}).
> > +
> > + at item
> > +The comparison predicate must be defined in the same module as the type.
> 
> Don't the equality and comparison predicates also need to be exported
> (i.e. declared in the interface section) if the type is exported?

Fixed.

> That seems to be what your test case is testing.
 
> It may be worth testing a few more cases, e.g.
> - the case of module A defining the equality predicate,
>   module B defining the type and importing A.
> - the case of module A defining the equality predicate and the type,
>   and module B importing module A and defining another predicate with
>   the same name as the equality predicate.

That's what the given test case was testing. I've added tests for the
other cases you list.

Simon.

Index: doc/reference_manual.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.274
diff -u -u -r1.274 reference_manual.texi
--- doc/reference_manual.texi	13 Apr 2003 05:22:10 -0000	1.274
+++ doc/reference_manual.texi	19 May 2003 05:20:00 -0000
@@ -3466,6 +3466,12 @@
 The equality predicate must be ``pure'' (@pxref{Impurity}).
 
 @item
+The equality predicate must be defined in the same module as the type.
+
+ at item
+If the type is exported the equality predicate must also be exported.
+
+ at item
 @var{equalitypred} should be an equivalence relation; that is, it must be
 symmetric, reflexive, and transitive.  However, the compiler is not required
 to check this at footnote{If @var{equalitypred} is not an equivalence relation,
@@ -3534,6 +3540,12 @@
 
 @item
 The comparison predicate must also be ``pure'' (@pxref{Impurity}).
+
+ at item
+The comparison predicate must be defined in the same module as the type.
+
+ at item
+If the type is exported the comparison predicate must also be exported.
 
 @item
 The relation
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.135
diff -u -u -r1.135 Mmakefile
--- tests/invalid/Mmakefile	17 Feb 2003 06:02:22 -0000	1.135
+++ tests/invalid/Mmakefile	19 May 2003 13:51:45 -0000
@@ -16,6 +16,8 @@
 	aditi_update_errors \
 	aditi_update_mode_errors \
 	duplicate_instance_2 \
+	exported_unify \
+	exported_unify3 \
 	ho_default_func_2.sub \
 	import_in_parent \
 	imported_mode \
Index: tests/invalid/exported_unify3.err_exp
===================================================================
RCS file: tests/invalid/exported_unify3.err_exp
diff -N tests/invalid/exported_unify3.err_exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/exported_unify3.err_exp	19 May 2003 13:56:43 -0000
@@ -0,0 +1,7 @@
+exported_unify3.m:005: In clause for unification predicate for type (exported_unify3.foo):
+exported_unify3.m:005:   error: undefined predicate `exported_unify3.defined_in_wrong_module/2'.
+exported_unify3.sub.int:003: In clause for unification predicate for type ((exported_unify3.sub).bar):
+exported_unify3.sub.int:003:   error: undefined predicate `exported_unify3.sub.not_exported/2'.
+exported_unify3.int0:003: In clause for unification predicate for type (exported_unify3.foo):
+exported_unify3.int0:003:   error: undefined predicate `exported_unify3.defined_in_wrong_module/2'.
+For more information, try recompiling with `-E'.
Index: tests/invalid/exported_unify3.m
===================================================================
RCS file: tests/invalid/exported_unify3.m
diff -N tests/invalid/exported_unify3.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/exported_unify3.m	19 May 2003 13:56:39 -0000
@@ -0,0 +1,33 @@
+:- module exported_unify3.
+
+:- interface.
+
+:- type foo ---> foo where equality is defined_in_wrong_module.
+
+	:- module exported_unify3.sub.
+
+	:- interface.
+
+	:- type bar ---> bar where equality is not_exported.
+
+	:- pred defined_in_wrong_module(foo::in, foo::in) is semidet.
+
+	:- end_module exported_unify3.sub.
+
+:- implementation.
+
+:- import_module exported_unify3.sub.
+
+	:- module exported_unify3.sub.
+
+	:- implementation.
+
+	:- import_module std_util.
+
+	defined_in_wrong_module(_, _) :- semidet_fail.
+
+	:- pred not_exported(bar::in, bar::in) is semidet.
+
+	not_exported(_, _) :- semidet_fail.
+
+	:- end_module exported_unify3.sub.
--------------------------------------------------------------------------
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