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 OAA06337; Tue, 19 Jun 2001 14:25:57 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 OAA07773 for ; Tue, 19 Jun 2001 14:25:56 +0200 (MET DST) Received: from mail.cs.uu.nl (sunset.cs.uu.nl [131.211.80.32]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f5JCPtX15133 for ; Tue, 19 Jun 2001 14:25:55 +0200 (MET DST) Received: from silvester.cs.uu.nl (silvester.cs.uu.nl [131.211.80.119]) by mail.cs.uu.nl (Postfix) with SMTP id DBA604518; Tue, 19 Jun 2001 14:25:54 +0200 (MET DST) Received: by silvester.cs.uu.nl (sSMTP sendmail emulation); Tue, 19 Jun 2001 14:25:54 +0200 Date: Tue, 19 Jun 2001 14:25:54 +0200 From: Frank Atanassow To: Sven LUTHER Cc: Fr?d?ric van der Plancke , caml Subject: Re: [Caml-list] Newbie: declarations Message-ID: <20010619142554.A7583@cs.uu.nl> References: <20010616170909.B10922@jean> <3B2F091F.EED457D9@decis.be> <20010619122206.A24467@lambda.u-strasbg.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010619122206.A24467@lambda.u-strasbg.fr>; from luther@dpt-info.u-strasbg.fr on Tue, Jun 19, 2001 at 12:22:06PM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Sven LUTHER wrote (on 19-06-01 12:22 +0200): > What about having a way to initialise struct types : > > something like : > > type datarec = { > mutable name : string = "?"; > mutable color : string = "?"; > mutable value : int = 0; > } > [...] > But is it really usefull, i guess you could simply wrap the datatype in a > constructor, and not worry about such things : Yes, and it also doesn't make sense for the common case where fields are polymorphic. > type datarec = { > mutable name : string; > mutable color : string; > mutable value : int; > } > > let new_datarec n c v = { > name = match n with None -> "?" | Some n -> n; > color = match c with None -> "?" | Some c -> c; > value = match v with None -> 0 | Some v -> v; > } > > Then you could simply do : > > let x = new_datarec None None (Some 113) > let y = new_datarec (Some "y") ("00FF00 FF00FF") None There is a simpler way: let new_datarec = { name = "?"; color = "?"; value = 0 } let x = { new_datarec with value = 113 } let y = { new datarec with color = "00FF00 FF00FF"; name = "y" } -- Frank Atanassow, Information & Computing Sciences, Utrecht University Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands Tel +31 (030) 253-3261 Fax +31 (030) 251-379 ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr