[mercury-users] partially instantiated data structures

Peter Schachte schachte at cs.mu.OZ.AU
Fri Jul 16 14:08:12 AEST 1999

On Fri, Jul 16, 1999 at 12:50:03PM +1000, Fergus Henderson wrote:
> On 16-Jul-1999, Thomas Conway <conway at cs.mu.OZ.AU> wrote:
> > When would you use partially instantiated data structures (if you
> > could) in Mercury? 
> One important case which Jeff Schultz brought to my attention is when
> you are writing a multi-pass compiler (or other data structure transformation)
> where each pass fills in a different field of a data structure.
> (In fact the Mercury solution in such cases is quite likely just as
> efficient as the Prolog solution, despite the copying, because of the
> efficiency advantages of Mercury's compile-time mode analysis.

I don't think that's a very meaningful comparison.  If you're saying
that "well, Prolog may be a bit faster here, but Mercury is so much
faster everywhere else that it wins overall," then I certainly agree,
but that doesn't mean Mercury couldn't use a variant of the Prolog
implementation strategy and do even better (ie, an aliased variable is
represented as a pointer to the cell to overwrite with the final
value).  As long as you have a det goal somewhere that binds the
variable, you can compile that goal as usual with an output for that
variable, and then generate code to write the value indirectly.  In
fact, I can't see why that wouldn't work for a multi goal, as well.

> But using partially instantiated data structures in this way is
> a little more elegant.)

And easier to code.

Peter Schachte                     Any Idiot can face a crisis; it is this
mailto:schachte at cs.mu.OZ.AU        day-to-day living that wears you out.
http://www.cs.mu.oz.au/~schachte/      -- Anton Chekhov 
PGP: finger schachte at  
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