[m-rev.] for review: copy/2 implementation for il backend
Fergus Henderson
fjh at cs.mu.OZ.AU
Thu Nov 28 01:28:08 AEDT 2002
On 26-Nov-2002, Peter Ross <pro at missioncriticalit.com> wrote:
> One questioned that needs to be asked is how does this behave compared
> to the implementation of MR_deep_copy on the C backend?
>
> On the C backend MR_deep_copy only deep copies Mercury values. If
> you have any references to foreign types then only the reference to
> their location will be copied. However my implementation below will
> copy the foreign type. Is this the behaviour we want?
>
> I think not,
Agreed.
> so how do we avoid it. We could add a custom attribute to
> every Mercury type indicating that it is a Mercury type and then only
> copy those types which have this attribute.
>
> This would avoid the problems where the foreign type could have circular
> references.
Another alternative would be to have a DeepCopyable base class, and
make all Mercury-generated classes inherit from that class (rather than
System.Object). This could provide a deep_copy() method. The default
implementation would use code along the lines that you posted.
The code for Mercury's copy/1 procedure would then just do a dynamic
cast to DeepCopyable, and if that succeeded call the deep_copy() method,
otherwise throw an exception.
The advantage of this approach is that it would make it possible to
implement foreign types that can be deep-copied by Mercury's copy/1.
This might be useful for implementing types in the Mercury standard
library, or for users who are writing code that interfaces Mercury
and other languages.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list