[mercury-users] Semidet functions

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Nov 19 16:02:36 AEDT 1999


On 19-Nov-1999, David Glen JEFFERY <dgj at cs.mu.OZ.AU> wrote:
> On 18-Nov-1999, Ralph Becket <rbeck at microsoft.com> wrote:
> > A while back I went through the standard library adding function versions
> > of all det predicates with a single output.
> 
> Just to throw a spanner into the works, Pete Ross found the following
> problem the other day:
> 
> :- pred p(pair(int), pair(int)).
> 
> p(X, Y) :-
> 	snd(X) = snd(Y).
> 
> This code looks fine at first glance, but because snd is both a predicate and
> a function, we get an error along the lines of:
> 
> x.m:013: In clause for predicate `x:p/2':
> x.m:013:   error: ambiguous overloading causes type ambiguity.
> x.m:013:   Possible type assignments include:
> x.m:013: V_5 :: (pred int) or int
> 
> The compiler doesn't know whether snd(X) is a curried predicate or a value of
> type int.
> 
> Ulch. A trap for the newcomer!

Indeed.  Also a potential backwards compatibility problem;
Ralph's changes to the standard library, which are included in our
development version, might break code written for Mercury 0.8.1.

A similar example to this one is

	foo(Pair) -->
		io__print(snd(Pair)).

Here you will actually get different output depending on how
the ambiguity is resolved.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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