Browse thread
[Caml-list] "List.index" or "List.unique" functions?
-
Rahul Siddharthan
- Richard Jones
- Martin Jambon
- Benjamin Geer
- Karl Zilles
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ 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? |
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