From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA13767; Mon, 5 Aug 2002 09:10:06 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA13791 for ; Mon, 5 Aug 2002 09:10:06 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from www.duonix.com ([210.113.163.221]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g757A4D11334 for ; Mon, 5 Aug 2002 09:10:04 +0200 (MET DST) Received: from hama ([192.168.0.254]) by www.duonix.com (8.12.5/8.11.6) with SMTP id g757DmQG051877 for ; Mon, 5 Aug 2002 16:13:48 +0900 (KST) (envelope-from shoh@duonix.com) X-Authentication-Warning: www.duonix.com: Host [192.168.0.254] claimed to be hama Message-ID: <000501c23c4f$2b781c50$fe00a8c0@hama> From: "SooHyoung Oh" To: "Caml-List" Subject: [Caml-list] Weak type, Open type Date: Mon, 5 Aug 2002 16:10:24 +0900 MIME-Version: 1.0 Content-Type: text/plain; charset="ks_c_5601-1987" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, Ocamlers! While I've studying design pattern with ocaml, I made the followding 3 classes (PART1): (1) class virtual entry: base class (2) class file: subclass of "entry" class (3) class dir: subclass of "entry" class I made some code using these classes on top level and it's ok. (PART 2). While I translate the top level code into new class definition (PART3), it makes some error. The error message is on (PART 4). It seems that (PART2) is weak type and (PART 3) is open type. [Q 1] Is (PART2) is correct? I don't know why it doesn't make type error. [Q 2] (depend on Q 1) Can I translate (PART2) into new class definition like (PART 3) without type error? Then how? ============ (PART 1) class definition =============== class virtual entry () = object method virtual name: unit -> string end;; class file name = object(self) inherit entry () method name () = name method file_size () = 100 end;; class dir name = object(self) inherit entry () method name () = name method dir_size () = 3000 end;; =============== (PART 2) NO ERROR with weak type (?) =================== let file_list = ref ([]: #entry list);; let add e = file_list := (e:>entry) :: !file_list;; let _ = add (new dir "root");; let _ = add (new file "hello.txt");; ================ (PART 3) ERROR with open type (?) ================ class dir2 name = object(self) inherit entry () val file_list = ref ([]: #entry list) method name () = name method add e = file_list := (e:>entry) :: !file_list end;; ================ (PART 4) error message ================ Some type variables are unbound in this type: class dir2 : string -> object val file_list : entry list ref method add : #entry -> unit method name : unit -> string end The method add has type #entry -> unit where .. is unbound --- SooHyoung Oh tel: 02)583-8709, 042)861-8649 cell. phone: 011-453-4303 web: http://www.duonix.com ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners