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

Mark Anthony BROWN dougl at cs.mu.OZ.AU
Thu Nov 30 16:55:29 AEDT 2000


Fergus Henderson writes:
> 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.
> 

This should be mentioned in NEWS.

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

s/`IO0'/`IO'/

> +% `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;").
>  
> 

Aside from those comments, this change looks fine.

Cheers,
Mark.

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