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 LAA06481 for caml-redistribution; Tue, 28 May 1996 11:31:12 +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 WAA24597 for ; Sat, 25 May 1996 22:28:00 +0200 Received: from hil-img-3.compuserve.com (hil-img-3.compuserve.com [149.174.215.203]) by concorde.inria.fr (8.7.1/8.7.1) with SMTP id WAA08762 for ; Sat, 25 May 1996 22:27:59 +0200 (MET DST) Received: by hil-img-3.compuserve.com (8.6.10/5.950515) id QAA25894; Sat, 25 May 1996 16:27:56 -0400 Date: 25 May 96 16:25:56 EDT From: ESPERET PHILIPPE <100060.2106@compuserve.com> To: liste Caml Subject: Oo.copy Message-ID: <960525202556_100060.2106_JHB98-1@CompuServe.COM> Sender: weis % ocaml1.tex 25-5-1996 (23h:16) %%%%%%%%%%%%%% Philippe Esperet (France) Fax : (33-1) 46 56 83 68 email 100060.2106@compuserve.com 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). One related problem is : the documentation for O'Caml exists but is not so thick ; it could be useful to have a list where true beginners in OCaml might ask their questions and find examples. (* #use "C:/OCAML/esperet/email3.ml";; *) class virtual 'a matrix(sz,init:int*'a) as self= val size=sz val m=Array.create_matrix sz sz init val zero=init virtual printa:'a -> unit (*method copy()=new matrix(size,zero) forbidden: One cannot create instances of the virtual class matrix*) method m=m method set(i,j,nval:int*int*'a)= m.(i).(j) <- nval method build(f:int->int->'a)=for i=0 to size-1 do for j=0 to size-1 do m.(i).(j)<- f i j done done;self method print()=for i=0 to size-1 do for j=0 to size-1 do self#printa m.(i).(j); print_char ';' done; print_newline() done end class int_matrix (sz:int)= inherit (int) matrix (sz,0) method printa=print_int end let m=new int_matrix 3;; (m#build (fun i j->i+j))#print();; m#print();; let n=Oo.copy m;; (*let nn=m#copy();;*) m#set(1,1,66);; n#print();; (*nn#print();;*)