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

Ralph Becket rafe at csse.unimelb.edu.au
Thu Mar 29 15:49:47 AEST 2007

doug.auclair at logicaltypes.com, Wednesday, 28 March 2007:
> Dear all, hello!
> This question is a two-parter: when I have a predicate branch on
> list insts, how do I tell the compiler when I am in the non-empty
> list branch that the inst of the list is indeed non_empty_list?
> Specifically, my pred print_kids/4 is structured thus:
> print_kids(Element, [], !IO) :-
>          print(Element, !IO),
>          print(" has no children\n", !IO).
> 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.

One could argue (strongly, IMO) that the mode system should be allowed
to assume that calls only refine insts...

Either way, the mode system implementation is a flaming can o' worms and
we don't currently have a willing PhD student to tackle the job.  Sorry!

-- Ralph
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