[mercury-users] inst of list in non-empty branch

doug.auclair at logicaltypes.com doug.auclair at logicaltypes.com
Fri Mar 30 04:35:10 AEST 2007

Dear Ralph (and all), you and I wrote:

>> print_kids(Element, Kids@[_|_], !IO) :-
>>          format("The child element%s of ", [s(singular_plural(Kids))], !IO),
>>          print(Element, !IO),
>>          is_are(Kids, !IO),
>>          print(Kids, !IO),
>>          nl(!IO).

>The mode for format/4 is pred(in, in, di, uo), so while the compiler
>knows that Kids has an inst matching non_empty_list before the call to
>format, it only knows it has inst ground afterwards.

Okay.  I think, however, that the mode for Kids is being set to just 'in'
anyway, because when I reduce the clause to:

print_kids(_, Kids@[_|_], !_IO) :-
        TheS = singular_plural(Kids).

-- recall that singular_plural/1's mode is in(non_empty_list) -- I still
get the same error:

test_xml_kids.m:071: In clause for `print_kids(in, in, di, uo)':
test_xml_kids.m:071:   in argument 1 of call to function
test_xml_kids.m:071:   `test_xml_kids.singular_plural'/1:
test_xml_kids.m:071:   mode error: variable `Kids' has instantiatedness
test_xml_kids.m:071:   `ground',
test_xml_kids.m:071:   expected instantiatedness was `bound(list.'[|]'(ground,
test_xml_kids.m:071:   ground))'.

This leads me to suspect that the mode for Kids is set to only 'in', even
in this non-empty-list clause.  ... I have seen the mode system set the
inst properly for other user-defined discriminated union types, particularly
when implementing different modes for different clauses (as illustrated in
the refman, sect 4.4) so it's puzzling why this particular example is being 

Is there a pragma or assertion where I can assign the inst to Kids? Is
there some call-out-to-C hackery that would force the inst assignment?

... or, if I had some time, how would you recommend I dig into the mode
system to implement changes for "mode-refinement-only" to the compiler?

Doug Auclair

mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au

More information about the users mailing list