[mercury-users] List instantiation question

Ralph Becket rafe at cs.mu.OZ.AU
Thu Mar 2 16:51:26 AEDT 2006

doug.auclair at logicaltypes.com, Thursday,  2 March 2006:
> Dear all,
> I have a list of a known length (a priori) but currently unknown
> element values (the /types/ of the elements /are/ known, e.g.: int)
> which I am attempting to fill: 
> A = 3, B = 7,
> Stuff = [_, _, _, _],
> populate_stuff(Stuff, A, B).
> where 
> populate_stuff([], _, _).
> populate_stuff([H|T], A, B) :-
>   do_something(H, A, B, NewB),
>   populate_stuff(T, A, NewB).
> The question is: what mode for populate_stuff/3 compiles successfully?
> Since Stuff's skeleton is bound it would appear to be a
> list_skel_in(?) -- the '?' token is where I am stuck: 'free' makes the
> compiler complain that the final instantiatedness of the actual
> argument is too ground, but 'bound(int)' fares no better. Mode
> 'list_skel_out' has similar problems. 
> Is this a 'do not do it this way because of inst issues' problem?

The short answer is, "yes".

Longer answer: the compiler currently doesn't support partially
instantiated structures like this and there is plenty of debate as to
whether it is a good thing to support at all, in terms of
maintainability of programs, even if we did know how to do such a thing

> Is there some list mode that I am not aware of that solves this issue?

Not really.

Whenever someone tries to do something Prologesque like this it's
usually an efficiency hack.  Mercury's optimisations are powerful enough
that just doing things the simple way (i.e., using ground values
throughout) will often generate just as efficient code as you'd expect
from a Mercury that did support partial instantiation.

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