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 RAA21685; Sun, 15 Dec 2002 17:12:42 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 RAA21733 for ; Sun, 15 Dec 2002 17:12:42 +0100 (MET) Received: from rcpt-expgw.biglobe.ne.jp (rcpt-expgw.biglobe.ne.jp [202.225.89.154]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id gBFGCej14455 for ; Sun, 15 Dec 2002 17:12:40 +0100 (MET) Received: from smtp-gw.biglobe.ne.jp by rcpt-expgw.biglobe.ne.jp (mnmy/5508310702) with ESMTP id gBFGCaN19785 for ; Mon, 16 Dec 2002 01:12:37 +0900 (JST) X-Biglobe-Sender: Received: from localhost (43.225.176.51 [43.225.176.51]) by smtp-gw.biglobe.ne.jp id BAHOC0A8265F; Mon, 16 Dec 2002 01:12:36 +0900 (JST) Date: Mon, 16 Dec 2002 01:18:51 +0900 (JST) Message-Id: <20021216.011851.730550325.nobuyuki@mua.biglobe.ne.jp> To: caml-list@inria.fr Subject: [Caml-list] Question on typing of class/object and optional argument. From: Nobuyuki Tomizawa X-Mailer: Mew version 2.1 on XEmacs 21.1.14 (Cuyahoga Valley) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Dear list: I have a question on class/object with optional arguments method. I could not compile following program: ------------------------------------------------------------ class foo s = object val str : string = s method to_string ?(opt = "" ) () = opt ^ s end;; let l = [new foo "a"; new foo "b"; new foo "c" ];; List.iter (fun e -> print_endline (e#to_string ())) l;; ------------------------------------------------------------ with folloing message. ------------------------------------------------------------ File "test.ml", line 8, characters 52-53: This expression has type foo list but is here used with type < to_string : unit -> string > list Type foo = < to_string : ?opt:string -> unit -> string > is not compatible with type < to_string : unit -> string > ------------------------------------------------------------ In contrast, I did not get the above message if I rewrote the program into module style like: ------------------------------------------------------------ module type BAR = sig type t val create : string -> t val to_string : ?opt:string -> t -> string end;; module Bar : BAR = struct type t = string let create t = t let to_string ?(opt = "") t = opt ^ t end;; let m = [Bar.create "a"; Bar.create "b"; Bar.create "c" ];; List.iter (fun e -> print_endline (Bar.to_string e)) m;; ------------------------------------------------------------ I can not understand how different these two versions are in Ocaml's typing systems. Colud you please tell me the point and what should I know to understand well about such kind of typing issues? Thanks in advance. Nobuyuki Tomizawa ------------------- 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