[mercury-users] inferred determinism

Mark Brown dougl at cs.mu.OZ.AU
Wed Feb 27 01:51:01 AEDT 2002


On 26-Feb-2002, Thomas Conway <conway at cs.mu.OZ.AU> wrote:
> On Tue, Feb 26, 2002 at 04:56:43PM EST, Fergus Henderson wrote:
> > On 26-Feb-2002, Michael Day <mikeday at bigpond.net.au> wrote:
> > > 
> > > The compiler infers a determinism of nondet for the predicate foo below,
> > > unless the call to `zero' in the first clause is replaced by the literal
> > > value 0. But it's an output argument, so why should it care?
> > > 
> > > :- pred foo(int, list(T)).
> > > :- mode foo(out, in) is det.
> > > 
> > > foo(zero, []).
> > > foo(N, [_|Xs]) :- foo(N0, Xs), N = N0+1.
> > > 
> > > :- func zero = int.
> > > zero = 0.
> > 
> > Switch detection will not look past function calls.
> > It only looks for unifications that occur before the
> > first function call or predicate call in the clause.
> > (One reason for this is that moving unifications across function
> > calls could change whether or not the program terminates;
> > e.g. consider the case where `zero' loops.)
> 
> This argument only applies in the case of the strict sequential model.

The switch detection rules are used to determine whether or not a Mercury
program is legal, and the legality of a Mercury program should not depend
on which operational semantics is being used.  Hence that argument is
still valid.

Having said that, perhaps the definition of "minimally reordered" (in
the 'Semantics' chapter of the reference manual) could be changed to
accommodate this?  For example, in addition to the other reorderings
allowed in the strict sequential model, we could allow function calls to
be delayed until after test unifications if this is necessary for switch
detection.  Then the argument above would no longer apply, although
there may yet be other reasons not to allow such switches.

Cheers,
Mark.

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