From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id MAA22195 for caml-redistribution; Wed, 29 May 1996 12:02:20 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.6.10/8.6.6) with ESMTP id UAA13622 for ; Tue, 28 May 1996 20:43:47 +0200 Received: from wildtype.Stanford.EDU (wildtype.Stanford.EDU [171.65.22.207]) by concorde.inria.fr (8.7.1/8.7.1) with ESMTP id UAA04578 for ; Tue, 28 May 1996 20:43:46 +0200 (MET DST) Received: (from arc@localhost) by wildtype.Stanford.EDU (8.7.5/8.7.1) id LAA10975; Tue, 28 May 1996 11:43:39 -0700 (PDT) Date: Tue, 28 May 1996 11:43:39 -0700 (PDT) From: Andrew Conway Message-Id: <199605281843.LAA10975@wildtype.Stanford.EDU> To: 100060.2106@compuserve.com, garrigue@kurims.kyoto-u.ac.jp Subject: Re: Oo.copy Cc: caml-list@pauillac.inria.fr Sender: weis >From: Jacques GARRIGUE > >>>>>> ESPERET PHILIPPE <100060.2106@compuserve.com> writes: > > > I cannot understand how to access a fresh copy of an object with > > O'Caml (Oo seems normally to copy only pointers). Thank you if someone > > can explain me how to get such a copy (please see below for an example). > > > [ gives example of a class where a mutable element of the class > > (an array) is not copied by OO.copy ] > >The problem is that your array is shared between the two copies. >There are various specific ways to solve it. I think that is a bad feature. I realise it may be unavoidable. In particular, when I read the documentation for OO.copy, I assumed that it was a function that descended the data structure, copying all mutable structures. This seemed like a very useful thing to me (and I wish it was available for any given type, not just classes). I can immagine that this is impractical due to the overhead involved in building specific "deep" copy functions for each data type defined (that could possibly contain a mutable data structure), unless the GC information contains enough of a specification to write a general copy function similar to the general comparison functions. This would perhaps only take one bit per block...saying whether the particular block is mutable or not. On the other hand, I do realise that bits are expensive. >One is to add an "unsharing" method in the virtual class, which is >applied after copying. Ugh! > ... > >This is difficult to have a general way, since mutable data structures >can get various forms. Agreed. Andrew.