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 WAA15849; Fri, 30 Apr 2004 22:59: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 WAA15798 for ; Fri, 30 Apr 2004 22:59: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 i3UKxIEV020491 for ; Fri, 30 Apr 2004 22:59:18 +0200 Received: (qmail 9899 invoked from network); 30 Apr 2004 20:56:47 -0000 Received: from karl.1969.ws (HELO 1969.ws) (10.3.2.15) by woodstock.1969.ws with SMTP; 30 Apr 2004 20:56:47 -0000 Message-ID: <4092BE10.6090803@1969.ws> Date: Fri, 30 Apr 2004 13:58: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: JM Nunes CC: caml-list@inria.fr Subject: Re: [Caml-list] "List.index" or "List.unique" functions? References: <20040430175429.GB11118@online.fr> <4092A448.6080909@1969.ws> <874qr1nseq.dlv@vanicat.homelinux.org> <1083358037.1352.92.camel@sophne> In-Reply-To: <1083358037.1352.92.camel@sophne> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 4092BE26.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 python:01 preserving:01 demonstrate:01 ocaml:01 int:01 int:01 wrote:03 let:04 functions:05 output:05 fold:07 fun:08 index:91 function:09 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk JM Nunes wrote: > Note that List.rev is not being useful in this case. See below: > >>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] This is the correct output. > > For sorting List.sort or other must be used. I think what you're missing is that he's not actually looking to sort the list. His python function was order preserving, as is my ocaml version. His test case could have been chosen more carefully to demonstrate that. ------------------- 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