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 PAA31008; Tue, 2 Sep 2003 15:45:39 +0200 (MET DST) 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 PAA16392 for ; Tue, 2 Sep 2003 15:45:38 +0200 (MET DST) Received: from aomori.annexia.org (annexia.force9.co.uk [212.56.101.183]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h82DjcT17322 for ; Tue, 2 Sep 2003 15:45:38 +0200 (MET DST) Received: from rich by aomori.annexia.org with local (Exim 3.36 #1 (Debian)) id 19uBTV-0001ue-00 for ; Tue, 02 Sep 2003 14:45:37 +0100 Date: Tue, 2 Sep 2003 14:45:37 +0100 To: caml-list@inria.fr Subject: [Caml-list] Alternate constructors for a class Message-ID: <20030902134537.GA7309@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.4i From: Richard Jones X-Loop: caml-list@inria.fr X-Spam: no; 0.00; untitled:99 marshall:01 serialized:01 incorrectly:01 freshmeat:01 bin:01 ltd:98 width:98 height:98 constructors:01 constructors:01 supplying:97 business:96 module:03 explicit:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I have a class defined currently like this: class view ?width ?height ?packing ?show ?(title = "untitled") () = (* ... *) I want to provide an alternate way of constructing this class, in this case by unmarshalling it from a channel (using the Marshall module). Callers should be able to construct a view either using the explicit parameters, or by doing: let chan = open_in_bin "serialized_class" in let view = new view ~chan in (* ... *) Now in the case above I guess I could add an extra optional ?chan argument, but that seems a bit ugly because it doesn't prevent users from supplying incorrectly both ~chan and ~title, for example. Is there an easy way to provide two different constructors for a class? Other languages do allow different sets of arguments to different constructors for the same class quite naturally. Rich. -- Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj Merjis Ltd. http://www.merjis.com/ - all your business data are belong to you. "I wish more software used text based configuration files!" -- A Windows NT user, quoted on Slashdot. ------------------- 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