[mercury-users] Modes problem

Simon Taylor stayl at cs.mu.OZ.AU
Sat May 19 00:47:32 AEST 2001


On Fri, May 18, 2001 at 04:09:08PM +0200, Ondrej Bojar wrote:
> What I am trying to do is this (simplified version of the problem):
> 
> :- pred test(list(pair(string))::in).
> 
> test([Head|Tail]) :-
>   Head = pair(A,A).
> 
> The predicate test should succeed if and only if the given list (is
> nonempty and) starts with a pair of identic structures.
> 
> Here, the error is similar:
> 
> pok.m:007: In clause for `test(in)':
> pok.m:007:   in argument 1 of call to function `std_util:pair/2':
> pok.m:007:   mode error: variable `A' has instantiatedness `free',
> pok.m:007:   expected instantiatedness was `ground'.

The function std_util__pair has only the default forwards mode.
:- func pair(T1, T2) = pair(T1, T2).
:- mode pair(in, in) = out is det.

In your code the output variable (Head) is bound before
the call to std_util__pair, the inputs (A) are not.

The code below will work. Data constructors can be used in any mode.

test([Head|Tail]) :-
	Head = A - A.

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