[m-dev.] for review: add `promise_only_solution_io'.

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Nov 30 16:46:14 AEDT 2000


Estimated hours taken: 0.75

library/builtin.m:
	Add `promise_only_solution_io'.
	This is like `promise_only_solution' except that
	it works for procedures that do I/O.

Workspace: /home/pgrad/fjh/ws/hg
Index: library/builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/builtin.m,v
retrieving revision 1.44
diff -u -d -r1.44 builtin.m
--- library/builtin.m	2000/11/23 01:59:53	1.44
+++ library/builtin.m	2000/11/30 05:36:54
@@ -147,6 +147,23 @@
 :- mode promise_only_solution(pred(out) is cc_multi) = out is det.
 :- mode promise_only_solution(pred(out) is cc_nondet) = out is semidet.
 
+% `promise_only_solution_io' is like `promise_only_solution', but
+% for procedures with unique modes (e.g. those that do IO).
+%
+% A call to `promise_only_solution_io(P, X, IO0, IO)' constitutes
+% a promise on the part of the caller that for the given IO0,
+% there is only one value of `X' and `IO0' for which P(X, IO0, IO) is true.
+% `promise_only_solution_io(P, X, IO0, IO)' presumes that this assumption
+% is satisfied, and returns the X and IO for which `Pred(X, IO0, IO)' is true.
+%
+% Note that misuse of this predicate may lead to unsound results:
+% if the assumption is not satisfied, the behaviour is undefined.
+% (If you lie to the compiler, the compiler will get its revenge!)
+
+:- pred promise_only_solution_io(pred(T, IO, IO), T, IO, IO).
+:- mode promise_only_solution_io(pred(out, di, uo) is cc_multi,
+		out, di, uo) is det.
+
 %-----------------------------------------------------------------------------%
 
 
@@ -218,6 +235,18 @@
                 "Y = X;").
 :- pragma c_code(cc_cast(X :: (pred(out) is cc_nondet)) =
                         (Y :: out(pred(out) is semidet)),
+                [will_not_call_mercury, thread_safe],
+                "Y = X;").
+
+promise_only_solution_io(Pred, X) -->
+	call(cc_cast_io(Pred), X).
+
+:- func cc_cast_io(pred(T, IO, IO)) = pred(T, IO, IO).
+:- mode cc_cast_io(pred(out, di, uo) is cc_multi) =
+	out(pred(out, di, uo) is det) is det.
+
+:- pragma c_code(cc_cast_io(X :: (pred(out, di, uo) is cc_multi)) =
+                        (Y :: out(pred(out, di, uo) is det)),
                 [will_not_call_mercury, thread_safe],
                 "Y = X;").
 

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- 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