[mercury-users] Determinism question

Simon Taylor stayl at cs.mu.OZ.AU
Fri Sep 7 00:49:47 AEST 2001


On 06-Sep-2001, Nicholas James Nethercote <njn at cs.mu.OZ.AU> wrote:
> I'm wondering about what happens when you have a conjunction of the form
> (semidet, erroneous)... the compiler infers such a conjunction as `failure'.
> For example:

> :- pred interesting_case(int::in).
> interesting_case(X) :-
>     semidet_pred(X),
>     error("foo").
 
> The Mercury Reference Manual says this about `failure' and `erroneous':
> 
>     If all possible calls to a particular mode of a predicate or function fail
>     without producing a solution, then that mode has a determinism of failure. 
> 
>     If all possible calls to a particular mode of a predicate or function lead
>     to a runtime error, i.e. neither succeed nor fail, then that mode has a
>     determinism of erroneous.
> 
> But then it has this summary diagram:
> 
>                     Maximum number of solutions
>     Can fail?       0               1               > 1
>     no              erroneous       det             multi
>     yes             failure         semidet         nondet
> 
> The information is subtly different - if we are working from the table, the
> procedure is clearly `failure';  if we are working from the sentences,
> the case isn't really covered.  
> 
> So are the sentences just imprecisely worded, or is there some deeper
> explanation?

It is slightly imprecise. The description is supposed to mean all possible
calls which return to the caller (calls which terminate, do not throw
an exception, and do not cause a fatal runtime error). For predicates
and functions with determinism erroneous, there are no possible calls
which return to the caller.

In your example, for all calls which do not call error/1,
`interesting_case/1' fails, so its inferred determinism is failure.
 
> And another thing - if interesting_case/1 above is inferred as failure, is
> there a possibility that a call to it might be optimised away and replace with
> `fail'?  Because that would change the behaviour of the above program.  Or
> does the compiler check whether a `failure' procedure might throw an error
> before it optimises it away like that?

This is discussed in the "Semantics" chapter of the Mercury Language
Reference Manual. If the `--fully-strict' option is set (as it is by
default), the compiler will never optimize away goals which might never
return to the caller.  Replacing `interesting_case/1' with `fail' would
remove a possible call to error/1.

Simon.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list