[m-dev.] for review: allow impurity on class methods

David Glen JEFFERY dgj at ender.cs.mu.oz.au
Mon Mar 27 14:38:42 AEST 2000


On 26-Mar-2000, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> 
> A test case containing errors is very useful too.

How about this, then:

Index: Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/invalid/Mmakefile,v
retrieving revision 1.59
diff -u -t -r1.59 Mmakefile
--- Mmakefile	2000/03/14 18:27:47	1.59
+++ Mmakefile	2000/03/27 04:28:20
@@ -31,6 +31,7 @@
         funcs_as_preds.m \
         ho_type_mode_bug.m \
         ho_unique_error.m \
+        impure_method_impl.m \
         inline_conflict.m \
         inst_list_dup.m \
         io_in_ite_cond.m \

New file: impure_method_impl.m
===================================================================

:- module impure_method_impl.
:- interface.

:- import_module io.

:- pred main(io__state::di, io__state::uo) is det.

:- typeclass c(T) where [
	pred m1(T::in, int::out) is det,
	semipure pred m2(T::in, int::out) is det
].

:- type foo ---> foo.

:- instance c(foo) where [
	pred(m1/2) is foo_m1,
	pred(m2/2) is foo_m2
].

:- semipure pred foo_m1(foo::in, int::out) is det.
:- impure pred foo_m2(foo::in, int::out) is det.

:- implementation.

main -->
	[].

:- pragma c_header_code("int foo_counter = 0;").

:- pragma c_code(foo_m1(_F::in, Val::out), "Val = foo_counter;").
:- pragma c_code(foo_m2(_F::in, Val::out), "Val = foo_counter++;").


New file: impure_method_impl.err_exp
===================================================================
impure_method_impl.m:017: In call to impure predicate `impure_method_impl:foo_m2/2':
impure_method_impl.m:017:   error: call must be preceded by `impure' indicator.
impure_method_impl.m:017: In type class method implementation:
impure_method_impl.m:017:   error: predicate is impure.
impure_method_impl.m:017:   It must be declared `impure' or promised pure.
impure_method_impl.m:016: In call to semipure predicate `impure_method_impl:foo_m1/2':
impure_method_impl.m:016:   error: call must be preceded by `semipure' indicator.
impure_method_impl.m:016: In type class method implementation:
impure_method_impl.m:016:   error: predicate is semipure.
impure_method_impl.m:016:   It must be declared `semipure' or promised pure.
For more information, try recompiling with `-E'.


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