[m-rev.] for review: try_func

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Jun 26 15:18:02 AEST 2001


On 26-Jun-2001, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> library/exception.m:
> 	Add a predicate, try_func, which is like try but takes a function, not
> 	a predicate, as its argument.
>  %
> +% try_func(Func, Result):
> +%    Operational semantics:
> +%	Call R = Func.
> +%	If Goal succeeds, succeed with Result = succeeded(R).
> +%	If Goal throws an exception E, succeed with Result = exception(E).
> +%    Declarative semantics:
> +%       try_func(Func, Result) <=>
> +%               ( R = Func, Result = succeeded(R)
> +%               ; Result = exception(_)
> +%		).

The odd indentation here is because you're mixing spaces and tabs.

The declarative semantics there has a type error;
it should contain `R = apply(Func)' rather than `R = Func'.

> +:- pred try_func((func) = T,	    exception_result(T)).
> +:- mode try_func((func) = out is det, out(cannot_fail)) is cc_multi.

There should be another mode for semidet functions:
:- mode try_func((func) = out is semidet, out) is cc_multi.

Also the semantics (both operational and declarative)
should handle the case where the function fails:

%    Operational semantics:
%	Call R = apply(Func).
%	If Func succeeds, succeed with Result = succeeded(R).
%	If Func throws an exception E, succeed with Result = exception(E).
%	If Func fails, succeed with Result = failed.
%    Declarative semantics:
%	try_func(Func, Result) <=>
%		( R = apply(Func), Result = succeeded(R)
%		; not (_ = apply(Func)), Result = failed
%		; Result = exception(_)
%		).

And there should be a test case.
There is in fact a file tests/hard_coded/exceptions/test_exceptions_func.m
which currently just contains duplicates of the tests of `try' in
test_exceptions.m.  That should be changed to instead test `try_func'.

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