Mercury List Unification

162 views Asked by At

I'm trying to learn Mercury. I've been messing around with lists, but I can't get a seemingly-simple unification to work. Here's my reduced example case:

main(!IO) :-
  [X,Y] = List,
  List = [1,2], % Error
  io.write(List, !IO),
  io.nl(!IO).

On the line List = [1,2] I get the following error (formatted and slightly edited):

main.m:024: In clause for `main(di, uo)':
mode error in unification of `List' and `list.[V_11 | V_21]'.
Variable `List' has instantiatedness
`unique(list.'[|]'(free, unique(list.'[|]'(free, unique((list.[]))))))', 
term `list.[V_11 | V_21]' has instantiatedness
`list.'[|]'( unique(1), free )'.

That doesn't seem right, though; specifically the instantiatedness of [1,2]. It's a literal; shouldn't its instantiatedness be, like, list.'[|]'( unique(1), list.'[|]'( unique(2), [] ) )?

Is this related somehow to the same partial-instantiation problem as here?

1

There are 1 answers

5
Paul Bone On BEST ANSWER

To compile a mode-correct program Mercury will re-order goals within a conjunction to try to make a mode-correct program, but before it does this it'll also break complex unfications up into parts. It looks like Mercury is struggling to re-order the parts of these two unifications to make a mode correct program, even though (from my looking) it should be possible. Try re-ordering the first two goals.