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 BAA02630; Tue, 18 Nov 2003 01:40:57 +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 BAA02725 for ; Tue, 18 Nov 2003 01:40:55 +0100 (MET) Received: from swordfish.cs.caltech.edu (swordfish.cs.caltech.edu [131.215.44.124]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hAI0eq106651 for ; Tue, 18 Nov 2003 01:40:52 +0100 (MET) Received: from cs.caltech.edu (wasco.cs.caltech.edu [131.215.44.173]) by swordfish.cs.caltech.edu (Postfix) with ESMTP id 9BB7ADF276; Mon, 17 Nov 2003 16:40:50 -0800 (PST) Message-ID: <3FB96A91.8000108@cs.caltech.edu> Date: Mon, 17 Nov 2003 16:40:49 -0800 From: Aleksey Nogin Organization: California Institute of Technology, Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031030 X-Accept-Language: ru, en-us, en MIME-Version: 1.0 To: "chris.danx" Cc: caml-list@inria.fr Subject: Re: [Caml-list] Records: syntax error... References: <3FB9668D.3060709@ntlworld.com> In-Reply-To: <3FB9668D.3060709@ntlworld.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 626:99 chris:01 imho:01 caltech:01 caltech:01 syntax:02 match:02 match:02 differs:03 explicit:03 wrote:03 slightly:03 intuitive:04 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On 17.11.2003 16:23, chris.danx wrote: > let insert item dl = > match dl with > {l = _; compare = _; in_order = true} -> Hint: you do not have to mention the fiends that you are not interested in. So you could just use ... match dl with { in_order = true } -> ... > {merge dl.compare (dl.l, [item]), dl.compare, true} You have to use the explicit field names when you construct records: { l = merge dl.compare (dl.l, [item]); compare = dl.compare; in_order = true } Hint: if you want to create a new record that only slightly differs from an existing one, use the "with" construction: { dl with l = merge dl.compare (dl.l, [item]) } > | {l = _; compare = _; in_order = false} -> > {item::dl.l, dl.compare, false};; Hint: it is IMHO a bad style to use "match" expressions simply to check on a boolean value - it's much more intuitive to use "if/then/else" for that. P.S. Here is how I would have written the insert function above: let insert item dl = { dl with l = if dl.in_order then merge dl.compare (dl.l, [item]) else item::dl.l } -- Aleksey Nogin Home Page: http://nogin.org/ E-Mail: nogin@cs.caltech.edu (office), aleksey@nogin.org (personal) Office: Jorgensen 70, tel: (626) 395-2907 ------------------- 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