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

Ian MacLarty maclarty at csse.unimelb.edu.au
Sat Mar 31 12:17:40 AEST 2007


On Fri, Mar 30, 2007 at 12:36:17PM +1000, Ian MacLarty wrote:
> On Thu, Mar 29, 2007 at 02:35:10PM -0400, doug.auclair at logicaltypes.com wrote:
> > 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).
> > 
> 
> I think that:
> 
> print_kids(_, Kids, !IO) :-
>     Kids = [_ | _],
>     TheS = singular_plural(Kids).
> 
> will do the trick.
> 

The following should also work:

print_kinds(_, [_|_] @ Kids, !_IO) :-
	...

(i.e. swap around the arguments of the unification expression).

It seems that print_kids(_, Kids @ [_ | _], ...) is transformed into:

print_kids(_, H1, ...) :-
	H1 = Kids,
	H1 = [_ | _],
	...

while print_kids(_, [_ | _] @ Kids, ...) is transformed into:

print_kids(_, H1, ...) :-
	H1 = [_ | _],
	H1 = Kids,
	...

in the first case Kids ends up being ground, while in the second case it gets
the inst non_empty_list.  I'm not sure why this is the case though.

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