Created
September 15, 2012 20:02
-
-
Save hcarty/3729519 to your computer and use it in GitHub Desktop.
Unique elements from a list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let unique (type s) ?(cmp = compare) (l : s list) = | |
let module M = struct | |
type t = s | |
let compare = cmp | |
end in | |
let module S = Set.Make(M) in | |
let s = List.fold_left (fun accu x -> S.add x accu) S.empty l in | |
S.elements s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment