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 WAA15259; Fri, 30 Apr 2004 22:47:42 +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 WAA15069 for ; Fri, 30 Apr 2004 22:47:41 +0200 (MET DST) Received: from localhost ([212.254.193.43]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i3UKleEV018754 for ; Fri, 30 Apr 2004 22:47:40 +0200 Received: from localhost ([127.0.0.1] helo=localhost.localdomain ident=ze) by localhost with esmtp (Exim 3.35 #1 (Debian)) id 1BJeuj-0000NR-00 for ; Fri, 30 Apr 2004 22:47:17 +0200 Subject: Re: [Caml-list] "List.index" or "List.unique" functions? From: JM Nunes To: caml-list@inria.fr In-Reply-To: <874qr1nseq.dlv@vanicat.homelinux.org> References: <20040430175429.GB11118@online.fr> <4092A448.6080909@1969.ws> <874qr1nseq.dlv@vanicat.homelinux.org> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.5 Date: 30 Apr 2004 22:47:16 +0200 Message-Id: <1083358037.1352.92.camel@sophne> Mime-Version: 1.0 X-Miltered: at nez-perce with ID 4092BB6C.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 int:01 int:01 let:04 functions:05 fold:07 fun:08 index:91 sort:11 rev:13 rev:13 case:16 else:20 then:23 mem:24 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Note that List.rev is not being useful in this case. > 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] # unique [7;1;2;3;4;3;4;5;6;5];; - : int list = [7; 1; 2; 3; 4; 5; 6] For sorting List.sort or other must be used. ------------------- 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