[mercury-users] inferred determinism
Peter Schachte
schachte at cs.mu.OZ.AU
Wed Feb 27 00:42:59 AEDT 2002
On Tue, Feb 26, 2002 at 04:56:43PM +1100, Fergus Henderson wrote:
> > foo(zero, []).
> > foo(N, [_|Xs]) :- foo(N0, Xs), N = N0+1.
> 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.)
That makes sense for code generation, but not for determinism
checking. Whether or not zero/0 loops, foo/2 is still deterministic
providing only that zero/0 and +/2 are deterministic.
Come to think of it, I don't see why it's even right for code
generation. Even if for semantics reasons you don't want to consider
the second argument before the first, why can't you do the switch
*after* the call to zero/0. Sure, it's too late to avoid the
choicepoint, but you can still cut it away and jump straight to the
right clause.
--
Peter Schachte Everything should be made as simple as possible,
schachte at cs.mu.OZ.AU but not simpler.
www.cs.mu.oz.au/~schachte/ -- Albert Einstein, Reader's Digest. Oct. 1977
Phone: +61 3 8344 9166
--------------------------------------------------------------------------
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