From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA22745 for caml-redistribution; Wed, 29 Sep 1999 22:19:02 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA10298 for ; Tue, 28 Sep 1999 20:37:16 +0200 (MET DST) Received: from ruby (pm1-14.triode.net.au [203.63.235.30]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id UAA28634 for ; Tue, 28 Sep 1999 20:37:10 +0200 (MET DST) Received: from maxtal.com.au (IDENT:root@localhost [127.0.0.1]) by ruby (8.9.3/8.9.3) with ESMTP id EAA07563 for ; Wed, 29 Sep 1999 04:56:37 +1000 Sender: weis Message-ID: <37F10F65.47A4212C@maxtal.com.au> Date: Wed, 29 Sep 1999 04:56:37 +1000 From: skaller Organization: Maxtal P/L X-Mailer: Mozilla 4.51 [en] (X11; I; Linux 2.2.5-15 i586) X-Accept-Language: en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Can someone explain? References: <19990909214313.55795@pauillac.inria.fr> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Is there a way to access a value of a class instance? If so, what is the syntax? If not, what is the purpose of allowing 'val' bindings in class declarations in module signatures? Similarly, what is the purpose of allowing 'virtual' methods in class types and class declarations in module signatures? I have a doubly linked list class, and concatenating two lists takes 100 times longer in ocaml using my code than pythons list concatenation function, which is written in C. My code isn't optimal (given the particular data structure I've chosen) because the concat function cannot get at values of the class. Excerpt given below. Any advice appreciated. (A high speed mutable list in the standard library would be even better :-) module DoublyLinkedList : BiDirectional = struct (* doubly linked list type *) type 't d_node = { mutable nxt: 't iterator; mutable prv: 't iterator; mutable data: 't } and 't iterator = Empty | Node of 't d_node let next x = match x with Empty -> Empty | Node n -> n.nxt let deref x = match x with Empty -> None | Node n -> Some n.data class ['t] dlist = object(self) val mutable first': 't iterator = Empty val mutable last': 't iterator = Empty val mutable size: int = 0 method private init node = last' <- node; first' <- node; size <- 1 method length = size (* STL style mutators *) method push_back (data':'t): unit = match last' with | Empty -> self#init (Node {nxt=Empty; prv=Empty; data=data'}) | Node fin -> let tmp = Node {nxt=Empty; prv=last'; data=data'} in fin.nxt <- tmp; last' <- tmp; size <- size + 1 method first = first' end let concat (x:'a dlist) (y:'a dlist) :'a dlist = let z = new dlist in let i = ref x#first in while deref !i <> None do match deref !i with | Some v -> z#push_back v; i := next !i | None -> assert false done; let j = ref y#first in while deref !j <> None do match deref !j with | Some v -> z#push_back v; j := next !j | None -> assert false done; z end -- John Skaller, mailto:skaller@maxtal.com.au 1/10 Toxteth Rd Glebe NSW 2037 Australia homepage: http://www.maxtal.com.au/~skaller downloads: http://www.triode.net.au/~skaller