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: JM Nunes <Jose.DeAbreuNunes@a...>
Subject: Re: [Caml-list] "List.index" or "List.unique" functions?
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