[mercury-users] Thanks, and a concrete question

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Jun 3 06:16:20 AEST 2003

On 02-Jun-2003, Keith Braithwaite <keith at keithbraithwaite.demon.co.uk> wrote:
> Many thanks for the earlier comments on my code. I've a definite 
> question new about instantiatedness.
> I'd like to use ++ to roll test suites together. So I've introduced 
> this to my testing module
> :- func named_suite ++ named_suite = named_suite.  %interface
> S1 ++ S2 = suite_append(S1, S2).   %implementation
> :- func suite_append( named_suite, named_suite) = named_suite.
> :- mode suite_append(in,in) = out is det.
> :- import_module string.
> suite_append(
> 	named_suite(Name1,Tests1),
> 	named_suite(Name2,Tests2)) =
> 	named_suite(Name3,Tests3) :-
> 	Name3 = Name1 ++ " then " ++ Name2,
> 	list__append(Tests1,Tests2,Tests3).	
> This seems to be working, since this test passes.
> :- pred test_suite_concatenation is semidet.
> test_suite_concatenation :-
> 	Example_suite1 = named_suite("suite1", []),
> 	Example_suite2 = named_suite("suite2", []),
> 	Suite = Example_suite1 ++ Example_suite2,
> 	Suite ^ name = "suite1 then suite2",
> 	Suite ^ tests = (Example_suite1 ^ tests) ++ (Example_suite2 ^ tests).
> that's when running my two test suites like this:
> main(!IO) :-
> 	run_tests(mtest_tests__suite,!IO),
> 	run_tests(gotests__suite,!IO).

That all looks fine.

> However, when I change to this
> main(!IO) :-
> 	run_tests(mtest_tests__suite ++ gotests__suite,!IO).
> The compiler complains that
> test.m:016: In clause for `main(di, uo)':
> test.m:016:   in argument 1 of call to predicate `mtest:run_tests/3':
> test.m:016:   mode error: variable `V_7' has instantiatedness `ground',
> test.m:016:   expected instantiatedness was 
> `bound(mtest:named_suite(ground, bound([] ; '[|]'((mtest:case), 
> list:list_skel((mtest:case))))))'.
> Which I don't understand.

You didn't give quite enough context information.
I suspect that the problem lies with the mode declaration for
`mtest__run_tests/3', which you did not include in your post.
However, I can hazard some guesses...

The variable `V_7' will be the compiler-introduced temporary
that is the result of the call to `++'.  That has inst `ground',
which is just what we'd expect.  The compiler is complaining
that this inst does not match the complicated inst shown in the
error message which is what run_tests/3 expects, according to
the mode declaration for run_tests/3.  The problem is not that
the argument is insufficiently instantiated, since "ground" is as
instantantiated as it is possible to get; rather, the problem
seems to be that the argument could be any value of that type,
but the mode declaration for `run_tests/3' says that it is
expecting a specific subtype.

Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- 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