Skip to content

Instantly share code, notes, and snippets.

@hcarty
Created September 15, 2012 20:02
Show Gist options
  • Save hcarty/3729519 to your computer and use it in GitHub Desktop.
Save hcarty/3729519 to your computer and use it in GitHub Desktop.
Unique elements from a list
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