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 VAA09954; Fri, 30 Apr 2004 21:09:21 +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 VAA10129 for ; Fri, 30 Apr 2004 21:09:20 +0200 (MET DST) Received: from woodstock.1969.ws (64-215-156-42.eosinc.net [64.215.156.42]) by nez-perce.inria.fr (8.12.10/8.12.10) with SMTP id i3UJ9IEV005811 for ; Fri, 30 Apr 2004 21:09:19 +0200 Received: (qmail 6345 invoked from network); 30 Apr 2004 19:06:47 -0000 Received: from karl.1969.ws (HELO 1969.ws) (10.3.2.15) by woodstock.1969.ws with SMTP; 30 Apr 2004 19:06:47 -0000 Message-ID: <4092A448.6080909@1969.ws> Date: Fri, 30 Apr 2004 12:08:56 -0700 From: Karl Zilles Organization: 1969 Communications, Inc. User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Rahul Siddharthan CC: caml-list@inria.fr Subject: Re: [Caml-list] "List.index" or "List.unique" functions? References: <20040430175429.GB11118@online.fr> In-Reply-To: <20040430175429.GB11118@online.fr> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 4092A45E.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 beginners:01 ocaml:01 int:01 wrote:03 recursive:03 suppose:03 tail:03 let:04 functions:05 fold:07 lists:91 fun:08 index:91 function:09 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Rahul Siddharthan wrote: > I have a question: suppose I have a list l1, and I want to create a new > list l2 with only one copy of any repeated members of the first list > (eg, l1=[1;2;3;4;3;4;5;6;5] -> l2=[1;2;3;4;5;6]) let unique l = List.rev (List.fold_left (fun results x -> if List.mem x results then results else x::results) [] l);; unique [1;2;3;4;3;4;5;6;5];; - : int list = [1; 2; 3; 4; 5; 6] List.rev is not tail recursive, so you wouldn't want to use this function on industrial size lists. You might want to check out the ocaml_beginners@yahoogroups.com mailing list. That is a good place to ask questions like this. ------------------- 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