[m-dev.] Re: purity changes

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Apr 24 21:05:54 AEST 2000


On 24-Apr-2000, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> extras/trailed_update/var.m failed to compile:
> 
> var.m:942: In call to impure predicate `var:debug_pred/3':
> var.m:942:   purity error: call must be preceded by `impure' indicator.
> var.m:969: In call to impure predicate `var:debug_pred2/4':
> var.m:969:   purity error: call must be preceded by `impure' indicator.
> 
> The problem is:
> 
>                 freeze(X, debug_pred2(Msg, Pred), Y),
> 
> This is not allowed by the current purity system since debug_pred2 is
> impure.
> 
> I'm not sure how you want to handle this.

In the long run, I think we ought to support impure closures.
In the mean time, I think the following approach is probably best.
(I'll go ahead and commit this one.)

Estimated hours taken: 0.5

extras/trailed_update/var.m:
	Declare the impure predicates debug_pred/3 and debug_pred2/4
	as pure, rather than impure.  This is necessary because we use
	these predicates as arguments to the higher-order predicate
	freeze/3, and currently Mercury doesn't support impure
	closures.

Workspace: /home/pgrad/fjh/ws/hg
Index: extras/trailed_update/var.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/trailed_update/var.m,v
retrieving revision 1.14
diff -u -d -r1.14 var.m
--- extras/trailed_update/var.m	1999/10/28 16:29:08	1.14
+++ extras/trailed_update/var.m	2000/04/24 10:57:41
@@ -982,9 +982,19 @@
 		fail
 	).
 
-:- impure pred debug_pred(string, pred(T), T) is semidet.
+:- /* impure */
+   pred debug_pred(string, pred(T), T) is semidet.
 :- mode debug_pred(in, pred(in) is semidet, in) is semidet.
 
+	% XXX the `pragma promise_pure' here is a lie,
+	% but it's needed, because currently Mercury doesn't
+	% support taking the address of an impure procedure.
+	% The `pragma no_inline' is intended to reduce the
+	% likelihood of the false `pragma promise_pure' causing
+	% trouble.
+:- pragma promise_pure(debug_pred/3).
+:- pragma no_inline(debug_pred/3).
+
 debug_pred(Msg, Pred, Var) :-
 	impure unsafe_perform_io(print("woke: ")),
 	impure unsafe_perform_io(print(Msg)),
@@ -1006,8 +1016,18 @@
 		semidet_fail
 	).
 
-:- impure pred debug_pred2(string, pred(T1, T2), T1, T2) is semidet.
+:- /* impure */
+   pred debug_pred2(string, pred(T1, T2), T1, T2) is semidet.
 :- mode debug_pred2(in, pred(in, out) is semidet, in, out) is semidet.
+
+	% XXX the `pragma promise_pure' here is a lie,
+	% but it's needed, because currently Mercury doesn't
+	% support taking the address of an impure procedure.
+	% The `pragma no_inline' is intended to reduce the
+	% likelihood of the false `pragma promise_pure' causing
+	% trouble.
+:- pragma promise_pure(debug_pred2/4).
+:- pragma no_inline(debug_pred2/4).
 
 debug_pred2(Msg, Pred, X, Y) :-
 	impure unsafe_perform_io(print("woke: ")),

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