Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] "List.index" or "List.unique" functions?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Karl Zilles <zilles@1...>
Subject: Re: [Caml-list] "List.index" or "List.unique" functions?
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