[mercury-users] New to mercury: structure reuse and efficiency

Ralph Becket rafe at cs.mu.OZ.AU
Mon Jul 5 09:07:00 AEST 2004

Maurizio Colucci, Sunday,  4 July 2004:
> On Monday 21 June 2004 21:40, Ralph Becket wrote:
> > That's a fair description although we don't support full Prolog style
> > unification
> Could you please explain what you mean by that? Or point me to some
> docs that explain it? In what sense Mercury's unification is different
> from Prolog's?


The main difference is that Prolog supports variable aliasing whereas
Mercury does not.  Aliasing occurs when two as-yet unbound variables are
unified; when you later bind one of those variables, it is as if also
bind the other at the same time.

Consider the following bit of Prolog:

p(A, B, C) :-
	A = B,
	B = C.

A call p(P, Q, R) (with P, Q, R initially free) will succeed, aliasing
P, Q and R together.  None of these variables has been bound to a value
yet, but they all now represent the same logical variable.

If we then bind P, say, with P = 42, then Q and R also simultaneously
become bound to 42 because they are aliased with P.

Mercury does not support variable aliasing that is visible outside the
body of a predicate definition because there are significant costs
associated with doing so.  You can write code that looks as though it is
aliasing variables within a predicate definition, but such code will
only be accepted if the Mercury compiler can rearrange the code so that
the apparent aliasing "goes away".

(We are currently working on adding support for types with Prolog
style unification as a special case of more general support for
constraint logic programming.)

Does this help?

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