[mercury-users] Exceptions and unique modes

Peter Ross peter.ross at miscrit.be
Fri Mar 2 01:01:22 AEDT 2001


On Fri, Feb 23, 2001 at 11:38:46AM +1100, Fergus Henderson wrote:
> On 22-Feb-2001, Peter Ross <peter.ross at miscrit.be> wrote:
> > On Thu, Feb 22, 2001 at 05:01:28PM +1100, Fergus Henderson wrote:
> > > In particular, what would you do about code which tries to reuse the
> > > storage for something with a `di' mode, e.g. by explicitly deallocating
> > > it so that the allocator can reuse it to hold something that has a
> > > different type?
> >
> > You would think that the best canditate for reuse of that memory is the
> > next state.  Unfortunately it is not quite that easy as the following
> > type indicates.
> > 
> > :- type t
> >     --->    f(int)
> >     ;       g(int, int).
> > 
> > No matter what you initialise this type to you need to make sure that
> > you allocate 2 words so that you can possibly hold the g constructor at
> > some later date.
> 
> That would be a bad idea in general, e.g. consider
> 
> 	:- type t2
> 	     --->    f2(int)
> 	     ;       g2(int, int, int, int, int, int, int, int, int, int,
> 	     		int, int, int, int, int, int, int, int, int, int).
> 
> and suppose that 99% of all values of type `t' use f2/1 rather than g2/22.
> Even for your type t, the cost of the extra space needed to allocate
> two words rather than one for f/1 may outweigh any gains you get from
> additional reuse.
> 
A simple source to source transformation along the lines of

:- type t2
        --->    f2(int)
        ;       wrapper(t2_g2).

:- type t2_g2
        --->    g2(int, int, int, int, int, int, int, int, int, int,
                int, int, int, int, int, int, int, int, int, int).

Would avoid this problem.

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