[mercury-users] functions vs predicates (was Re: State variable problem
Peter Moulder
Peter.Moulder at infotech.monash.edu.au
Fri Jul 21 23:23:06 AEST 2006
On Wed, May 31, 2006 at 11:29:44AM +1000, Ralph Becket wrote:
> I used to think the same way [that function calls are just an
> alternative syntax for predicate calls], but I've been convinced
> otherwise. The main thing is that with functions it is natural to
> assume referential transparency.
That may well be a natural assumption, but it's unfortunately a false
one in Mercury: that is, the code
f \= f
can succeed (where f is a function application in the usual forward
direction) even though
Z = f,
Z \= Z
always fails. (Even if the NaN problem were fixed.)
This problem arises with function applications that fail: f \= f is
converted to not(f = f), which becomes not(f = Tmp1, f = Tmp2, Tmp1 =
Tmp2), where the `f = Tmp' calls are treated like predicate calls:
failure of the call means success of the `not' goal, i.e. success of
f \= f.
This is one reason that it's discouraged for the forward mode of a
function (i.e. f(in, in, ..., in) = out) to have determinism semidet (or
failure), and why the standard library would usually use a predicate
instead for such cases.
pjrm.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at csse.unimelb.edu.au
administrative address: owner-mercury-users at csse.unimelb.edu.au
unsubscribe: Address: mercury-users-request at csse.unimelb.edu.au Message: unsubscribe
subscribe: Address: mercury-users-request at csse.unimelb.edu.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list